292 lines
10 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;
2025-02-19 13:07:05 +08:00
using DG.Tweening;
2025-02-21 11:49:10 +08:00
using System;
2025-03-11 15:22:41 +08:00
using System.Drawing;
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-03-11 16:27:06 +08:00
float leftBgOriginalY = 0;
2025-02-10 17:23:54 +08:00
protected override void OnInit(IUIData uiData = null)
{
2025-03-11 10:33:07 +08:00
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuithandler).UnRegisterWhenGameObjectDestroyed(this);
2025-03-11 16:27:06 +08:00
leftBgOriginalY = LeftBg.rectTransform.sizeDelta.y;
2025-02-13 11:02:16 +08:00
DragBtn.onValueChanged.AddListener(isOn =>
{
2025-03-11 15:22:41 +08:00
CheckHighUI(DragBtn.transform, 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 =>
{
2025-03-11 15:22:41 +08:00
CheckHighUI(ActiveBtn.transform, 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-17 17:03:48 +08:00
MenuBtn.onClick.AddListener(() =>
{
2025-02-21 11:49:10 +08:00
StringEventSystem.Global.Register($"On{UIBody3DMenuTree.Name}Close", OnUIBody3DMenuTreeClose);
2025-02-17 17:03:48 +08:00
UIKit.OpenPanelAsync<UIBody3DMenuTree>(canvasLevel: UILevel.PopUI, new UIBody3DMenuTreeData() { body = mData.body }).ToAction().StartGlobal();
2025-02-19 14:01:21 +08:00
HideSelf(true);
2025-02-17 17:03:48 +08:00
});
2025-02-19 13:07:05 +08:00
DragReset.onClick.AddListener(() =>
{
while (Body3DController.Instance.moveObjs.Count > 0)
{
GameObject obj = Body3DController.Instance.PopMoveObj();
if (obj != null)
{
obj.GetComponent<ObjDrag>().OnDoubleClick();
}
}
});
HideAll.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
2025-03-11 16:27:06 +08:00
DOTween.To(() => LeftBg.rectTransform.sizeDelta.y,
(value) => { LeftBg.rectTransform.sizeDelta = new Vector2(LeftBg.rectTransform.sizeDelta.x, value); }, 52f, 0.5f).OnComplete(() =>
{
LeftBg.transform.GetChild(0).gameObject.SetActive(false);
});
2025-02-19 14:01:21 +08:00
RightContent.GetComponent<DOTweenAnimation>().DORestart();
2025-02-19 13:07:05 +08:00
HideAll.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><>ʾ";
}
else
{
2025-03-11 16:27:06 +08:00
LeftBg.transform.Find("ResetBtn").gameObject.SetActive(true);
DOTween.To(() => LeftBg.rectTransform.sizeDelta.y,
(value) => { LeftBg.rectTransform.sizeDelta = new Vector2(LeftBg.rectTransform.sizeDelta.x, value); }, leftBgOriginalY, 0.5f);
2025-02-19 14:01:21 +08:00
RightContent.GetComponent<DOTweenAnimation>().DOPlayBackwards();
2025-02-19 13:07:05 +08:00
HideAll.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><><EFBFBD><EFBFBD>";
}
2025-02-19 14:01:21 +08:00
CloseBtn.gameObject.SetActive(!isOn);
2025-02-19 13:07:05 +08:00
});
2025-02-17 17:03:48 +08:00
2025-02-19 16:33:28 +08:00
MouseBtn.onValueChanged.AddListener(isOn =>
{
2025-03-11 15:22:41 +08:00
CheckHighUI(MouseBtn.transform, isOn);
2025-02-19 16:33:28 +08:00
if (isOn)
{
UIKit.OpenPanelAsync<UIBody3DMouse>().ToAction().StartGlobal();
}
else
{
UIKit.HidePanel<UIBody3DMouse>();
}
});
2025-02-21 11:49:10 +08:00
DrawBtn.onClick.AddListener(() =>
{
StringEventSystem.Global.Register($"On{UIDraw.Name}Close", OnUIDrawClose);
UIKit.OpenPanelAsync<UIDraw>().ToAction().StartGlobal();
HideSelf(true);
});
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
2025-02-10 17:23:54 +08:00
}
2025-03-11 15:22:41 +08:00
/// <summary>
/// <20><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UI
/// <20><>ΪUI<55><49><EFBFBD>Ƶ<EFBFBD><C6B5>µ<EFBFBD>ӷ<EFBFBD>״<EFBFBD><D7B4><EFBFBD>
/// </summary>
public void CheckHighUI(Transform trans, bool isOn)
{
Transform target = trans.Find("High");
if (target != null)
{
target.gameObject.SetActive(isOn);
}
}
2025-03-11 10:33:07 +08:00
private void OnModuleQuithandler(OnModuleQuit quit)
{
Hide();
}
2025-02-21 11:49:10 +08:00
private void OnUIDrawClose()
2025-02-19 14:01:21 +08:00
{
2025-02-21 11:49:10 +08:00
StringEventSystem.Global.UnRegister($"On{UIDraw.Name}Close", OnUIDrawClose);
2025-02-19 14:01:21 +08:00
HideSelf(false);
}
2025-02-21 11:49:10 +08:00
private void OnUIBody3DMenuTreeClose()
{
StringEventSystem.Global.UnRegister($"On{UIBody3DMenuTree.Name}Close", OnUIBody3DMenuTreeClose);
HideSelf(false);
}
2025-02-19 14:01:21 +08:00
public void HideSelf(bool isTrue)
{
if (isTrue)
{
HideAll.GetComponent<DOTweenAnimation>().DORestart();
}
else
{
HideAll.GetComponent<DOTweenAnimation>().DOPlayBackwards();
}
HideAll.isOn = isTrue;
CloseBtn.gameObject.SetActive(!isTrue);
}
2025-02-10 17:23:54 +08:00
protected override void OnOpen(IUIData uiData = null)
{
2025-02-19 13:07:05 +08:00
if (uiData != null)
2025-02-17 17:03:48 +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();
2025-02-17 17:03:48 +08:00
bodyListIndex.Clear();
2025-02-14 17:09:41 +08:00
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 });
2025-02-17 17:03:48 +08:00
bodyListIndex[body.Name].bodys.Clear();
2025-02-14 17:09:41 +08:00
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-03-11 13:59:38 +08:00
Show3DCamera.instance.ResetCamera(root.transform);
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()
{
}
}
}