shenjianxing f1d865dc81 修改bug
2025-03-11 13:59:38 +08:00

265 lines
9.0 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using XMLTool;
using TMPro;
using System.Collections.Generic;
using static XMLTool.Body3D;
using DG.Tweening;
using System;
namespace QFramework.Example
{
public class UIBody3DData : UIPanelData
{
public Body3D.Body body = new Body3D.Body();
}
public partial class UIBody3D : UIPanel
{
GameObject root;
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>();
protected override void OnInit(IUIData uiData = null)
{
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuithandler).UnRegisterWhenGameObjectDestroyed(this);
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<OnBody3DDragChanged>();
});
DragBack.onClick.AddListener(() =>
{
GameObject obj = Body3DController.Instance.PopMoveObj();
if (obj != null)
{
obj.GetComponent<ObjDrag>().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(() =>
{
StringEventSystem.Global.Register($"On{UIBody3DMenuTree.Name}Close", OnUIBody3DMenuTreeClose);
UIKit.OpenPanelAsync<UIBody3DMenuTree>(canvasLevel: UILevel.PopUI, new UIBody3DMenuTreeData() { body = mData.body }).ToAction().StartGlobal();
HideSelf(true);
});
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)
{
LeftContent.GetComponent<DOTweenAnimation>().DORestart();
RightContent.GetComponent<DOTweenAnimation>().DORestart();
HideAll.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><>ʾ";
}
else
{
LeftContent.GetComponent<DOTweenAnimation>().DOPlayBackwards();
RightContent.GetComponent<DOTweenAnimation>().DOPlayBackwards();
HideAll.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><><EFBFBD><EFBFBD>";
}
CloseBtn.gameObject.SetActive(!isOn);
});
MouseBtn.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
UIKit.OpenPanelAsync<UIBody3DMouse>().ToAction().StartGlobal();
}
else
{
UIKit.HidePanel<UIBody3DMouse>();
}
});
DrawBtn.onClick.AddListener(() =>
{
StringEventSystem.Global.Register($"On{UIDraw.Name}Close", OnUIDrawClose);
UIKit.OpenPanelAsync<UIDraw>().ToAction().StartGlobal();
HideSelf(true);
});
}
private void OnModuleQuithandler(OnModuleQuit quit)
{
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)
{
if (isTrue)
{
HideAll.GetComponent<DOTweenAnimation>().DORestart();
}
else
{
HideAll.GetComponent<DOTweenAnimation>().DOPlayBackwards();
}
HideAll.isOn = isTrue;
CloseBtn.gameObject.SetActive(!isTrue);
}
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<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();
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<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 });
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<Button>().onClick.AddListener(() =>
{
bodyListIndex[add.name]?.Add();
});
sub.GetComponent<Button>().onClick.AddListener(() =>
{
bodyListIndex[add.name]?.Sub();
});
}
FreeCameraController.instance.gameObject.SetActive(false);
Show3DCamera.instance.gameObject.SetActive(true);
ResetCamera(-1);
}
public void ResetCamera(float moveTime)
{
Show3DCamera.instance.ResetCamera(root.transform);
}
protected override void OnShow()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}