From 194672f17c7423ac6ab404ef3be4647f84e1df83 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Thu, 13 Feb 2025 17:39:33 +0800 Subject: [PATCH] =?UTF-8?q?3D=E8=A7=A3=E5=89=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Controller/Body3DController.cs | 7 ++++- Assets/Scripts/Item/Body3DOjbItem.cs | 27 +++++++++++++------ Assets/Scripts/UI/UIBody3D.cs | 2 ++ 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/Assets/Scripts/Controller/Body3DController.cs b/Assets/Scripts/Controller/Body3DController.cs index db550de3..274b4345 100644 --- a/Assets/Scripts/Controller/Body3DController.cs +++ b/Assets/Scripts/Controller/Body3DController.cs @@ -15,7 +15,7 @@ public class Body3DController : MonoSingleton { Normal = 1 << 0, Active = 1 << 1, - Move = 1 << 2, + Drag = 1 << 2, } Body3DController() { } @@ -87,6 +87,11 @@ public class Body3DController : MonoSingleton } } + public bool CheckStatus(Status status) + { + return (this.status & status) == status; + } + public void Active(bool isActive) diff --git a/Assets/Scripts/Item/Body3DOjbItem.cs b/Assets/Scripts/Item/Body3DOjbItem.cs index d2073ef6..0c62dce5 100644 --- a/Assets/Scripts/Item/Body3DOjbItem.cs +++ b/Assets/Scripts/Item/Body3DOjbItem.cs @@ -34,18 +34,29 @@ public class Body3DOjbItem : MonoBehaviour objToggle.OnValueChanged.AddListener(isOn => { - colorToggle?.SetColor(isOn); - objDrag = gameObject.GetOrAddComponent(); - RefreshDrag(); - TypeEventSystem.Global.Send(new OnBody3DSelected() { isOn = isOn, obj = gameObject }); - if (isOn) + if (Body3DController.Instance.CheckStatus(Body3DController.Status.Active)) { - TypeEventSystem.Global.Register(OnBody3DDragHandler); + if (isOn == true) + { + gameObject.SetActive(false); + } } else { - TypeEventSystem.Global.UnRegister(OnBody3DDragHandler); + colorToggle?.SetColor(isOn); + objDrag = gameObject.GetOrAddComponent(); + RefreshDrag(); + TypeEventSystem.Global.Send(new OnBody3DSelected() { isOn = isOn, obj = gameObject }); + if (isOn) + { + TypeEventSystem.Global.Register(OnBody3DDragHandler); + } + else + { + TypeEventSystem.Global.UnRegister(OnBody3DDragHandler); + } } + }); } @@ -61,7 +72,7 @@ public class Body3DOjbItem : MonoBehaviour { if (objToggle != null && objDrag != null) { - objDrag.isOn = objToggle.isOn && Body3DController.Instance.allowDrag; + objDrag.isOn = objToggle.isOn && Body3DController.Instance.CheckStatus(Body3DController.Status.Drag); } } } diff --git a/Assets/Scripts/UI/UIBody3D.cs b/Assets/Scripts/UI/UIBody3D.cs index e9c1352e..405beec1 100644 --- a/Assets/Scripts/UI/UIBody3D.cs +++ b/Assets/Scripts/UI/UIBody3D.cs @@ -17,6 +17,7 @@ namespace QFramework.Example { DragBtn.transform.Find("SubBtns").gameObject.SetActive(isOn); Body3DController.Instance.allowDrag = isOn; + Body3DController.Instance.SetStatus(Body3DController.Status.Drag, isOn); TypeEventSystem.Global.Send(); }); DragBack.onClick.AddListener(() => @@ -27,6 +28,7 @@ namespace QFramework.Example ActiveBtn.onValueChanged.AddListener(isOn => { ActiveBtn.transform.Find("SubBtns").gameObject.SetActive(isOn); + Body3DController.Instance.SetStatus(Body3DController.Status.Active, isOn); }); ActiveBack.onClick.AddListener(() =>