private void AddToManagers(GameObjectCopy obj) { foreach (ComponentCopy cmp in obj.Components) { this.AddToManagers(cmp); } }
private void RemoveFromManagers(GameObjectCopy obj) { foreach (ComponentCopy cmp in obj.Components) { this.RemoveFromManagers(cmp); } }
public void AddObject(GameObjectCopy obj) { if (obj.Scene != null && obj.Scene != this) { obj.Scene.RemoveObject(obj); } this.objectManager.AddObject(obj); }
private void OnParentChanged(GameObjectCopy oldParent, GameObjectCopy newParent) { // Public event if (this.eventParentChanged != null) { this.eventParentChanged(this, new GameObjectCopyParentChangedEventArgs(this, oldParent, newParent)); } }
private void RemoveObjectDeep(GameObjectCopy obj, List <GameObjectCopy> removedObjects) { foreach (GameObjectCopy child in obj.Children) { this.RemoveObjectDeep(child, removedObjects); } if (this.allObj.Remove(obj)) { removedObjects.Add(obj); } }
private void AddObjectDeep(GameObjectCopy obj, List <GameObjectCopy> addedObjects) { if (this.allObj.Add(obj)) { addedObjects.Add(obj); } foreach (GameObjectCopy child in obj.Children) { this.AddObjectDeep(child, addedObjects); } }
/// <summary> /// Determines the index path from this GameObject to the specified child (or grandchild, etc.) of it. /// </summary> /// <param name="child">The child GameObject to lead to.</param> /// <returns>A <see cref="List{T}"/> of indices that lead from this GameObject to the specified child GameObject.</returns> /// <seealso cref="GetChildAtIndexPath"/> public List <int> GetIndexPathOfChild(GameObjectCopy child) { List <int> path = new List <int>(); while (child.parent != null && child != this) { path.Add(child.parent.children.IndexOf(child)); child = child.parent; } path.Reverse(); return(path); }
public void RemoveObject(GameObjectCopy obj) { if (obj.Scene != this) { return; } if (obj.Parent != null && obj.Parent.Scene == this) { obj.Parent = null; } this.objectManager.RemoveObject(obj); }
public bool IsChildOf(GameObjectCopy parent) { if (this.parent == parent) { return(true); } else if (this.parent != null) { return(this.parent.IsChildOf(parent)); } else { return(false); } }
private static int SerializeGameObjectComparison(GameObjectCopy a, GameObjectCopy b) { int depthA = 0; int depthB = 0; while (a.Parent != null) { a = a.Parent; ++depthA; } while (b.Parent != null) { b = b.Parent; ++depthB; } return(depthA - depthB); }
/// <summary> /// Executes a series of child indexing operations, beginning at this GameObject and /// each on the last retrieved child object. /// </summary> /// <param name="indexPath">An enumeration of child indices.</param> /// <returns>The last retrieved GameObject after executing all indexing steps.</returns> /// <example> /// Calling <c>ChildAtIndexPath(new[] { 0, 0 })</c> will return the first child of the first child. /// </example> public GameObjectCopy GetChildAtIndexPath(IEnumerable <int> indexPath) { GameObjectCopy curObj = this; foreach (int i in indexPath) { if (i < 0) { return(null); } if (i >= curObj.children.Count) { return(null); } curObj = curObj.children[i]; } return(curObj); }
void ICloneExplicit.CopyDataTo(object targetObj, ICloneOperation operation) { GameObjectCopy target = targetObj as GameObjectCopy; // Copy plain old data target.name = this.name; target.initState = this.initState; if (!operation.Context.PreserveIdentity) { target.identifier = this.identifier; } // Copy Components from source to target for (int i = 0; i < this.compList.Count; i++) { operation.HandleObject(this.compList[i]); } // Copy child objects from source to target if (this.children != null) { for (int i = 0; i < this.children.Count; i++) { operation.HandleObject(this.children[i]); } } // Copy the objects parent scene as a weak reference, i.e. // by assignment, and only when the the scene is itself part of the // copied object graph. That way, cloning a GameObject but not its // scene will result in a clone that doesn't reference a parent scene. SceneCopy targetScene = operation.GetWeakTarget(this.scene); if (targetScene != null) { target.scene = targetScene; } // Copy the objects prefab link operation.HandleObject(this.prefabLink, ref target.prefabLink, true); }
/// <summary> /// Returns the first <see cref="Duality.GameObject"/> that matches the specified name. /// </summary> /// <param name="objEnum"></param> /// <param name="name"></param> /// <returns></returns> public static GameObjectCopy FirstByName(this IEnumerable <GameObjectCopy> objEnum, string name) { if (name.IndexOf('/') != -1) { string[] names = name.Split('/'); GameObjectCopy cur = objEnum.FirstByName(names[0]); for (int i = 1; i < names.Length; i++) { if (cur == null) { return(null); } cur = cur.Children.FirstByName(names[i]); } return(cur); } else { return(objEnum.FirstOrDefault(o => o.Name == name)); } }
public void CopyTo(GameObjectCopy target) { this.DeepCopyTo(target); }
private void UnregisterEvents(GameObjectCopy obj) { obj.EventParentChanged -= this.OnParentChanged; obj.EventComponentAdded -= this.OnComponentAdded; obj.EventComponentRemoving -= this.OnComponentRemoving; }
public void AddObject(GameObjectCopy obj) { this.AddObjects(new GameObjectCopy[] { obj }); }
/// <summary> /// Unregisters a GameObject and all of its children /// </summary> /// <param name="obj"></param> public void RemoveObject(GameObjectCopy obj) { this.RemoveObjects(new GameObjectCopy[] { obj }); }
public GameObjectCopy(string name, GameObjectCopy parent = null) { this.Name = name; this.Parent = parent; }
public GameObjectCopyEventArgs(GameObjectCopy obj) { this.obj = obj; }
public GameObjectCopyParentChangedEventArgs(GameObjectCopy obj, GameObjectCopy oldParent, GameObjectCopy newParent) : base(obj) { this.oldParent = oldParent; this.newParent = newParent; }
void ICloneExplicit.SetupCloneTargets(object targetObj, ICloneTargetSetup setup) { GameObjectCopy target = targetObj as GameObjectCopy; bool isPrefabApply = setup.Context is ApplyPrefabContext; if (!isPrefabApply) { // Destroy additional Components in the target GameObject if (target.compMap.Count > 0) { List <Type> removeComponentTypes = null; foreach (var pair in target.compMap) { if (!this.compMap.ContainsKey(pair.Key)) { if (removeComponentTypes == null) { removeComponentTypes = new List <Type>(); } removeComponentTypes.Add(pair.Key); } } if (removeComponentTypes != null) { foreach (Type type in removeComponentTypes) { target.RemoveComponent(type); } } } // Destroy additional child objects in the target GameObject if (target.children != null) { int thisChildCount = this.children != null ? this.children.Count : 0; for (int i = target.children.Count - 1; i >= thisChildCount; i--) { target.children[i].Dispose(); } } } // Create missing Components in the target GameObject foreach (var pair in this.compMap) { ComponentCopy targetComponent = target.AddComponent(pair.Key); setup.HandleObject(pair.Value, targetComponent, CloneBehavior.ChildObject); } // Create missing child objects in the target GameObject if (this.children != null) { for (int i = 0; i < this.children.Count; i++) { GameObjectCopy targetChild; if (target.children != null && target.children.Count > i) { targetChild = target.children[i]; } else { targetChild = new GameObjectCopy(string.Empty, target); } setup.HandleObject(this.children[i], targetChild, CloneBehavior.ChildObject); } } // Handle referenced and child objects setup.HandleObject(this.scene, target.scene, CloneBehavior.Reference); setup.HandleObject(this.prefabLink, target.prefabLink); }