internal static void ForceUpdateByRootCanvas(GameObject root)
        {
            using (var scope = ListPoolScope <SortingOrderByCanvas> .Create())
            {
                root.GetComponentsInChildren(false, scope.list);
                foreach (var item in scope.list)
                {
                    item.DoChange();
                }
            }

            using (var scope = ListPoolScope <SortingOrderByRenderer> .Create())
            {
                root.GetComponentsInChildren(false, scope.list);
                scope.list.Sort(RendererSorter);
                foreach (var item in scope.list)
                {
                    item.DoChange();
                }
            }

            using (var scope = ListPoolScope <SortingOrderBySortingGroup> .Create())
            {
                root.GetComponentsInChildren(false, scope.list);
                foreach (var item in scope.list)
                {
                    item.DoChange();
                }
            }
        }
Esempio n. 2
0
 public static Canvas GetParentCanvas(GameObject gameObject)
 {
     using (var scope = ListPoolScope <Canvas> .Create())
     {
         gameObject.GetComponentsInParent(false, scope.list);
         foreach (var canvas in scope.list)
         {
             if (canvas.isActiveAndEnabled)
             {
                 return(canvas);
             }
         }
     }
     return(null);
 }
 internal void DoChange()
 {
     parentCanvas = GameObjectUtil.GetParentCanvas(gameObject);
     if (parentCanvas == null)
     {
         return;
     }
     using (var scope = ListPoolScope <Renderer> .Create())
     {
         GetComponentsInChildren(true, scope.list);
         foreach (var renderer in scope.list)
         {
             renderer.sortingLayerID = parentCanvas.sortingLayerID;
             renderer.sortingOrder   = parentCanvas.sortingOrder + Offset;
         }
     }
 }
Esempio n. 4
0
        public static float CalcCanvasGroupAlpha(GameObject go)
        {
            if (go == null)
            {
                return(1);
            }
            var alpha = 1f;

            using (var scope = ListPoolScope <CanvasGroup> .Create())
            {
                go.GetComponentsInParent(false, scope.list);
                for (var i = 0; i < scope.list.Count; i++)
                {
                    alpha *= scope.list[i].alpha;
                    if (scope.list[i].ignoreParentGroups)
                    {
                        break;
                    }
                }
            }
            return(alpha);
        }