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(() =>