/* * /// <summary> * ///some ideas, implement if actualy needed * /// </summary> * public BaseDataBlob ThisRelatedDatablob; * * public InstancesDB ThisEntitesInstancesDB; * * (call this from Set Parent, virtual would be empty, inherited classes would have something below eg) * protected virtual void FilterParents(ComponentTreeHeirarchyAbilityState parentToSet) * { * Type T = typeof(FireControlAbilityState) * if(parentToSet is T) * { * if (ParentState != null) * { * ParentState.ChildrenStates.Remove(this); * } * * ParentState = newParent; * if(newParent != null) * ParentState.ChildrenStates.Add(this); * } * else * throw exception? fail silently? log? * } * * protected virtual void FilterChildren(ComponentTreeHeirarchyAbilityState childToAdd) * { * if(childToAdd is T) * ChildrenState.Add(childToAdd); * else * throw exception? fail silently? log? * } * * * /// <summary> * /// If parent is null, will return an empty list * /// </summary> * /// <typeparam name="T"></typeparam> * /// <returns></returns> * public List<T> GetSiblingsOfType<T>() * where T : ComponentTreeHeirarchyAbilityState * { * if(ParentState == null) * return new List<T>(); * return ParentState.GetChildrenOfType<T>(); * } * * * public List<T> GetChildrenOfType<T>() where T: ComponentTreeHeirarchyAbilityState * { * List<T> children = new List<T>(); * foreach (var child in ChildrenStates) * { * if(child is T) * children.Add((T)child); * } * return children; * } * * public ComponentInstance[] GetChildrenInstancesOfType<T>() where T: ComponentTreeHeirarchyAbilityState * { * var childrenStates = GetChildrenOfType<T>(); * ComponentInstance[] instances = new ComponentInstance[childrenStates.Count]; * for (int i = 0; i < childrenStates.Count; i++) * { * instances[i] = childrenStates[i].ComponentInstance; * } * return instances; * } * */ public ComponentTreeHeirarchyAbilityState GetRoot() { if (ParentState != null) { return(ParentState.GetRoot()); } else { return(this); } }