protected override void Awake() { if (!m_audioSource) { m_audioSource = this.GetComponent <AudioSource>(); } m_controlType = ControlType.IMCCanvas; m_containerType = ContainerType.Container; IMCUIManager.Instance.CanvasList.Add(this); for (int i = 0; i < this.transform.childCount; i++) { IMCForm tempform = this.transform.GetChild(i).gameObject.GetComponent <IMCForm>(); if (tempform) { tempform.canvas = this; forms.Add(tempform); if (tempform.showOnAwake) { tempform.Show(); } } } for (int i = 0; i < forms.Count; i++) { forms[i].Initialize(); } }
/// <summary> /// 从forms数组中移除掉对应元素 /// </summary> public void UnRegisterForm(IMCForm form) { form.canvas = null; if (forms.Contains(form)) { forms.Remove(form); } }
/// <summary> /// 向forms数组中添加对应元素 /// </summary> public void RegisterForm(IMCForm form) { form.canvas = this; form.Initialize(); if (!forms.Contains(form)) { forms.Add(form); } }
void FindRootForm(GameObject obj) { IMCForm uiobj = GetIMCUIBehaviourParent(obj); if (uiobj) { m_form = uiobj; return; } if (obj.transform.parent) { FindRootForm(obj.transform.parent.gameObject); } }
// Actual controls public static GameObject CreateForm(Resources resources) { GameObject go = CreateUIElementRoot("IMC Form", s_ThickElementSize); RectTransform rectTransform = go.GetComponent <RectTransform>(); rectTransform.anchorMin = Vector2.zero; rectTransform.anchorMax = Vector2.one; rectTransform.anchoredPosition = Vector2.zero; rectTransform.sizeDelta = Vector2.zero; IMCForm form = go.AddComponent <IMCForm>(); IMCImage image = go.AddComponent <IMCImage>(); image.sprite = resources.background; image.type = IMCImage.Type.Sliced; image.color = Color.white; go.AddComponent <CanvasGroup>(); return(go); }