From 10f624a77647b3dc13b7fe13093cf09bc3ce1947 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Wed, 19 Feb 2025 17:23:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=BC=A0=E6=A0=87=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Art/UIPrefab/UIBody3DMouse.prefab | 2 +- Assets/Scripts/Item/Body3DOjbItem.cs | 2 +- Assets/Scripts/UI/UIBody3DMouse.cs | 64 ++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Assets/Art/UIPrefab/UIBody3DMouse.prefab b/Assets/Art/UIPrefab/UIBody3DMouse.prefab index 2fb5d558..7da19ae4 100644 --- a/Assets/Art/UIPrefab/UIBody3DMouse.prefab +++ b/Assets/Art/UIPrefab/UIBody3DMouse.prefab @@ -98,7 +98,7 @@ MonoBehaviour: m_SelectOnDown: {fileID: 0} m_SelectOnLeft: {fileID: 0} m_SelectOnRight: {fileID: 0} - m_Transition: 0 + m_Transition: 1 m_Colors: m_NormalColor: {r: 1, g: 1, b: 1, a: 1} m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} diff --git a/Assets/Scripts/Item/Body3DOjbItem.cs b/Assets/Scripts/Item/Body3DOjbItem.cs index cac75d5a..a0a24ca0 100644 --- a/Assets/Scripts/Item/Body3DOjbItem.cs +++ b/Assets/Scripts/Item/Body3DOjbItem.cs @@ -10,7 +10,7 @@ public class Body3DOjbItem : MonoBehaviour { public Body3D.Body body; - ObjectToggle objToggle; + public ObjectToggle objToggle; ObjDrag objDrag; // ¼һ갴µʱ private float lastClickTime; diff --git a/Assets/Scripts/UI/UIBody3DMouse.cs b/Assets/Scripts/UI/UIBody3DMouse.cs index a1dcdb70..05095ca5 100644 --- a/Assets/Scripts/UI/UIBody3DMouse.cs +++ b/Assets/Scripts/UI/UIBody3DMouse.cs @@ -11,6 +11,8 @@ namespace QFramework.Example public partial class UIBody3DMouse : UIPanel { UIDragItem dragItem; + private GameObject currentHitObject; // ǰе + private bool isObjectHit; // Ƿ屻 protected override void OnInit(IUIData uiData = null) { mData = uiData as UIBody3DMouseData ?? new UIBody3DMouseData(); @@ -18,7 +20,14 @@ namespace QFramework.Example SelectBtn.onClick.AddListener(() => { - + if (currentHitObject != null) + { + var item = currentHitObject.GetComponent(); + if (item != null) + { + item.objToggle.OnValueChanged.Invoke(!item.objToggle.isOn); + } + } }); } @@ -42,7 +51,7 @@ namespace QFramework.Example { if (Point != null && Camera.main != null) { - // ȡImageĵĻ + // ȡ Image ĵĻ Vector2 imageCenter = new Vector2(Point.rectTransform.position.x, Point.rectTransform.position.y); // ĻתΪ @@ -52,12 +61,57 @@ namespace QFramework.Example // ߼ if (Physics.Raycast(ray, out hit)) { - // ӡ - Debug.LogError("е: " + hit.collider.gameObject.name); + GameObject hitObject = hit.collider.gameObject; + + if (!isObjectHit) + { + // ״ν + currentHitObject = hitObject; + isObjectHit = true; + Debug.Log("߽: " + hitObject.name); + OnEnterBody(currentHitObject); + } + else if (currentHitObject != hitObject) + { + // ߴ֮ǰƳ + Debug.Log("Ƴ: " + currentHitObject.name); + OnExitBody(currentHitObject); + currentHitObject = hitObject; + OnEnterBody(currentHitObject); + Debug.Log("߽: " + hitObject.name); + } + } + else + { + if (isObjectHit) + { + // Ƴǰ + OnExitBody(currentHitObject); + Debug.Log("Ƴ: " + currentHitObject.name); + currentHitObject = null; + isObjectHit = false; + } + } + } + + } + + void OnEnterBody(GameObject obj) + { + if (obj != null) + { + var bodyItem = currentHitObject.GetComponent(); + if (bodyItem != null) + { + BodyName.text = bodyItem.body.Name; + BodyName.gameObject.SetActive(true); } } } - + void OnExitBody(GameObject obj) + { + BodyName.gameObject.SetActive(false); + } protected override void OnShow() {