//------------------------------------------------------------------------/ // CTOR //------------------------------------------------------------------------/ public StratusGameObjectInformation(GameObject target) { // Set target this.target = target; // Set components this.fieldCount = 0; this.propertyCount = 0; Component[] targetComponents = target.GetComponents <Component>(); List <StratusComponentInformation> components = new List <StratusComponentInformation>(); for (int i = 0; i < targetComponents.Length; ++i) { Component component = targetComponents[i]; if (component == null) { throw new Exception($"The component at index {i} is null!"); } StratusComponentInformation componentInfo = new StratusComponentInformation(component); this.fieldCount += componentInfo.fieldCount; this.propertyCount += componentInfo.propertyCount; components.Add(componentInfo); } this.components = components.ToArray(); // Now cache member references this.CacheReferences(); }
//------------------------------------------------------------------------/ // CTOR //------------------------------------------------------------------------/ public MemberReference(MemberInfo member, StratusComponentInformation componentInfo, int index) { this.name = member.Name; this.componentName = componentInfo.name; this.type = member.MemberType; this.memberIndex = index; this.Initialize(componentInfo); }
/// <summary> /// Verifies that the component references for this GameObject are still valid, /// returning false if any components were removed /// </summary> private Change ValidateComponents() { bool watchlistChanged = false; bool changed = false; // Check if any components are null foreach (var component in this.components) { if (component.component == null) { changed = true; if (component.hasWatchList) { watchlistChanged = true; } } else { if (component.valid) { changed |= component.Refresh(); } } } // Check for other component changes Component[] targetComponents = target.GetComponents <Component>(); changed |= this.numberofComponents != targetComponents.Length; // If there's noticeable changes, let's add any components that were not there before if (changed) { List <StratusComponentInformation> currentComponents = new List <StratusComponentInformation>(); currentComponents.AddRangeWhere((StratusComponentInformation component) => { return(component.component != null); }, this.components); // If there's no information for this component, let's add it foreach (var component in targetComponents) { StratusComponentInformation ci = currentComponents.Find(x => x.component == component); if (ci == null) { ci = new StratusComponentInformation(component); currentComponents.Add(ci); } } // Now update the list of components this.components = currentComponents.ToArray(); } if (changed) { if (watchlistChanged) { return(Change.ComponentsAndWatchList); } return(Change.Components); } // If any components were removed, or added, note the change return(Change.None); }
//------------------------------------------------------------------------/ // Methods //------------------------------------------------------------------------/ /// <summary> /// Initializes this member reference, linking it to the component it's part of. /// This needs to be done before attempting to retrieve the value /// </summary> /// <param name="componentInfo"></param> public void Initialize(StratusComponentInformation componentInfo) { this.componentInfo = componentInfo; this.initialized = true; }