private void SetupTemplate() { this.validTemplate = false; if (!this.m_Template) { UnityEngine.Debug.LogError("The dropdown template is not assigned. The template needs to be assigned and must have a child GameObject with a Toggle component serving as the item.", this); } else { GameObject gameObject = this.m_Template.gameObject; gameObject.SetActive(true); Toggle componentInChildren = this.m_Template.GetComponentInChildren <Toggle>(); this.validTemplate = true; if (!componentInChildren || componentInChildren.transform == this.template) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The template must have a child GameObject with a Toggle component serving as the item.", this.template); } else if (!(componentInChildren.transform.parent is RectTransform)) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The child GameObject with a Toggle component (the item) must have a RectTransform on its parent.", this.template); } else if (this.itemText != null && !this.itemText.transform.IsChildOf(componentInChildren.transform)) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The Item Text must be on the item GameObject or children of it.", this.template); } else if (this.itemImage != null && !this.itemImage.transform.IsChildOf(componentInChildren.transform)) { this.validTemplate = false; UnityEngine.Debug.LogError("The dropdown template is not valid. The Item Image must be on the item GameObject or children of it.", this.template); } if (!this.validTemplate) { gameObject.SetActive(false); } else { Dropdown.DropdownItem dropdownItem = componentInChildren.gameObject.AddComponent <Dropdown.DropdownItem>(); dropdownItem.text = this.m_ItemText; dropdownItem.image = this.m_ItemImage; dropdownItem.toggle = componentInChildren; dropdownItem.rectTransform = (RectTransform)componentInChildren.transform; Canvas orAddComponent = Dropdown.GetOrAddComponent <Canvas>(gameObject); orAddComponent.overrideSorting = true; orAddComponent.sortingOrder = 30000; Dropdown.GetOrAddComponent <GraphicRaycaster>(gameObject); Dropdown.GetOrAddComponent <CanvasGroup>(gameObject); gameObject.SetActive(false); this.validTemplate = true; } } }