diff --git a/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab b/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab index 75d4b8b5..343b267b 100644 --- a/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab +++ b/Assets/QFramework/Toolkits/UIKit/Scripts/Resources/VRUIRoot.prefab @@ -156,6 +156,7 @@ GameObject: - component: {fileID: 1943472158707926008} - component: {fileID: 6717849271440217812} - component: {fileID: 2720570802681005941} + - component: {fileID: 3686205199050710443} m_Layer: 0 m_Name: ZFrame m_TagString: Untagged @@ -210,6 +211,19 @@ MonoBehaviour: enableCollision: 1 isMov: 1 isRot: 1 +--- !u!114 &3686205199050710443 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 765259898297824089} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b2c08eae7cce6c9479adebcaad5706c3, type: 3} + m_Name: + m_EditorClassIdentifier: + animSpeed: 1 --- !u!1 &1270204780161445289 GameObject: m_ObjectHideFlags: 0 @@ -1674,7 +1688,7 @@ PrefabInstance: m_Modifications: - target: {fileID: 132536, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3} propertyPath: m_Name - value: w + value: Debug objectReference: {fileID: 0} - target: {fileID: 11414302, guid: 67117722a812a2e46ab8cb8eafbf5f5e, type: 3} propertyPath: m_Size diff --git a/Assets/Scripts/Item/DeviceItem.cs b/Assets/Scripts/Item/DeviceItem.cs index 58d03189..9ff9f6fc 100644 --- a/Assets/Scripts/Item/DeviceItem.cs +++ b/Assets/Scripts/Item/DeviceItem.cs @@ -5,6 +5,7 @@ using QFramework.Example; using System; using System.Collections; using System.Collections.Generic; +using System.Runtime.CompilerServices; using UnityEngine; using static OperationController; @@ -25,12 +26,7 @@ public class DeviceItem : MonoBehaviour TypeEventSystem.Global.Register(OnStepChanged); #if VR effect.constantWidth = false; - UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectEntered.AddListener(OnObjEnter); - UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectEntered.AddListener(OnObjEnter); - UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectExited.AddListener(OnObjExit); - UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectExited.AddListener(OnObjExit); - UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectEntered.AddListener(OnClick); - UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectEntered.AddListener(OnClick); + #endif } if (device.MeshCollider) @@ -51,26 +47,40 @@ public class DeviceItem : MonoBehaviour tipItem = gameObject.GetOrAddComponent(); tipItem.Set(device.Tip); } + UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectEntered.AddListener(OnObjEnter); + UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectEntered.AddListener(OnObjEnter); + UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectExited.AddListener(OnObjExit); + UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectExited.AddListener(OnObjExit); + UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnClick.AddListener(OnClick); + UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnClick.AddListener(OnClick); } + #if VR - private void OnClick(ZPointer arg0, GameObject arg1) + + private void OnClick(ZPointer arg0, int arg1, GameObject arg2) { - if (gameObject == arg1) + Debug.LogError($"当前物体:{gameObject.name} 目标物体:{arg2.name}"); + if (gameObject == arg2) { + Debug.LogError("OnClick:" + arg2.name); var effect = gameObject.GetComponent(); if (effect != null) { effect.highlighted = false; } } - } private void OnObjExit(ZPointer arg0, GameObject arg1) { if (gameObject == arg1) { - gameObject.GetComponent().highlighted = false; + Debug.LogError("OnObjExit:" + arg1.name); + var effect = gameObject.GetComponent(); + if (effect) + { + effect.highlighted = false; + } } } @@ -78,7 +88,12 @@ public class DeviceItem : MonoBehaviour { if (gameObject == arg1) { - gameObject.GetComponent().highlighted = true; + Debug.LogError("OnObjEnter:" + arg1.name); + var effect = gameObject.GetComponent(); + if (effect) + { + effect.highlighted = true; + } } } #endif diff --git a/Assets/Scripts/Item/TipItem.cs b/Assets/Scripts/Item/TipItem.cs index 147043a9..ddb1f728 100644 --- a/Assets/Scripts/Item/TipItem.cs +++ b/Assets/Scripts/Item/TipItem.cs @@ -15,22 +15,38 @@ public class TipItem : MonoBehaviour public void Set(string label) { this.label = label; -//#if VR -// UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectEntered.AddListener(OnObjEnter); -// UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectEntered.AddListener(OnObjEnter); -// UIRoot.Instance.transform.Find("ZMouse").GetComponent().OnObjectExited.AddListener(OnObjExit); -// UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectExited.AddListener(OnObjExit); -//#endif +#if VR + UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectEntered.AddListener(OnObjEnter); + UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnObjectExited.AddListener(OnObjExit); + UIRoot.Instance.transform.Find("ZStylus").GetComponent().OnClick.AddListener(OnClick); +#endif + } + + private void OnClick(ZPointer arg0, int arg1, GameObject arg2) + { + if (arg2 == gameObject) + { + if (tip != null) + { + tip.Active(false); + } + } } #if VR private void OnObjExit(ZPointer arg0, GameObject arg1) { - OnExit(); + if (arg1 == gameObject) + { + OnExit(); + } } private void OnObjEnter(ZPointer arg0, GameObject arg1) { - OnEnter(); + if (arg1 == gameObject) + { + OnEnter(); + } } #endif private void OnMouseEnter()