Exemple #1
0
        internal static bool AddChildItem(this HierarchyItem self, HierarchyItem item)
        {
            int index;

            if (self.FindSiblingIndex(item, out index))
            {
                // The transform is already in the array?
                return(false);
            }

            var currentLoopCount = HierarchyItem.CurrentLoopCount;

            if (item.LastLoopCount != currentLoopCount)
            {
                item.CachedTransformSiblingIndex = item.Transform.GetSiblingIndex();
                item.LastLoopCount = currentLoopCount;
            }

            if (self.FindSiblingIndex(item.Transform, item.CachedTransformSiblingIndex, item.TransformID, out index))
            {
                return(false);
            }

            // make sure item is added in the correct position within the array
            UnityEditor.ArrayUtility.Insert(ref self.ChildNodes, index, item);
            item.SiblingIndex = index;

            /*
             * bool childrenModified = false;
             * for (int i = index + 1; i < ChildNodes.Length; i++)
             * {
             *      if (ChildNodes[i].SiblingIndex != i)
             *      {
             *              ChildNodes[i].SiblingIndex = i;
             *              childrenModified = true;
             *      }
             * }
             * if (childrenModified)*/
            {
                var parentData = self as ParentNodeData;
                if (parentData != null)
                {
                    parentData.ChildrenModified = true;
                }
            }

            Debug.Assert(self.ChildNodes[index] == item);
            return(true);
        }
Exemple #2
0
        internal static bool RemoveChildItem(this HierarchyItem self, HierarchyItem item)
        {
            int index;

            if (!self.FindSiblingIndex(item, out index))
            {
                // The transform is not in the array?
                return(false);
            }

            // make sure item is removed from the array
            UnityEditor.ArrayUtility.RemoveAt(ref self.ChildNodes, index);
            //item.siblingIndex = -1;
            return(true);
        }
Exemple #3
0
        // returns true on success
        internal static bool AddNode(HierarchyItem node, ParentNodeData top)
        {
            if (node.Parent != null)
            {
                //Debug.Log("node.parent != null");
                return(false);
            }

            if (!top.Transform)
            {
//				var top_transform_name	= (top.transform == null) ? "null" : top.transform.name;
//				var node_transform_name = (node.transform == null) ? "null" : node.transform.name;
//				Debug.Log("!top.transform (top.transform=" + top_transform_name + ", node.transform = " + node_transform_name + ")", node.transform);
                return(false);
            }

            var ancestors = new List <Transform>();

            var leafTransform = node.Transform;

            if (leafTransform == null)
            {
                //Debug.Log("node.transform == null");
                return(false);
            }
            var iterator = leafTransform.parent;

            while (iterator != null &&
                   iterator != top.Transform)
            {
                ancestors.Add(iterator);
                iterator = iterator.parent;
            }

            var defaultModel = InternalCSGModelManager.GetDefaultCSGModelForObject(iterator);

            if (!defaultModel)
            {
                return(false);
            }

            var defaultModelTransform = defaultModel.transform;

            if (iterator == null || top.Transform == null ||
                top.Transform == defaultModelTransform)
            {
                iterator = defaultModelTransform;
            }

            if (iterator == null)
            {
                node.Reset();
                top.Reset();
                //Debug.Log("iterator == null");
                return(false);
            }
            if (iterator != top.Transform)
            {
                //Debug.Log("iterator != top.transform");
                return(false);
            }

//			var currentLoopCount = CurrentLoopCount;

            HierarchyItem lastParent    = top;
            var           ancestorDepth = ancestors.Count - 1;

            while (ancestorDepth >= 0)
            {
                var ancestor = ancestors[ancestorDepth];
                int childIndex;
                if (!lastParent.FindSiblingIndex(ancestor, ancestor.GetSiblingIndex(), ancestor.GetInstanceID(), out childIndex))
                {
                    break;
                }

                lastParent = lastParent.ChildNodes[childIndex];
                ancestorDepth--;
            }
            while (ancestorDepth >= 0)
            {
                var newAncestor = new HierarchyItem();
                newAncestor.Transform   = ancestors[ancestorDepth];
                newAncestor.TransformID = newAncestor.Transform.GetInstanceID();
                newAncestor.Parent      = lastParent;

                if (!lastParent.AddChildItem(newAncestor))
                {
                    return(false);
                }

                lastParent = newAncestor;
                ancestorDepth--;
            }

            node.Parent          = lastParent;
            top.ChildrenModified = true;
            return(lastParent.AddChildItem(node));
        }
        // returns true on success
        internal static bool AddNode(HierarchyItem node, ParentNodeData top)
        {
            if (node.Parent != null)
            {
                return(false);
            }

            if (!top.Transform)
            {
                return(false);
            }

            var ancestors = new List <Transform>();

            var leafTransform = node.Transform;

            if (leafTransform == null)
            {
                return(false);
            }
            var iterator = leafTransform.parent;

            while (iterator != null &&
                   iterator != top.Transform)
            {
                ancestors.Add(iterator);
                iterator = iterator.parent;
            }

            var defaultModel = InternalCSGModelManager.GetDefaultCSGModelForObject(iterator);

            if (!defaultModel)
            {
                return(false);
            }

            var defaultModelTransform = defaultModel.transform;

            if (iterator == null || top.Transform == null ||
                top.Transform == defaultModelTransform)
            {
                iterator = defaultModelTransform;
            }

            if (iterator == null)
            {
                node.Reset();
                top.Reset();
                return(false);
            }
#if !UNITY_2018_3_OR_NEWER
            // TODO: figure out how to check this, yet still support prefab isolation mode
            if (iterator != top.Transform)
            {
                return(false);
            }
#endif

            //var currentLoopCount = CurrentLoopCount;

            HierarchyItem lastParent    = top;
            var           ancestorDepth = ancestors.Count - 1;
            while (ancestorDepth >= 0)
            {
                var ancestor = ancestors[ancestorDepth];
                int childIndex;
                if (!lastParent.FindSiblingIndex(ancestor, ancestor.GetSiblingIndex(), ancestor.GetInstanceID(), out childIndex))
                {
                    break;
                }

                lastParent = lastParent.ChildNodes[childIndex];
                ancestorDepth--;
            }
            while (ancestorDepth >= 0)
            {
                var newAncestor = new HierarchyItem();
                newAncestor.Transform   = ancestors[ancestorDepth];
                newAncestor.TransformID = newAncestor.Transform.GetInstanceID();
                newAncestor.Parent      = lastParent;

                if (!lastParent.AddChildItem(newAncestor))
                {
                    return(false);
                }

                lastParent = newAncestor;
                ancestorDepth--;
            }

            node.Parent          = lastParent;
            top.ChildrenModified = true;
            return(lastParent.AddChildItem(node));
        }