/// <summary> /// Removes member from this EntityCollection. If not in this EntityCollection, attempts to remove from child EntityCollections. Parent transform of member is /// set to null. /// </summary> /// <param name="member">An EntityMember.</param> /// <returns>Returns true if member is in this EntityCollection and is successfully removed.</returns> public bool RemoveMember(EntityMember member) { if (member) { if (member.ParentCollection == this) { Unparent(member); if (childMemberSet.Remove(member)) { return(childMemberDictionary.Remove(member.Coordinates)); } } else { foreach (EntityCollection childCollection in childCollectionSet) { if (childCollection.RemoveMember(member)) { return(true); } } } } return(false); }
/// <summary> /// Adds a unique EntityMember with unique coordinates to this EntityCollection. Parent transform of member is /// set to this EntityCollection's transform. If this member already has a parent collection, it will be moved to this EntityCollection. /// </summary> /// <param name="member">A unique EntityMember with unique coordinates.</param> /// <returns>Returns if member added successfully.</returns> public bool AddMember(EntityMember member) { if (member) { if (member.ParentCollection != null) { member.ParentCollection.RemoveMember(member); } if (childMemberDictionary.ContainsKey(member.Coordinates) || childMemberSet.Contains(member)) { return(false); } else { childMemberDictionary.Add(member.Coordinates, member); childMemberSet.Add(member); Parent(member); return(true); } } return(false); }
private void Start() { entityMember = GetComponent <EntityMember>(); movable = GetComponent <Movable>(); attributes = GetComponent <Attributes>(); }