//关闭面板方法 public void ClosePanel(string name) { if (!openedPanelDict.ContainsKey(name)) { return; } PanelBase panel = (PanelBase)openedPanelDict[name]; if (panel == null) { return; } openedPanelDict.Remove(name); panel.OnClosing(); //openedPanelDict.Remove(name); panel.OnClosed(); GameObject.Destroy(panel.panelPrefab); Component.Destroy(panel); }
//打开面板方法 public void OpenPanel <T>(string panelPrefabPath, params object[] args) where T : PanelBase { string name = typeof(T).ToString(); if (openedPanelDict.ContainsKey(name)) { return; } PanelBase panel = UI_Root.AddComponent <T>(); //PanelBase panel = new GameObject().AddComponent<T>(); panel.Init(args); openedPanelDict.Add(name, panel); if (panelPrefabPath != "") { } else { panelPrefabPath = panel.panelPrefabPath; } GameObject panelPrefab = Resources.Load <GameObject>(panelPrefabPath); //panelPrefab.AddComponent<T>(); if (panelPrefab == null) { Debug.LogError("[ERROR]OpenPanel<T>():GameObject panelPrefab = Resources.Load<GameObject>(panelPrefabPath)"); } panel.panelPrefab = (GameObject)Instantiate(panelPrefab); Transform transform = panel.panelPrefab.transform; PanelLayer panelLayer = panel.panelLayer; Transform parent = panelLayerDict[panelLayer]; transform.SetParent(parent, false); panel.OnOpening(); panel.OnOpened(); }