diff --git a/Assets/Scripts/UI/UIBody3D.cs b/Assets/Scripts/UI/UIBody3D.cs index c316c4d0..09963fdf 100644 --- a/Assets/Scripts/UI/UIBody3D.cs +++ b/Assets/Scripts/UI/UIBody3D.cs @@ -62,6 +62,7 @@ namespace QFramework.Example protected override void OnInit(IUIData uiData = null) { TypeEventSystem.Global.Register(OnModuleQuithandler).UnRegisterWhenGameObjectDestroyed(this); + StringEventSystem.Global.Register($"On{UIBody3DMenuTree.Name}Close", OnUIBody3DMenuTreeClose); loader = ResLoader.Allocate(); leftBgOriginalY = LeftBg.rectTransform.sizeDelta.y; DragBtn.onValueChanged.AddListener(isOn => @@ -99,7 +100,6 @@ namespace QFramework.Example MenuBtn.onClick.AddListener(() => { - //StringEventSystem.Global.Register($"On{UIBody3DMenuTree.Name}Close", OnUIBody3DMenuTreeClose); UIKit.OpenPanelAsync(canvasLevel: UILevel.PopUI, new UIBody3DMenuTreeData() { body = mData.body }).ToAction().StartGlobal(); //HideSelf(true); }); @@ -357,6 +357,11 @@ namespace QFramework.Example } + private void OnUIBody3DMenuTreeClose() + { + OnShow(); + } + /// /// 检查是否有相关UI /// 因为UI设计导致的臃肿代码 @@ -374,17 +379,7 @@ namespace QFramework.Example Hide(); } - //private void OnUIDrawClose() - //{ - // StringEventSystem.Global.UnRegister($"On{UIDraw.Name}Close", OnUIDrawClose); - // HideSelf(false); - //} - //private void OnUIBody3DMenuTreeClose() - //{ - // StringEventSystem.Global.UnRegister($"On{UIBody3DMenuTree.Name}Close", OnUIBody3DMenuTreeClose); - // HideSelf(false); - //} public void HideSelf(bool isTrue) @@ -431,6 +426,7 @@ namespace QFramework.Example obj.SetActive(body.isShow); bodyToggle.onValueChanged.AddListener(isOn => { + SetAllChildren(obj.transform, isOn); obj.SetActive(isOn); }); var iconImg = bodyItem.transform.Find("Icon").GetComponent(); @@ -476,6 +472,19 @@ namespace QFramework.Example } + public void SetAllChildren(Transform parent, bool isOn) + { + for (int i = 0; i < parent.childCount; i++) + { + Transform trans = parent.GetChild(i); + T t = trans.GetComponent(); + if (t != null) + { + trans.gameObject.SetActive(isOn); + } + SetAllChildren(trans, isOn); + } + } public void LoadIcon(string path, Body body, Image iconImg) { if (string.IsNullOrEmpty(body.Icon) == false) @@ -501,6 +510,20 @@ namespace QFramework.Example protected override void OnShow() { + if (mData != null && mData.body != null && mData.body.subBody != null) + { + int index = 0; + foreach (var item in mData.body.subBody) + { + Transform trans = BodyContent.GetChild(index); + index++; + if (item.Value.isBodyList == true) + { + continue; + } + trans.GetComponent().isOn = Utility.FindObj(item.Value.Path).activeSelf; + } + } } protected override void OnHide() diff --git a/Assets/Scripts/UI/UIBody3DMenuTree.cs b/Assets/Scripts/UI/UIBody3DMenuTree.cs index 7c56fe43..e47c74c0 100644 --- a/Assets/Scripts/UI/UIBody3DMenuTree.cs +++ b/Assets/Scripts/UI/UIBody3DMenuTree.cs @@ -204,6 +204,7 @@ namespace QFramework.Example //DOTweenAnimation contentAnim; protected override void OnInit(IUIData uiData = null) { + mData = uiData as UIBody3DMenuTreeData ?? new UIBody3DMenuTreeData(); TypeEventSystem.Global.Register(OnModuleQuithandler).UnRegisterWhenGameObjectDestroyed(this); //contentAnim = RootContent.GetComponent(); // please add init code here @@ -232,6 +233,7 @@ namespace QFramework.Example RefreshSearchContent(str); } }); + BuildTreeUI(mData.body); } private void OnModuleQuithandler(OnModuleQuit quit) @@ -242,10 +244,19 @@ namespace QFramework.Example protected override void OnOpen(IUIData uiData = null) { mData = uiData as UIBody3DMenuTreeData ?? new UIBody3DMenuTreeData(); - //contentAnim.DORestart(); - Content.RemoveAllChildren(); - objBtnDataMap.Clear(); - BuildTreeUI(mData.body); + foreach (var item in mData.body.subBody) + { + if (item.Value.isBodyList) + { + continue; + } + GameObject obj = Utility.FindObj(item.Value.Path); + Button btn = Content.Find(item.Value.Name).Find("Content/Toggle/ObjContent/Obj").GetComponent