/// <summary> /// Add a child to this object. /// </summary> /// <param name="child">A prefab object.</param> public void AddChild(PrefabObject child) { if (child == null) { throw new ArgumentNullException("child was null"); } if (child.Prefab != Prefab) { throw new ArgumentException("Prefab of child does not match this object's prefab"); } child.SetParent(this); }
/// <summary> /// Sets the object's parent. /// </summary> /// <param name="parent">The new parent. Pass null to unparent.</param> public void SetParent(PrefabObject parent) { if (parent.Prefab != Prefab) { throw new ArgumentException("Prefab of new parent does not match this object's prefab"); } PrefabObject oldParent = GetParent(); if (oldParent != null) { oldParent.ChildrenIDs.Remove(ID); } if (parent != null) { parent.ChildrenIDs.Add(ID); ParentID = parent.ID; } else { ParentID = string.Empty; } }