public bool ResetByPrefab(string prefabName, Node prefabNode) { bool reset = false; if (!this.HasOwnPrefabData && this.PrefabName == prefabName && this.PrefabNodeId == prefabNode.Id) { reset = true; int preId = this.Id; string prePrefabName = this.PrefabName; int prePrefabNodeId = this.PrefabNodeId; Comment preComment = (this.CommentObject != null) ? this.CommentObject.Clone() : null; prefabNode.CloneProperties(this); this.Id = preId; this.PrefabName = prePrefabName; this.PrefabNodeId = prePrefabNodeId; this.HasOwnPrefabData = false; this.CommentObject = preComment; // check the deleted children by the prefab node List<Node> deletedChildren = new List<Node>(); foreach(Node child in this.Children) { if (!child.HasOwnPrefabData && child.PrefabName == prefabName) { bool bFound = false; foreach(Node prefabChild in prefabNode.Children) { if (child.PrefabNodeId == prefabChild.Id) { bFound = true; break; } } if (!bFound) { deletedChildren.Add(child); } } } foreach(Node child in deletedChildren) { ((Node)child.Parent).RemoveChild(child.ParentConnector, child); } // check the added children by the prefab node List<Node> addedChildren = new List<Node>(); List<int> indexes = new List<int>(); for (int i = 0; i < prefabNode.Children.Count; ++i) { Node prefabChild = (Node)prefabNode.Children[i]; bool bFound = false; foreach(Node child in this.Children) { if (!string.IsNullOrEmpty(prefabChild.PrefabName) && child.PrefabName == prefabChild.PrefabName && child.PrefabNodeId == prefabChild.PrefabNodeId || child.PrefabName == prefabName && child.PrefabNodeId == prefabChild.Id) { bFound = true; break; } } if (!bFound) { addedChildren.Add(prefabChild); indexes.Add(i); } } for (int i = 0; i < addedChildren.Count; ++i) { Node child = addedChildren[i].CloneBranch(); child.SetPrefab(prefabName); Node.Connector conn = addedChildren[i].ParentConnector; Debug.Check(conn != null); Node.Connector childconn = this.GetConnector(conn.Identifier); Debug.Check(childconn != null); if (indexes[i] < this.Children.Count) { this.AddChild(childconn, child, indexes[i]); } else { this.AddChild(childconn, child); } child.ResetId(true); } } if (!(this is ReferencedBehavior)) { foreach(Node child in this.Children) { reset |= child.ResetByPrefab(prefabName, prefabNode); } } return reset; }