// 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)); }