RenderQueue、SortingLayer、SortingOrder等的设置,让物体B挡在物体A前面
渲染流水线相关
附Canvas组件反编译源码
using System;
using System.Runtime.CompilerServices;
using System.Threading;
using UnityEngine.Bindings;
using UnityEngine.Scripting;
namespace UnityEngine
{
/// <summary>
/// <para>Element that can be used for screen rendering.</para>
/// </summary>
[NativeHeader("Runtime/UI/Canvas.h"), NativeHeader("Runtime/UI/UIStructs.h"), NativeClass("UI::Canvas"), RequireComponent(typeof(RectTransform))]
public sealed class Canvas : Behaviour
{
public delegate void WillRenderCanvases();
public static event Canvas.WillRenderCanvases willRenderCanvases
{
add
{
Canvas.WillRenderCanvases willRenderCanvases = Canvas.willRenderCanvases;
Canvas.WillRenderCanvases willRenderCanvases2;
do
{
willRenderCanvases2 = willRenderCanvases;
willRenderCanvases = Interlocked.CompareExchange<Canvas.WillRenderCanvases>(ref Canvas.willRenderCanvases, (Canvas.WillRenderCanvases)Delegate.Combine(willRenderCanvases2, value), willRenderCanvases);
}
while (willRenderCanvases != willRenderCanvases2);
}
remove
{
Canvas.WillRenderCanvases willRenderCanvases = Canvas.willRenderCanvases;
Canvas.WillRenderCanvases willRenderCanvases2;
do
{
willRenderCanvases2 = willRenderCanvases;
willRenderCanvases = Interlocked.CompareExchange<Canvas.WillRenderCanvases>(ref Canvas.willRenderCanvases, (Canvas.WillRenderCanvases)Delegate.Remove(willRenderCanvases2, value), willRenderCanvases);
}
while (willRenderCanvases != willRenderCanvases2);
}
}
/// <summary>
/// <para>Is the Canvas in World or Overlay mode?</para>
/// </summary>
public extern RenderMode renderMode
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Is this the root Canvas?</para>
/// </summary>
public extern bool isRootCanvas
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
/// <summary>
/// <para>Get the render rect for the Canvas.</para>
/// </summary>
public Rect pixelRect
{
get
{
Rect result;
this.get_pixelRect_Injected(out result);
return result;
}
}
/// <summary>
/// <para>Used to scale the entire canvas, while still making it fit the screen. Only applies with renderMode is Screen Space.</para>
/// </summary>
public extern float scaleFactor
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>The number of pixels per unit that is considered the default.</para>
/// </summary>
public extern float referencePixelsPerUnit
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Allows for nested canvases to override pixelPerfect settings inherited from parent canvases.</para>
/// </summary>
public extern bool overridePixelPerfect
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Force elements in the canvas to be aligned with pixels. Only applies with renderMode is Screen Space.</para>
/// </summary>
public extern bool pixelPerfect
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>How far away from the camera is the Canvas generated.</para>
/// </summary>
public extern float planeDistance
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>The render order in which the canvas is being emitted to the Scene. (Read Only)</para>
/// </summary>
public extern int renderOrder
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
/// <summary>
/// <para>Override the sorting of canvas.</para>
/// </summary>
public extern bool overrideSorting
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Canvas' order within a sorting layer.</para>
/// </summary>
public extern int sortingOrder
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>For Overlay mode, display index on which the UI canvas will appear.</para>
/// </summary>
public extern int targetDisplay
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Unique ID of the Canvas' sorting layer.</para>
/// </summary>
public extern int sortingLayerID
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Cached calculated value based upon SortingLayerID.</para>
/// </summary>
public extern int cachedSortingLayerValue
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
/// <summary>
/// <para>Get or set the mask of additional shader channels to be used when creating the Canvas mesh.</para>
/// </summary>
public extern AdditionalCanvasShaderChannels additionalShaderChannels
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Name of the Canvas' sorting layer.</para>
/// </summary>
public extern string sortingLayerName
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Returns the Canvas closest to root, by checking through each parent and returning the last canvas found. If no other canvas is found then the canvas will return itself.</para>
/// </summary>
public extern Canvas rootCanvas
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
}
/// <summary>
/// <para>Camera used for sizing the Canvas when in Screen Space - Camera. Also used as the Camera that events will be sent through for a World Space [[Canvas].</para>
/// </summary>
[NativeProperty("Camera", false, TargetType.Function)]
public extern Camera worldCamera
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>The normalized grid size that the canvas will split the renderable area into.</para>
/// </summary>
[NativeProperty("SortingBucketNormalizedSize", false, TargetType.Function)]
public extern float normalizedSortingGridSize
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>The normalized grid size that the canvas will split the renderable area into.</para>
/// </summary>
[Obsolete("Setting normalizedSize via a int is not supported. Please use normalizedSortingGridSize", false), NativeProperty("SortingBucketNormalizedSize", false, TargetType.Function)]
public extern int sortingGridNormalizedSize
{
[MethodImpl(MethodImplOptions.InternalCall)]
get;
[MethodImpl(MethodImplOptions.InternalCall)]
set;
}
/// <summary>
/// <para>Returns the default material that can be used for rendering text elements on the Canvas.</para>
/// </summary>
[Obsolete("Shared default material now used for text and general UI elements, call Canvas.GetDefaultCanvasMaterial()", false), FreeFunction("UI::GetDefaultUIMaterial")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Material GetDefaultCanvasTextMaterial();
/// <summary>
/// <para>Returns the default material that can be used for rendering normal elements on the Canvas.</para>
/// </summary>
[FreeFunction("UI::GetDefaultUIMaterial")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Material GetDefaultCanvasMaterial();
/// <summary>
/// <para>Gets or generates the ETC1 Material.</para>
/// </summary>
/// <returns>
/// <para>The generated ETC1 Material from the Canvas.</para>
/// </returns>
[FreeFunction("UI::GetETC1SupportedCanvasMaterial")]
[MethodImpl(MethodImplOptions.InternalCall)]
public static extern Material GetETC1SupportedCanvasMaterial();
/// <summary>
/// <para>Force all canvases to update their content.</para>
/// </summary>
public static void ForceUpdateCanvases()
{
Canvas.SendWillRenderCanvases();
}
[RequiredByNativeCode]
private static void SendWillRenderCanvases()
{
if (Canvas.willRenderCanvases != null)
{
Canvas.willRenderCanvases();
}
}
[MethodImpl(MethodImplOptions.InternalCall)]
private extern void get_pixelRect_Injected(out Rect ret);
}
}