private void Start() { // Root should already exist just grab child if (rootObject == null) { rootObject = transform.GetChild(0).gameObject; } int groupSetting = CommandSettings.PerformanceHUDMode; // Just a guard statement essentially if (PerformanceComponentGroups.groups.Length > groupSetting) { UnityDebugger.Debugger.Log("Performance", "The current channel was set to index: " + groupSetting); currentGroup = PerformanceComponentGroups.groups[groupSetting]; // Order by ascending using Linq if (currentGroup.disableUI == true) { currentGroup.groupElements = currentGroup.groupElements.OrderBy(c => c.PriorityID()).ToArray(); } } else if (groupSetting > 0 && PerformanceComponentGroups.groups.Length > 0) { // If so then just set to first option (normally none) UnityDebugger.Debugger.LogError("Performance", "Index out of range: Current group is set to 0" + groupSetting); } else { // Else set to none (none is a readonly so it should always exist) UnityDebugger.Debugger.LogError("Performance", "Array Empty: The PerformanceComponentGroups.groups array is empty"); currentGroup = PerformanceComponentGroups.None; } // Setup UI DirtyUI(); }
/// <summary> /// Clean and Re-Draw /// Can be static cause it shouldn't matter. /// </summary> public static void DirtyUI() { // Guard if (rootObject == null) { return; } // Could be improved but its fine rootObject.transform.parent.gameObject.SetActive(true); // Clear foreach (Transform child in rootObject.transform) { Destroy(child.gameObject); } // Draw // Get new Performance Mode/Group currentGroup = PerformanceComponentGroups.groups[CommandSettings.PerformanceHUDMode]; // Order by ascending using Linq if (currentGroup.disableUI == true) { currentGroup.groupElements = currentGroup.groupElements.OrderBy(c => c.PriorityID()).ToArray(); } // Draw and Begin UI Functionality foreach (BasePerformanceComponent element in currentGroup.groupElements) { BasePerformanceComponentUI go = ((GameObject)Instantiate(Resources.Load(element.NameOfComponent()))).GetComponent <BasePerformanceComponentUI>(); go.gameObject.transform.SetParent(rootObject.transform); element.Start(go); } }