169 lines
5.8 KiB
C#
Raw Normal View History

2025-02-10 17:23:54 +08:00
using UnityEngine;
using UnityEngine.UI;
using XMLTool;
using TMPro;
2025-02-14 17:09:41 +08:00
using System.Collections.Generic;
using static XMLTool.Body3D;
using UnityEngine.Assertions.Must;
2025-02-10 17:23:54 +08:00
namespace QFramework.Example
{
public class UIBody3DData : UIPanelData
{
2025-02-11 16:42:39 +08:00
public Body3D.Body body = new Body3D.Body();
2025-02-10 17:23:54 +08:00
}
public partial class UIBody3D : UIPanel
{
2025-02-14 13:20:54 +08:00
GameObject root;
2025-02-14 17:09:41 +08:00
public Dictionary<string, Body> bodyList { get; set; } = new Dictionary<string, Body>();
public class BodyListItem
{
public Body3D.Body root;
public List<string> bodys = new List<string>();
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<string, BodyListItem> bodyListIndex = new Dictionary<string, BodyListItem>();
2025-02-10 17:23:54 +08:00
protected override void OnInit(IUIData uiData = null)
{
2025-02-13 11:02:16 +08:00
DragBtn.onValueChanged.AddListener(isOn =>
{
DragBtn.transform.Find("SubBtns").gameObject.SetActive(isOn);
2025-02-13 11:02:16 +08:00
Body3DController.Instance.allowDrag = isOn;
2025-02-13 17:39:33 +08:00
Body3DController.Instance.SetStatus(Body3DController.Status.Drag, isOn);
2025-02-13 11:02:16 +08:00
TypeEventSystem.Global.Send<OnBody3DDragChanged>();
});
DragBack.onClick.AddListener(() =>
{
2025-02-14 13:20:54 +08:00
GameObject obj = Body3DController.Instance.PopMoveObj();
if (obj != null)
{
obj.GetComponent<ObjDrag>().OnDoubleClick();
}
});
ActiveBtn.onValueChanged.AddListener(isOn =>
{
ActiveBtn.transform.Find("SubBtns").gameObject.SetActive(isOn);
2025-02-13 17:39:33 +08:00
Body3DController.Instance.SetStatus(Body3DController.Status.Active, isOn);
});
ActiveBack.onClick.AddListener(() =>
{
2025-02-14 08:58:46 +08:00
Body3DController.Instance.PopActiveObj()?.gameObject.SetActive(true);
2025-02-13 11:02:16 +08:00
});
2025-02-14 13:20:54 +08:00
ResetBtn.onClick.AddListener(() =>
{
ResetCamera(0.5f);
});
2025-02-10 17:23:54 +08:00
}
protected override void OnOpen(IUIData uiData = null)
{
2025-02-11 16:42:39 +08:00
mData = uiData as UIBody3DData ?? new UIBody3DData();
2025-02-10 17:23:54 +08:00
BodyContent.RemoveAllChildren();
2025-02-14 13:20:54 +08:00
root = Utility.FindObj(mData.body.Path);
root.SetActive(true);
2025-02-14 17:09:41 +08:00
bodyList.Clear();
2025-02-12 17:36:00 +08:00
foreach (var bodyData in mData.body.subBody)
2025-02-10 17:23:54 +08:00
{
2025-02-14 17:09:41 +08:00
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<TextMeshProUGUI>().text = body.Name;
var bodyToggle = bodyItem.GetComponent<Toggle>();
bodyToggle.isOn = body.isShow;
GameObject obj = Utility.FindObj(body.Path);
obj.SetActive(body.isShow);
bodyToggle.onValueChanged.AddListener(isOn =>
{
obj.SetActive(isOn);
});
}
}
BodyList.RemoveAllChildren();
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<TextMeshProUGUI>().text = body.Name + "+";
sub.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = body.Name + "-";
sub.name = add.name = body.Name;
bodyListIndex.Add(body.Name, new BodyListItem() { index = 0, root = body });
foreach (var subList in body.subBody)
{
bodyListIndex[body.Name].bodys.Add(subList.Value.Name);
Utility.FindObj(subList.Value.Path)?.SetActive(false);
}
add.GetComponent<Button>().onClick.AddListener(() =>
{
bodyListIndex[add.name]?.Add();
});
sub.GetComponent<Button>().onClick.AddListener(() =>
2025-02-10 17:23:54 +08:00
{
2025-02-14 17:09:41 +08:00
bodyListIndex[add.name]?.Sub();
2025-02-10 17:23:54 +08:00
});
}
FreeCameraController.instance.gameObject.SetActive(false);
Show3DCamera.instance.gameObject.SetActive(true);
2025-02-14 13:20:54 +08:00
ResetCamera(-1);
2025-02-13 11:02:16 +08:00
2025-02-10 17:23:54 +08:00
}
2025-02-14 13:20:54 +08:00
public void ResetCamera(float moveTime)
{
2025-02-14 17:09:41 +08:00
Show3DCamera.instance.Set(root.transform, distance: 5, isRenderTexture: false, moveTime: moveTime, pitchMin: -80);
2025-02-14 13:20:54 +08:00
}
2025-02-10 17:23:54 +08:00
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}