using System; using System.Collections; using System.Collections.Generic; using DefaultNamespace; using MotionFramework; using UnityEngine; using UnityEngine.Serialization; using UnityEngine.UI; namespace ToolsPack { public enum ModelTypeEnum { 工具, 设备 } /// /// 工具窗口管理器 /// public class ToolsPackWindowManager : MonoBehaviour { private Dictionary> _toolsNames; private Dictionary> _toolsNamesString; [SerializeField] private Transform content; [SerializeField] private Toggle tog; public void OnEnable() { // ChangePage(ModelTypeEnum.工具); StartCoroutine(SetToggleOnNextFrame(tog)); } private IEnumerator SetToggleOnNextFrame(Toggle toggle) { // 等待一帧,确保所有初始化完成 yield return null; // 设置 Toggle 的选中状态 // 设置 isOn 属性为 true toggle.isOn = true; toggle.onValueChanged.Invoke(true); } private void OnDisable() { } /// /// Toggle切换 /// public void ChangePage(ModelTypeEnum windw) { int count = content.childCount; for (int i = 0; i < count; i++) { Destroy(content.GetChild(i).gameObject); } MotionEngine.GetModule().ClearToolsPackWindowItemBts(); if (MotionEngine.GetModule().GetToolsPackScene() == ToolsPackScene.工具间) { //初始化工具集 _toolsNames = MotionEngine.GetModule().GetToolsPack(); GameObject bt = MotionEngine.GetModule().GetToolsPackWindowBt(); foreach (var v in _toolsNames) { List li = MotionEngine.GetModule().GetToolsPackData(v.Key); if (li == null) { foreach (var b in v.Value) { ToolsPackGameObjectComponent tp = b.GetComponent(); if (tp.GetModelTypeEnum() == windw) { ToolsPackWindowItemBtComponent btComponent = Instantiate(bt, content, false).GetComponent(); btComponent.name = v.Key; btComponent.Init(v.Key, v.Key, tp.GetIndex(), tp.GetModelTypeEnum()); MotionEngine.GetModule().AddToolsPackWindowItemBts(btComponent.gameObject); } } } else { foreach (var lis in v.Value) { if (lis.GetComponent().GetModelTypeEnum() == windw) { foreach (var to in li) { ToolsPackGameObjectComponent tp = lis.GetComponent(); ToolsPackWindowItemBtComponent btComponent = Instantiate(bt, content, false).GetComponent(); btComponent.name = to; btComponent.Init(to, v.Key, tp.GetIndex(), tp.GetModelTypeEnum()); MotionEngine.GetModule().AddToolsPackWindowItemBts(btComponent.gameObject); } } } } } } else { _toolsNamesString = MotionEngine.GetModule().GetToolsPackString(); GameObject bt = MotionEngine.GetModule().GetToolsPackWindowBt(); foreach (var v in _toolsNamesString) { List li = MotionEngine.GetModule().GetToolsPackData(v.Key); if (li == null) { foreach (var b in v.Value) { if (b.ModelTypeEnum == windw) { ToolsPackWindowItemBtComponent btComponent = Instantiate(bt, content, false).GetComponent(); btComponent.name = v.Key; btComponent.Init(v.Key, v.Key, b.Index, b.ModelTypeEnum); MotionEngine.GetModule().AddToolsPackWindowItemBts(btComponent.gameObject); } } } else { foreach (var lis in v.Value) { if (lis.ModelTypeEnum == windw) { foreach (var to in li) { ToolsPackWindowItemBtComponent btComponent = Instantiate(bt, content, false).GetComponent(); btComponent.name = to; btComponent.Init(to, v.Key, lis.Index, lis.ModelTypeEnum); MotionEngine.GetModule().AddToolsPackWindowItemBts(btComponent.gameObject); } } } } } } } } }