unity3d:UGUI层级设置有几种方式,最终是设置了什么

RenderQueue、SortingLayer、SortingOrder等的设置,让物体B挡在物体A前面

SortingOrder

unity3d:UGUI层级设置有几种方式,最终是设置了什么_第1张图片
unity3d:UGUI层级设置有几种方式,最终是设置了什么_第2张图片

SortingLayer

unity3d:UGUI层级设置有几种方式,最终是设置了什么_第3张图片
unity3d:UGUI层级设置有几种方式,最终是设置了什么_第4张图片

RenderQueue

unity3d:UGUI层级设置有几种方式,最终是设置了什么_第5张图片
unity3d:UGUI层级设置有几种方式,最终是设置了什么_第6张图片

最终设置了什么

渲染流水线相关

附Canvas组件反编译源码

using System;
using System.Runtime.CompilerServices;
using System.Threading;
using UnityEngine.Bindings;
using UnityEngine.Scripting;

namespace UnityEngine
 {
     /// 
     ///   Element that can be used for screen rendering.
     /// 
     [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);
             }
         }

         /// 
         ///   Is the Canvas in World or Overlay mode?
         /// 
         public extern RenderMode renderMode
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   Is this the root Canvas?
         /// 
         public extern bool isRootCanvas
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
         }

         /// 
         ///   Get the render rect for the Canvas.
         /// 
         public Rect pixelRect
         {
             get
             {
                 Rect result;
                 this.get_pixelRect_Injected(out result);
                 return result;
             }
         }

         /// 
         ///   Used to scale the entire canvas, while still making it fit the screen. Only applies with renderMode is Screen Space.
         /// 
         public extern float scaleFactor
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   The number of pixels per unit that is considered the default.
         /// 
         public extern float referencePixelsPerUnit
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   Allows for nested canvases to override pixelPerfect settings inherited from parent canvases.
         /// 
         public extern bool overridePixelPerfect
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   Force elements in the canvas to be aligned with pixels. Only applies with renderMode is Screen Space.
         /// 
         public extern bool pixelPerfect
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   How far away from the camera is the Canvas generated.
         /// 
         public extern float planeDistance
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   The render order in which the canvas is being emitted to the Scene. (Read Only)
         /// 
         public extern int renderOrder
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
         }

         /// 
         ///   Override the sorting of canvas.
         /// 
         public extern bool overrideSorting
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   Canvas' order within a sorting layer.
         /// 
         public extern int sortingOrder
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   For Overlay mode, display index on which the UI canvas will appear.
         /// 
         public extern int targetDisplay
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   Unique ID of the Canvas' sorting layer.
         /// 
         public extern int sortingLayerID
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   Cached calculated value based upon SortingLayerID.
         /// 
         public extern int cachedSortingLayerValue
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
         }

         /// 
         ///   Get or set the mask of additional shader channels to be used when creating the Canvas mesh.
         /// 
         public extern AdditionalCanvasShaderChannels additionalShaderChannels
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   Name of the Canvas' sorting layer.
         /// 
         public extern string sortingLayerName
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   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.
         /// 
         public extern Canvas rootCanvas
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
         }

         /// 
         ///   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].
         /// 
         [NativeProperty("Camera", false, TargetType.Function)]
         public extern Camera worldCamera
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   The normalized grid size that the canvas will split the renderable area into.
         /// 
         [NativeProperty("SortingBucketNormalizedSize", false, TargetType.Function)]
         public extern float normalizedSortingGridSize
         {
             [MethodImpl(MethodImplOptions.InternalCall)]
             get;
             [MethodImpl(MethodImplOptions.InternalCall)]
             set;
         }

         /// 
         ///   The normalized grid size that the canvas will split the renderable area into.
         /// 
         [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;
         }

         /// 
         ///   Returns the default material that can be used for rendering text elements on the Canvas.
         /// 
         [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();

         /// 
         ///   Returns the default material that can be used for rendering normal elements on the Canvas.
         /// 
         [FreeFunction("UI::GetDefaultUIMaterial")]
         [MethodImpl(MethodImplOptions.InternalCall)]
         public static extern Material GetDefaultCanvasMaterial();

         /// 
         ///   Gets or generates the ETC1 Material.
         /// 
         /// 
         ///   The generated ETC1 Material from the Canvas.
         /// 
         [FreeFunction("UI::GetETC1SupportedCanvasMaterial")]
         [MethodImpl(MethodImplOptions.InternalCall)]
         public static extern Material GetETC1SupportedCanvasMaterial();

         /// 
         ///   Force all canvases to update their content.
         /// 
         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);
     }
 }

你可能感兴趣的:(UGUI,unity3d,UGUI层级设置,SortingOrder,RenderQueue,SortingLayer)