// ---------[ UTILITY ]--------- /// <summary>Checks a ModContainer's template structure.</summary> public static bool HasValidTemplate(ExplorerFilterTagsDropdown selector, out string helpMessage) { helpMessage = null; // - null checks - if (selector.categoryDisplay == null || !GameTagCategoryDisplay.HasValidTemplate(selector.categoryDisplay, out helpMessage)) { helpMessage = ("The required GameTagCategoryDisplay is missing or" + " has an invalid template."); return(false); } // - Validity checks - bool isValid = true; TagContainerItem tagItem = selector.categoryDisplay.template.tagTemplate; // check for StateToggleDisplay if (tagItem.gameObject.GetComponentInChildren <StateToggleDisplay>(true) == null) { helpMessage = ("This ExplorerFilterTagsDropdown has an invalid template." + "\nThe tag template of the GameTagCategoryDisplay must" + " also have a StateToggleDisplay derived component as" + " a child, or on the same GameObject." + "\n(EG. GameObjectToggle, StateToggle, or SlideToggle.)"); isValid = false; } return(isValid); }
// ---------[ UTILITY ]--------- /// <summary>Checks a display's template structure.</summary> public static bool HasValidTemplate(GameTagCategoryDisplay display, out string helpMessage) { helpMessage = null; bool isValid = true; // null check if (display.template.root == null) { helpMessage = ("This Game Tag Category Display has an invalid template." + "\nThe template root is not assigned."); isValid = false; } // null check else if (display.template.tagTemplate == null) { helpMessage = ("This Game Tag Category Display has an invalid template." + "\nThe tag template is not assigned."); isValid = false; } // template.root is child of Component else if (!display.template.root.IsChildOf(display.transform) || display.template.root == display.transform) { helpMessage = ("This Game Tag Category Display has an invalid template." + "\nThe template root must be a child of this object."); isValid = false; } // template.category is child of, or attached to template.root else if (display.template.categoryLabel.displayComponent != null && !display.template.categoryLabel.displayComponent.transform.IsChildOf(display.template.root) && display.template.categoryLabel.displayComponent.transform != display.template.root) { helpMessage = ("This Game Tag Category Display has an invalid template." + "\nThe category label must be a child of, or attached to" + " the template root."); isValid = false; } // template.tag is child of template.root else if (!display.template.tagTemplate.transform.IsChildOf(display.template.root) || display.template.tagTemplate.transform == display.template.root) { helpMessage = ("This Game Tag Category Display has an invalid template." + "\nThe tag template must be a child of the template root."); isValid = false; } // template.category is not in template.tag hierarchy else if (display.template.categoryLabel.displayComponent != null && (display.template.categoryLabel.displayComponent.transform.IsChildOf(display.template.tagTemplate.transform) || display.template.categoryLabel.displayComponent.transform == display.template.tagTemplate.transform)) { helpMessage = ("This Game Tag Category Display has an invalid template." + "\nThe category label cannot be a child of, or attached to the" + " same transform as the tag template."); isValid = false; } return(isValid); }
// ---------[ INITIALIZATION ]--------- /// <summary>Initialize template.</summary> protected virtual void Awake() { // check template #if DEBUG string message; if (!GameTagCategoryDisplay.HasValidTemplate(this, out message)) { Debug.LogError("[mod.io] " + message, this); return; } #endif // Hide template this.template.root.gameObject.SetActive(false); // Check for category name duplication if (this.template.tagTemplate.categoryName.displayComponent == this.template.categoryLabel.displayComponent) { this.template.tagTemplate.categoryName.SetTextDisplayComponent(null); } // Add item component this.m_itemTemplate = this.template.root.gameObject.GetComponent <CategoryItem>(); if (this.m_itemTemplate == null) { this.m_itemTemplate = this.template.root.gameObject.AddComponent <CategoryItem>(); this.m_itemTemplate.label = this.template.categoryLabel; this.m_itemTemplate.tagContainer = this.template.tagTemplate.transform.parent as RectTransform; this.m_itemTemplate.tagInstances = new TagContainerItem[1] { this.template.tagTemplate, }; } // Collect vars this.m_container = this.template.root.parent as RectTransform; // Clear any instantiated categories List <CategoryItem> itemInstances = new List <CategoryItem>(this.m_container.GetComponentsInChildren <CategoryItem>(true)); itemInstances.Remove(this.m_itemTemplate); foreach (CategoryItem item in itemInstances) { GameObject.Destroy(item.gameObject); } }