public T Get <T>(HierarchyScopes scope) where T : class, IComponent { T component; // Must be before Hierarchy. if (scope.Contains(HierarchyScopes.Root) && Root.TryGet(out component)) { return(component); } // Must return if scope is Hierarchy to prevent duplicated work. if (scope.Contains(HierarchyScopes.Hierarchy)) { return(Root.Get <T>(HierarchyScopes.Descendants)); } // Should be before Siblings, Children, Descendants, Parent and Ancestors for fastest resolution. if (scope.Contains(HierarchyScopes.Self) && TryGet(out component)) { return(component); } if (scope.Contains(HierarchyScopes.Siblings) && parent != null && parent.Children.Count > 0) { for (int i = 0; i < parent.Children.Count; i++) { var child = parent.Children[i]; if (child != this && child.TryGet(out component, HierarchyScopes.Self)) { return(component); } } } // Must be before Descendants. if (scope.Contains(HierarchyScopes.Children) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { if (children[i].TryGet(out component, HierarchyScopes.Self)) { return(component); } } } if (scope.Contains(HierarchyScopes.Descendants) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { if (children[i].TryGet(out component, HierarchyScopes.Descendants)) { return(component); } } } // Must be before Ancestors. if (scope.Contains(HierarchyScopes.Parent) && parent != null) { if (parent.TryGet(out component, HierarchyScopes.Self)) { return(component); } } if (scope.Contains(HierarchyScopes.Ancestors) && parent != null) { if (parent.TryGet(out component, HierarchyScopes.Ancestors)) { return(component); } } return(null); }
public void GetAll(List <IComponent> components, Type componentType, HierarchyScopes scope) { Assert.IsNotNull(components); Assert.IsNotNull(componentType); // Must be before Hierarchy. if (scope.Contains(HierarchyScopes.Root)) { components.AddRange(Root.GetAll(componentType)); } // Must return if scope is Hierarchy to prevent duplicated work. if (scope.Contains(HierarchyScopes.Hierarchy)) { Root.GetAll(components, componentType, HierarchyScopes.Descendants); return; } // Should be before Siblings, Children, Descendants, Parent and Ancestors for fastest resolution. if (scope.Contains(HierarchyScopes.Self)) { components.AddRange(GetAll(componentType)); } if (scope.Contains(HierarchyScopes.Siblings) && parent != null && parent.Children.Count > 0) { for (int i = 0; i < parent.Children.Count; i++) { var child = parent.Children[i]; if (child != this) { child.GetAll(components, componentType, HierarchyScopes.Self); } } } // Must be before Descendants. if (scope.Contains(HierarchyScopes.Children) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { children[i].GetAll(components, componentType, HierarchyScopes.Self); } } if (scope.Contains(HierarchyScopes.Descendants) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { children[i].GetAll(components, componentType, HierarchyScopes.Descendants); } } // Must be before Ancestors. if (scope.Contains(HierarchyScopes.Parent) && parent != null) { parent.GetAll(components, componentType, HierarchyScopes.Self); } if (scope.Contains(HierarchyScopes.Ancestors) && parent != null) { parent.GetAll(components, componentType, HierarchyScopes.Ancestors); } }
public bool Has(IComponent component, HierarchyScopes scope) { Assert.IsNotNull(component); // Must be before Hierarchy. if (scope.Contains(HierarchyScopes.Root) && Root.Has(component)) { return(true); } // Must return if scope is Hierarchy to prevent duplicated work. if (scope.Contains(HierarchyScopes.Hierarchy)) { return(Root.Has(component, HierarchyScopes.Descendants)); } // Should be before Siblings, Children, Descendants, Parent and Ancestors for fastest resolution. if (scope.Contains(HierarchyScopes.Self) && Has(component)) { return(true); } if (scope.Contains(HierarchyScopes.Siblings) && parent != null && parent.Children.Count > 0) { for (int i = 0; i < parent.Children.Count; i++) { var child = parent.Children[i]; if (child != this && child.Has(component, HierarchyScopes.Self)) { return(true); } } } // Must be before Descendants. if (scope.Contains(HierarchyScopes.Children) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { if (children[i].Has(component, HierarchyScopes.Self)) { return(true); } } } if (scope.Contains(HierarchyScopes.Descendants) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { if (children[i].Has(component, HierarchyScopes.Descendants)) { return(true); } } } // Must be before Ancestors. if (scope.Contains(HierarchyScopes.Parent) && parent != null && parent.Has(component, HierarchyScopes.Self)) { return(true); } if (scope.Contains(HierarchyScopes.Ancestors) && parent != null && parent.Has(component, HierarchyScopes.Ancestors)) { return(true); } return(false); }
public void SendMessage <TId, TArg>(TId identifier, TArg argument, HierarchyScopes scope) { // Must be before Hierarchy. if (scope.Contains(HierarchyScopes.Root)) { Root.SendMessage(identifier, argument); } // Must return if scope is Hierarchy to prevent duplicated work. if (scope.Contains(HierarchyScopes.Hierarchy)) { Root.SendMessage(identifier, argument, HierarchyScopes.Descendants); return; } // Should be before Siblings, Children, Descendants, Parent and Ancestors for fastest resolution. if (scope.Contains(HierarchyScopes.Self)) { SendMessage(identifier, argument); } if (scope.Contains(HierarchyScopes.Siblings) && parent != null && parent.Children.Count > 0) { for (int i = 0; i < parent.Children.Count; i++) { var child = parent.Children[i]; if (child != this) { child.SendMessage(identifier, argument, HierarchyScopes.Self); } } } // Must be before Descendants. if (scope.Contains(HierarchyScopes.Children) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { children[i].SendMessage(identifier, argument, HierarchyScopes.Self); } } if (scope.Contains(HierarchyScopes.Descendants) && children.Count > 0) { for (int i = 0; i < children.Count; i++) { children[i].SendMessage(identifier, argument, HierarchyScopes.Descendants); } } // Must be before Ancestors. if (scope.Contains(HierarchyScopes.Parent) && parent != null) { parent.SendMessage(identifier, argument, HierarchyScopes.Self); } if (scope.Contains(HierarchyScopes.Ancestors) && parent != null) { parent.SendMessage(identifier, argument, HierarchyScopes.Ancestors); } }