コード例 #1
0
        // add order to existing order, keep layer
        public static void SetDeepDeltaOrder(UnityEngine.GameObject root, int deltaOrder, bool ignoreLinkedObjects)
        {
            SortingLayer sortingLayer = Picus.Utils.GO.Finder.FindComponentAddIfNotExist <SortingLayer>(root);

            sortingLayer.SetDefaults(sortingLayer.SortingLayerId, sortingLayer.SortingOrder + deltaOrder, true, true);

            Transform transform = root.transform;
            int       count     = transform.childCount;

            for (int i = 0; i < count; i++)
            {
                Transform child = transform.GetChild(i);

                if (ignoreLinkedObjects && child.GetComponent <GO.TopInfo>() != null)
                {
                    continue;
                }

                SetDeepDeltaOrder(child.gameObject, deltaOrder);
            }
        }
コード例 #2
0
        public static int RecomputedSortingLevel(UnityEngine.GameObject obj)
        {
            Transform transform = obj == null ? null : obj.transform;

            // TODO: optimalise through GameObjectTopInfo
            while (transform != null)
            {
                SortingLayer sortingLayerComp = transform.GetComponent <SortingLayer>();
                int          sortingLayer;
                int          sortingOrder;

                if (sortingLayerComp != null)
                {
                    sortingLayer = sortingLayerComp.SortingLayerId;                     // need to be sorted in layers order
                    sortingOrder = sortingLayerComp.SortingOrder;
                }
                else
                {
                    Renderer renderer = transform.GetComponent <Renderer>();
                    if (renderer == null)
                    {
                        transform = transform.parent;
                        continue;
                    }
                    sortingLayer = renderer.sortingLayerID;
                    sortingOrder = renderer.sortingOrder;
                }
                Debug.Assert(sortingOrder < MAX_SORTING_ORDER, "Utils.GameObject.SortingLevel too high sorting order " + sortingOrder);

                int ret = sortingLayer * MAX_SORTING_ORDER + sortingOrder;
                //				Debug.Log("Utils.GameObject.SortingLevel sName: " + renderer.sortingLayerName + "; sId: " + sortingLayer + "; sOrder: " + sortingOrder + " => " + ret);

                return(ret);
            }

            return(-1);
        }
コード例 #3
0
        /* private */
        private static void Set(UnityEngine.GameObject root, string newName, int newOrder, int deltaOrder, bool deep, int newId, bool setOrder, bool ignoreLinked)         // get newId only if newName is null
        {
            if (newName != null && newName.Equals("Default"))
            {
                Picus.Sys.Debug.Empty();
            }

            SortingLayer sortingLayer = Picus.Utils.GO.Finder.FindComponentAddIfNotExist <SortingLayer>(root);

            if (newName == null)
            {
                sortingLayer.SetDefaults(newId, newOrder, true, setOrder);
            }
            else
            {
                sortingLayer.SetDefaults(newName, newOrder, setOrder);
            }

            if (!deep)
            {
                return;
            }

            Transform transform = root.transform;
            int       count     = transform.childCount;

            for (int i = 0; i < count; i++)
            {
                Transform child = transform.GetChild(i);
                if (ignoreLinked && child.GetComponent <GO.TopInfo>() != null)
                {
                    continue;
                }
                Set(child.gameObject, newName, newOrder + deltaOrder, deltaOrder, deep, newId, setOrder, ignoreLinked);
            }
        }
コード例 #4
0
 public void SortAllDeepFrom(SortingLayer sortingLayer)
 {
     SetDeepStaticOrder(gameObject, sortingLayer.SortingLayerId);
     SetDeepDeltaOrder(gameObject, sortingLayer.SortingOrder);
 }