void AppendPartsInParent <T>(IWhole target, List <T> list) where T : class, IPart { AppendParts <T>(target, list); if (target.parent != null) { AppendPartsInParent <T>(target.parent, list); } }
void AppendPartsInChildren <T>(IWhole target, List <T> list) where T : class, IPart { AppendParts <T>(target, list); for (int i = 0; i < target.children.Count; ++i) { AppendPartsInChildren <T>(target.children[i], list); } }
public void AddChild(IWhole whole) { if (_children.Contains(whole)) { return; } _children.Add(whole); whole.parent = this; }
void AppendParts <T>(IWhole target, List <T> list) where T : class, IPart { for (int i = 0; i < target.parts.Count; ++i) { if (target.parts[i] is T) { list.Add(target.parts[i] as T); } } }
public void RemoveChild(IWhole whole) { int index = _children.IndexOf(whole); if (index != -1) { _children.RemoveAt(index); whole.parent = null; } }
void CheckEnabledInParent() { bool shouldEnable = allowed; IWhole next = parent; while (shouldEnable && next != null) { shouldEnable = next.allowed; next = next.parent; } running = shouldEnable; }
public void Destroy() { if (_didDestroy) { return; } _didDestroy = true; allowed = false; parent = null; for (int i = _parts.Count - 1; i >= 0; i--) { _parts[i].Disassemble(); } for (int i = _children.Count - 1; i >= 0; i--) { _children[i].Destroy(); } }