Ejemplo n.º 1
0
        static HierarchySnapshot CreateSnapshot(Transform t)
        {
            HierarchySnapshot h = new HierarchySnapshot();

            h.name   = t.name;
            h.parent = t.parent;
            h.me     = t;
            return(h);
        }
Ejemplo n.º 2
0
        static void OnHierarchyChangeCheck()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            bool found = false;

            for (int i = 0; i < _hierarchySnapshots.Count;)
            {
                HierarchySnapshot h = _hierarchySnapshots[i];
                if (h.me == null)
                {
                    _hierarchySnapshots.RemoveAt(i);
                    _hierarchyTransforms.RemoveAt(i);
                    OnHierarchyChnaged(EChangeType.Deleted, h);
                    found = true;
                    continue;
                }

                else if (h.parent != h.me.parent)
                {
                    OnHierarchyChnaged(EChangeType.Parented, h);
                    h.parent = h.me.parent;
                    found    = true;
                    break;
                }

                else if (h.name != h.me.name)
                {
                    OnHierarchyChnaged(EChangeType.Renamed, h);
                    h.name = h.me.name;
                    found  = true;
                    break;
                }

                i++;
            }

            if (!found)
            {
                Transform[] all = GameObject.FindObjectsOfType <Transform>();
                foreach (Transform t in all)
                {
                    if (!_hierarchyTransforms.Contains(t))
                    {
                        HierarchySnapshot h = CreateSnapshot(t);
                        _hierarchySnapshots.Add(h);
                        _hierarchyTransforms.Add(t);

                        OnHierarchyChnaged(EChangeType.Created, h);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        static void OnHierarchyChange(EChangeType type, HierarchySnapshot snapshot)
        {
            string log = type.ToString();

            if (snapshot.me != null)
            {
                log += " name:" + snapshot.me.name + ", parent: " + snapshot.me.parent;
            }
            log += " snapshot name: " + snapshot.name + ", parent: " + snapshot.parent;
            Debug.Log(log);
        }
Ejemplo n.º 4
0
        static HierarchyChangedDetecter()
        {
            _hierarchySnapshots  = new List <HierarchySnapshot>();
            _hierarchyTransforms = new List <Transform>();

            Transform[] all = GameObject.FindObjectsOfType <Transform>();
            foreach (Transform t in all)
            {
                HierarchySnapshot h = CreateSnapshot(t);
                _hierarchySnapshots.Add(h);
                _hierarchyTransforms.Add(t);
            }

            EditorApplication.hierarchyWindowChanged += OnHierarchyChangeCheck;
                        #if Debug
            OnHierarchyChnaged += OnHierarchyChange;
                        #endif
        }