适配VR一体机

This commit is contained in:
shenjianxing 2025-03-20 13:21:32 +08:00
parent 55a59d57d2
commit cd482fde08
7 changed files with 61 additions and 5 deletions

View File

@ -49,6 +49,11 @@ namespace GCSeries.Core.Input
{ {
} }
[Serializable]
public class CollisionClickEvent : UnityEvent<ZPointer, int, GameObject>
{
}
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
// Inspector Fields // Inspector Fields
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -170,6 +175,11 @@ namespace GCSeries.Core.Input
[Tooltip("Event dispatched when the pointer exits an object.")] [Tooltip("Event dispatched when the pointer exits an object.")]
public CollisionEvent OnObjectExited = new CollisionEvent(); public CollisionEvent OnObjectExited = new CollisionEvent();
[Tooltip("µã»÷ÁËÎïÌå")]
public CollisionClickEvent OnClick = new CollisionClickEvent();
/// <summary> /// <summary>
/// Event dispatched when a pointer button becomes pressed. /// Event dispatched when a pointer button becomes pressed.
/// </summary> /// </summary>
@ -726,6 +736,10 @@ namespace GCSeries.Core.Input
if (this._buttonState[i].BecamePressed) if (this._buttonState[i].BecamePressed)
{ {
this.OnButtonPressed.Invoke(this, i); this.OnButtonPressed.Invoke(this, i);
if (_hitInfo.gameObject != null)
{
this.OnClick.Invoke(this, i, _hitInfo.gameObject);
}
} }
if (this._buttonState[i].BecameReleased) if (this._buttonState[i].BecameReleased)

View File

@ -372,7 +372,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
EventCamera: {fileID: 263436429275714491} EventCamera: {fileID: 263436429275714491}
Visualization: {fileID: 7822688151064336048} Visualization: {fileID: 7822688151064336048}
MaxHitDistance: 0.75 MaxHitDistance: 1.5
MaxHitRadius: 0 MaxHitRadius: 0
IgnoreMask: IgnoreMask:
serializedVersion: 2 serializedVersion: 2
@ -392,6 +392,9 @@ MonoBehaviour:
OnObjectExited: OnObjectExited:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
OnClick:
m_PersistentCalls:
m_Calls: []
OnButtonPressed: OnButtonPressed:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
@ -1583,7 +1586,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
EventCamera: {fileID: 263436429275714491} EventCamera: {fileID: 263436429275714491}
Visualization: {fileID: 6603607056250446267} Visualization: {fileID: 6603607056250446267}
MaxHitDistance: 0.3 MaxHitDistance: 1.5
MaxHitRadius: 0 MaxHitRadius: 0
IgnoreMask: IgnoreMask:
serializedVersion: 2 serializedVersion: 2
@ -1603,6 +1606,9 @@ MonoBehaviour:
OnObjectExited: OnObjectExited:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
OnClick:
m_PersistentCalls:
m_Calls: []
OnButtonPressed: OnButtonPressed:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []

View File

@ -90,6 +90,9 @@ namespace QFramework
break; break;
} }
} }
#if VR
effect.constantWidth = false;
#endif
} }
else else
{ {

View File

@ -58,9 +58,9 @@ public class MoveAction : IAction
{ {
obj = UIRoot.Instance.transform.Find("ZFrame").gameObject; obj = UIRoot.Instance.transform.Find("ZFrame").gameObject;
} }
#else
obj = Utility.FindObj(path);
#endif #endif
obj = Utility.FindObj(path);
if (obj == null) if (obj == null)
{ {
Debug.LogError($"没有找到路径{path}"); Debug.LogError($"没有找到路径{path}");

View File

@ -1,3 +1,4 @@
using GCSeries.Core.Input;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@ -17,6 +18,7 @@ namespace QFramework
string path; string path;
string deviceName; string deviceName;
bool isRight; bool isRight;
public static ObjClickCondition Allocate(string path, Dictionary<string, string> datas) public static ObjClickCondition Allocate(string path, Dictionary<string, string> datas)
{ {
var conditionAction = mSimpleObjectPool.Allocate(); var conditionAction = mSimpleObjectPool.Allocate();
@ -49,6 +51,9 @@ namespace QFramework
} }
} }
} }
#if VR
#else
if (Input.GetMouseButtonUp(0) && EventSystem.current.IsPointerOverGameObject() == false) if (Input.GetMouseButtonUp(0) && EventSystem.current.IsPointerOverGameObject() == false)
{ {
Vector3 mousePos = Input.mousePosition; Vector3 mousePos = Input.mousePosition;
@ -66,7 +71,7 @@ namespace QFramework
} }
} }
} }
#endif
return false; return false;
} }
@ -76,7 +81,22 @@ namespace QFramework
public ActionStatus Status { get; set; } public ActionStatus Status { get; set; }
public void OnStart() public void OnStart()
{ {
#if VR
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
#endif
} }
#if VR
public void OnClick(ZPointer pointer, int index, GameObject obj)
{
if (this.obj != null && obj == this.obj)
{
this.Finish();
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnClick.RemoveListener(OnClick);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnClick.RemoveListener(OnClick);
}
}
#endif
public void OnExecute(float dt) public void OnExecute(float dt)
{ {

View File

@ -28,9 +28,19 @@ namespace QFramework
{ {
if (obj == null) if (obj == null)
{ {
#if VR
if (uiPath.Contains("UIRoot/"))
{
uiPath = uiPath.Replace("UIRoot/", "UIRoot/ZCameraRig/ZCanvas/");
}
#endif
obj = Utility.FindObj(uiPath); obj = Utility.FindObj(uiPath);
} }
#if VR
if (obj != null && Input.GetMouseButtonUp(0))
#else
if (obj != null && Input.GetMouseButtonUp(0) && EventSystem.current.IsPointerOverGameObject()) if (obj != null && Input.GetMouseButtonUp(0) && EventSystem.current.IsPointerOverGameObject())
#endif
{ {
return obj == EventSystem.current.currentSelectedGameObject; return obj == EventSystem.current.currentSelectedGameObject;
} }

View File

@ -22,6 +22,9 @@ public class DeviceItem : MonoBehaviour
effect.outlineColor = Utility.ToColor(device.HighColor); effect.outlineColor = Utility.ToColor(device.HighColor);
StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent); StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged); TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
#if VR
effect.constantWidth = false;
#endif
} }
if (device.MeshCollider) if (device.MeshCollider)
{ {