shenjianxing 3359efe49d VR适配
2025-03-20 17:31:29 +08:00

80 lines
1.8 KiB
C#

using GCSeries.Core.Input;
using QFramework;
using QFramework.Example;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
public class TipItem : MonoBehaviour
{
UIDeviceTip tip;
public string label;
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
private void OnObjExit(ZPointer arg0, GameObject arg1)
{
OnExit();
}
private void OnObjEnter(ZPointer arg0, GameObject arg1)
{
OnEnter();
}
#endif
private void OnMouseEnter()
{
OnEnter();
}
public void OnEnter()
{
tip = UIKit.GetPanel<UIDeviceTip>();
if (tip == null)
{
UIKit.OpenPanelAsync<UIDeviceTip>(UILevel.PopUI).ToAction().Start(this, () =>
{
tip = UIKit.GetPanel<UIDeviceTip>();
tip.Set(label);
tip.Active(true);
});
}
else
{
tip.Set(label);
tip.Active(true);
}
}
public void OnExit()
{
if (tip != null)
{
tip.Active(false);
}
}
private void OnMouseExit()
{
OnExit();
}
private void OnMouseUpAsButton()
{
if (tip != null)
{
tip.Active(false);
}
}
}