void OnDestroy() { if (ins != null) { ins = null; //reset ui foreach (var p in root.GetComponents <MonoBehaviour>()) { GameObject.DestroyImmediate(p); } int count = root.childCount; for (int i = 0; i < count; i++) { var _panel_sort = root.GetChild(i); //clear script foreach (var p in _panel_sort.GetComponents <MonoBehaviour>()) { GameObject.DestroyImmediate(p); } //clear child-child while (_panel_sort.childCount > 0) { var _child_child = _panel_sort.GetChild(0); GameObject.DestroyImmediate(_child_child.gameObject); } } _acvtive_panels.Clear(); this.root = null; } }
void Awake() { ins = this; root = transform.Find("Root"); int count = root.childCount; for (int i = 0; i < count; i++) { _sort_panels.Add(root.GetChild(i)); } UICanvas = this.GetComponent <RectTransform>(); }