完善VR版逻辑

This commit is contained in:
shenjianxing 2025-03-24 10:32:48 +08:00
parent 4984936411
commit 77ebcb713b
3 changed files with 65 additions and 20 deletions

View File

@ -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

View File

@ -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<StepStatusOnChange>(OnStepChanged);
#if VR
effect.constantWidth = false;
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnClick);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnClick);
#endif
}
if (device.MeshCollider)
@ -51,26 +47,40 @@ public class DeviceItem : MonoBehaviour
tipItem = gameObject.GetOrAddComponent<TipItem>();
tipItem.Set(device.Tip);
}
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().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<HighlightEffect>();
if (effect != null)
{
effect.highlighted = false;
}
}
}
private void OnObjExit(ZPointer arg0, GameObject arg1)
{
if (gameObject == arg1)
{
gameObject.GetComponent<HighlightEffect>().highlighted = false;
Debug.LogError("OnObjExit:" + arg1.name);
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect)
{
effect.highlighted = false;
}
}
}
@ -78,7 +88,12 @@ public class DeviceItem : MonoBehaviour
{
if (gameObject == arg1)
{
gameObject.GetComponent<HighlightEffect>().highlighted = true;
Debug.LogError("OnObjEnter:" + arg1.name);
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect)
{
effect.highlighted = true;
}
}
}
#endif

View File

@ -15,23 +15,39 @@ public class TipItem : MonoBehaviour
public void Set(string label)
{
this.label = label;
//#if VR
// UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
// UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
// UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
// UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
//#endif
#if VR
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectEntered.AddListener(OnObjEnter);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnObjectExited.AddListener(OnObjExit);
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().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)
{
if (arg1 == gameObject)
{
OnExit();
}
}
private void OnObjEnter(ZPointer arg0, GameObject arg1)
{
if (arg1 == gameObject)
{
OnEnter();
}
}
#endif
private void OnMouseEnter()
{