using UnityEngine; using UnityEngine.UI; using XMLTool; using TMPro; using System.Collections.Generic; using static XMLTool.Body3D; using UnityEngine.Assertions.Must; namespace QFramework.Example { public class UIBody3DData : UIPanelData { public Body3D.Body body = new Body3D.Body(); } public partial class UIBody3D : UIPanel { GameObject root; public Dictionary bodyList { get; set; } = new Dictionary(); public class BodyListItem { public Body3D.Body root; public List bodys = new List(); public int index = 0; public string GetCurName() { if (index > bodys.Count - 1 || index < 0) { return null; } return bodys[index]; } public void Add() { if (index < bodys.Count) { string name = bodys[index]; var body = root.subBody[name]; Utility.FindObj(body.Path)?.SetActive(true); index++; } } public void Sub() { if (index > 0) { index--; string name = bodys[index]; var body = root.subBody[name]; Utility.FindObj(body.Path)?.SetActive(false); } } } Dictionary bodyListIndex = new Dictionary(); protected override void OnInit(IUIData uiData = null) { DragBtn.onValueChanged.AddListener(isOn => { DragBtn.transform.Find("SubBtns").gameObject.SetActive(isOn); Body3DController.Instance.allowDrag = isOn; Body3DController.Instance.SetStatus(Body3DController.Status.Drag, isOn); TypeEventSystem.Global.Send(); }); DragBack.onClick.AddListener(() => { GameObject obj = Body3DController.Instance.PopMoveObj(); if (obj != null) { obj.GetComponent().OnDoubleClick(); } }); ActiveBtn.onValueChanged.AddListener(isOn => { ActiveBtn.transform.Find("SubBtns").gameObject.SetActive(isOn); Body3DController.Instance.SetStatus(Body3DController.Status.Active, isOn); }); ActiveBack.onClick.AddListener(() => { Body3DController.Instance.PopActiveObj()?.gameObject.SetActive(true); }); ResetBtn.onClick.AddListener(() => { ResetCamera(0.5f); }); MenuBtn.onClick.AddListener(() => { UIKit.OpenPanelAsync(canvasLevel: UILevel.PopUI, new UIBody3DMenuTreeData() { body = mData.body }).ToAction().StartGlobal(); Hide(); }); } protected override void OnOpen(IUIData uiData = null) { if (uiData!=null) { mData = uiData as UIBody3DData ?? new UIBody3DData(); } BodyContent.RemoveAllChildren(); root = Utility.FindObj(mData.body.Path); root.SetActive(true); bodyList.Clear(); foreach (var bodyData in mData.body.subBody) { if (bodyData.Value.isBodyList == true) { bodyList.Add(bodyData.Value.Name, bodyData.Value); } else { var body = bodyData.Value; var bodyItem = GameObject.Instantiate(BodyItem.gameObject, BodyContent); bodyItem.transform.Find("Label").GetComponent().text = body.Name; var bodyToggle = bodyItem.GetComponent(); bodyToggle.isOn = body.isShow; GameObject obj = Utility.FindObj(body.Path); obj.SetActive(body.isShow); bodyToggle.onValueChanged.AddListener(isOn => { obj.SetActive(isOn); }); } } BodyList.RemoveAllChildren(); bodyListIndex.Clear(); foreach (var list in bodyList) { var body = list.Value; var add = GameObject.Instantiate(BodyBtn.gameObject, BodyList); var sub = GameObject.Instantiate(BodyBtn.gameObject, BodyList); add.transform.Find("Label").GetComponent().text = body.Name + "+"; sub.transform.Find("Label").GetComponent().text = body.Name + "-"; sub.name = add.name = body.Name; bodyListIndex.Add(body.Name, new BodyListItem() { index = 0, root = body }); bodyListIndex[body.Name].bodys.Clear(); foreach (var subList in body.subBody) { bodyListIndex[body.Name].bodys.Add(subList.Value.Name); Utility.FindObj(subList.Value.Path)?.SetActive(false); } add.GetComponent