shenjianxing c8642b1afb 修复bug
2025-04-18 15:03:20 +08:00

578 lines
21 KiB
C#
Raw 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 DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using XMLTool;
using System;
using static XMLTool.Body3D;
using Turing.Core.TuringInput;
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>();
float leftBgOriginalY = 0;
ResLoader loader;
Shader shader;
protected override void OnInit(IUIData uiData = null)
{
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuithandler).UnRegisterWhenGameObjectDestroyed(this);
StringEventSystem.Global.Register($"On{UIBody3DMenuTree.Name}Close", OnUIBody3DMenuTreeClose);
loader = ResLoader.Allocate();
leftBgOriginalY = LeftBg.rectTransform.sizeDelta.y;
DragBtn.onValueChanged.AddListener(isOn =>
{
CheckHighUI(DragBtn.transform, 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<IObjDrag>().OnDoubleClick();
}
});
ActiveBtn.onValueChanged.AddListener(isOn =>
{
CheckHighUI(ActiveBtn.transform, 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<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<IObjDrag>().OnDoubleClick();
}
}
});
HideAll.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
LeftBg.GetComponent<Mask>().enabled = true;
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);
HideAll.transform.SetAsFirstSibling();
});
RightContent.GetComponent<DOTweenAnimation>().DORestart();
RightBottom.GetComponent<DOTweenAnimation>().DORestart();
HideAll.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><>ʾ";
}
else
{
HideAll.transform.SetAsLastSibling();
DOTween.To(() => LeftBg.rectTransform.sizeDelta.y,
(value) => { LeftBg.rectTransform.sizeDelta = new Vector2(LeftBg.rectTransform.sizeDelta.x, value); }, leftBgOriginalY, 0.5f).OnComplete(() =>
{
LeftBg.GetComponent<Mask>().enabled = false;
});
RightContent.GetComponent<DOTweenAnimation>().DOPlayBackwards();
RightBottom.GetComponent<DOTweenAnimation>().DOPlayBackwards();
HideAll.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><><EFBFBD><EFBFBD>";
}
CloseBtn.gameObject.SetActive(!isOn);
});
MouseBtn.onValueChanged.AddListener(isOn =>
{
CheckHighUI(MouseBtn.transform, isOn);
if (isOn)
{
UIKit.OpenPanelAsync<UIBody3DMouse>().ToAction().StartGlobal();
}
else
{
UIKit.HidePanel<UIBody3DMouse>();
}
});
DrawBtn.onValueChanged.AddListener((isOn) =>
{
CheckHighUI(DrawBtn.transform, isOn);
if (isOn)
{
UIKit.OpenPanelAsync<UIDraw>().ToAction().StartGlobal();
}
else
{
UIKit.HidePanel<UIDraw>();
}
});
RotMode.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
RotMode.transform.Find("Normal").gameObject.SetActive(false);
RotMode.transform.Find("High").gameObject.SetActive(true);
RotMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת";
RotMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = Color.white;
Show3DCamera.instance.ChangeMode(Show3DCamera.RotationType.Spherical);
}
else
{
RotMode.transform.Find("Normal").gameObject.SetActive(true);
RotMode.transform.Find("High").gameObject.SetActive(false);
RotMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = <><D6B1><EFBFBD><EFBFBD>ת";
RotMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = new Color(74f / 255f, 91f / 255f, 116f / 255f);
Show3DCamera.instance.ChangeMode(Show3DCamera.RotationType.Orbit);
}
});
LineMode.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
LineMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = <><C8A1><EFBFBD>߿<EFBFBD>";
LineMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = Color.white;
if (shader == null)
{
shader = Shader.Find("URP/WhiteOutline");
}
TypeEventSystem.Global.Send(new OnChangeMat() { shader = shader });
}
else
{
LineMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22>߿<EFBFBD>ģʽ";
LineMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = new Color(74f / 255f, 91f / 255f, 116f / 255f);
TypeEventSystem.Global.Send(new OnChangeMat() { shader = null });
}
});
LockMode.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
LockMode.transform.Find("Normal").gameObject.SetActive(false);
LockMode.transform.Find("High").gameObject.SetActive(true);
LockMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ";
LockMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = Color.white;
}
else
{
LockMode.transform.Find("Normal").gameObject.SetActive(true);
LockMode.transform.Find("High").gameObject.SetActive(false);
LockMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().text = "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļ";
LockMode.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = new Color(74f / 255f, 91f / 255f, 116f / 255f);
}
TypeEventSystem.Global.Send<OnLock>(new OnLock() { isLock = isOn });
});
CloseBtn.onClick.AddListener(() =>
{
Hide();
TypeEventSystem.Global.Send<OnModuleQuit>();
UIKit.OpenPanelAsync<UIModuleSelect>().ToAction().StartGlobal();
});
BgBtn.onValueChanged.AddListener(isOn =>
{
if (isOn)
{
BgBtn.transform.Find("High").gameObject.SetActive(true);
BgSelect.GetComponent<DOTweenAnimation>().DOPlayForward();
}
else
{
BgBtn.transform.Find("High").gameObject.SetActive(false);
BgSelect.GetComponent<DOTweenAnimation>().DOPlayBackwards();
}
});
White.onValueChanged.AddListener(isOn =>
{
White.transform.Find("High").gameObject.SetActive(isOn);
if (isOn)
{
StringEventSystem.Global.Send<string>("BgChange", White.name);
White.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = Color.white;
}
else
{
White.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = new Color(74f / 255f, 91f / 255f, 116f / 255f);
}
});
Black.onValueChanged.AddListener(isOn =>
{
Black.transform.Find("High").gameObject.SetActive(isOn);
if (isOn)
{
StringEventSystem.Global.Send<string>("BgChange", Black.name);
Black.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = Color.white;
}
else
{
Black.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = new Color(74f / 255f, 91f / 255f, 116f / 255f);
}
});
Grey.onValueChanged.AddListener(isOn =>
{
Grey.transform.Find("High").gameObject.SetActive(isOn);
if (isOn)
{
StringEventSystem.Global.Send<string>("BgChange", Grey.name);
Grey.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = Color.white;
}
else
{
Grey.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = new Color(74f / 255f, 91f / 255f, 116f / 255f);
}
});
Gradient.onValueChanged.AddListener(isOn =>
{
Gradient.transform.Find("High").gameObject.SetActive(isOn);
if (isOn)
{
StringEventSystem.Global.Send<string>("BgChange", Gradient.name);
Gradient.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = Color.white;
}
else
{
Gradient.transform.Find("Label").GetComponent<TextMeshProUGUI>().color = new Color(74f / 255f, 91f / 255f, 116f / 255f);
}
});
PicBtn.onClick.AddListener(() =>
{
string fileName = ChinarFileController.SaveProject(".png");
if (string.IsNullOrEmpty(fileName))
{
return;
}
TypeEventSystem.Global.Send<BeginScreenShot>(new BeginScreenShot());
gameObject.SetActive(false);
// <20><><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD>
//string fileName = "Screenshot_" + System.DateTime.Now.ToString("yyyyMMddHHmmss") + ".png";
// <20><><EFBFBD>ý<EFBFBD><C3BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
ScreenCapture.CaptureScreenshot(fileName);
ActionKit.DelayFrame(1, () =>
{
gameObject.SetActive(true);
TypeEventSystem.Global.Send<EndScreenShot>(new EndScreenShot());
}).StartGlobal();
});
help.onClick.AddListener(() =>
{
UIKit.OpenPanelAsync<UIHelp>(canvasLevel: UILevel.PopUI).ToAction().Start(this);
});
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
#if Turing
UIRoot.Instance.transform.Find("ZStylus").GetComponent<TuringStylus>().OnButtonPressing.AddListener(OnButtonPressing);
#endif
}
#if Turing
private void OnButtonPressing(TuringPointer arg0, int arg1)
{
if (arg1 == 1)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ʹ<E5A3AC><CAB9> Time.deltaTime ȷ<><C8B7><EFBFBD><EFBFBD>ת<EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>޹<EFBFBD>
root.transform.Rotate(Vector3.up, -100 * Time.deltaTime);
}
else if (arg1 == 2)
{ // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ʹ<E5A3AC><CAB9> Time.deltaTime ȷ<><C8B7><EFBFBD><EFBFBD>ת<EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>޹<EFBFBD>
root.transform.Rotate(Vector3.up, 100 * Time.deltaTime);
}
}
#endif
private void OnUIBody3DMenuTreeClose()
{
OnShow();
}
/// <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);
}
}
private void OnModuleQuithandler(OnModuleQuit quit)
{
Hide();
}
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();
TitleName.text = Global.Instance.curModule.ModuleName;
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("Content/Btns").gameObject.SetActive(false);
bodyItem.transform.Find("Content/Label").GetComponent<TextMeshProUGUI>().text = body.Name;
var bodyToggle = bodyItem.GetComponent<Toggle>();
GameObject obj = Utility.FindObj(body.Path);
obj.SetActive(body.isShow);
bodyToggle.onValueChanged.AddListener(isOn =>
{
SetAllChildren<Transform>(obj.transform, isOn);
obj.SetActive(isOn);
});
bodyToggle.isOn = body.isShow;
var iconImg = bodyItem.transform.Find("Icon").GetComponent<Image>();
LoadIcon(body.Icon, body, iconImg);
}
}
BodyList.RemoveAllChildren();
bodyListIndex.Clear();
foreach (var list in bodyList)
{
var body = list.Value;
Utility.FindObj(body.Path)?.SetActive(true);
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);
}
var bodyItem = GameObject.Instantiate(BodyItem.gameObject, BodyContent);
bodyItem.transform.Find("Content/Label").GetComponent<TextMeshProUGUI>().text = body.Name;
bodyItem.GetComponent<Toggle>().interactable = false;
var add = bodyItem.transform.Find("Content/Btns/Add").gameObject;
var sub = bodyItem.transform.Find("Content/Btns/Sub").gameObject;
sub.name = add.name = body.Name;
add.GetComponent<Button>().onClick.AddListener(() =>
{
bodyListIndex[add.name]?.Add();
});
sub.GetComponent<Button>().onClick.AddListener(() =>
{
bodyListIndex[add.name]?.Sub();
});
var iconImg = bodyItem.transform.Find("Icon").GetComponent<Image>();
LoadIcon(body.Icon, body, iconImg);
}
FreeCameraController.instance.gameObject.SetActive(false);
Show3DCamera.instance.gameObject.SetActive(true);
ResetCamera(-1);
loader.LoadAsync();
}
public void SetAllChildren<T>(Transform parent, bool isOn)
{
for (int i = 0; i < parent.childCount; i++)
{
Transform trans = parent.GetChild(i);
T t = trans.GetComponent<T>();
if (t != null)
{
trans.gameObject.SetActive(isOn);
}
SetAllChildren<T>(trans, isOn);
}
}
public void LoadIcon(string path, Body body, Image iconImg)
{
if (string.IsNullOrEmpty(body.Icon) == false)
{
iconImg.gameObject.name = body.Icon;
var localImageUrl = Global.imagePath + body.Icon;
loader.Add2Load(localImageUrl.ToNetImageResName(),
(bool success, IRes res) =>
{
if (success)
{
iconImg.sprite = Utility.GetSprite(res.Asset as Texture2D);
iconImg.SetNativeSize();
}
});
}
}
public void ResetCamera(float moveTime)
{
Show3DCamera.instance.ResetCamera(root.transform);
}
protected override void OnShow()
{
if (mData != null && mData.body != null && mData.body.subBody != null)
{
int index = 0;
foreach (var item in mData.body.subBody)
{
Transform trans = BodyContent.GetChild(index);
index++;
if (item.Value.isBodyList == true)
{
continue;
}
trans.GetComponent<Toggle>().isOn = Utility.FindObj(item.Value.Path).activeSelf;
}
}
}
//private void Update()
//{
// if (Input.GetKey(KeyCode.A))
// {
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ʹ<E5A3AC><CAB9> Time.deltaTime ȷ<><C8B7><EFBFBD><EFBFBD>ת<EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>޹<EFBFBD>
// root.transform.Rotate(Vector3.up, -100 * Time.deltaTime);
// }
// if (Input.GetKey(KeyCode.B))
// {
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD><D7AA><EFBFBD>ʹ<E5A3AC><CAB9> Time.deltaTime ȷ<><C8B7><EFBFBD><EFBFBD>ת<EFBFBD>ٶ<EFBFBD><D9B6><EFBFBD>֡<EFBFBD><D6A1><EFBFBD>޹<EFBFBD>
// root.transform.Rotate(Vector3.up, 100 * Time.deltaTime);
// }
//}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}