96 lines
2.0 KiB
C#
Raw Normal View History

2025-03-20 17:31:29 +08:00
using GCSeries.Core.Input;
2024-12-14 18:27:59 +08:00
using QFramework;
using QFramework.Example;
2025-03-20 17:31:29 +08:00
using System;
2024-12-14 18:27:59 +08:00
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;
2025-03-24 10:32:48 +08:00
#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)
{
2025-03-27 13:14:48 +08:00
tip.Hide();
2025-03-24 10:32:48 +08:00
}
}
2025-03-20 17:31:29 +08:00
}
#if VR
private void OnObjExit(ZPointer arg0, GameObject arg1)
{
2025-03-24 10:32:48 +08:00
if (arg1 == gameObject)
{
OnExit();
}
2024-12-14 18:27:59 +08:00
}
2025-03-20 17:31:29 +08:00
private void OnObjEnter(ZPointer arg0, GameObject arg1)
{
2025-03-24 10:32:48 +08:00
if (arg1 == gameObject)
{
OnEnter();
}
2025-03-20 17:31:29 +08:00
}
#endif
2024-12-14 18:27:59 +08:00
private void OnMouseEnter()
2025-02-10 10:54:47 +08:00
{
OnEnter();
}
public void OnEnter()
2024-12-14 18:27:59 +08:00
{
tip = UIKit.GetPanel<UIDeviceTip>();
if (tip == null)
{
2025-03-27 13:14:48 +08:00
UIKit.OpenPanelAsync<UIDeviceTip>(UILevel.PopUI).ToAction().StartGlobal(() =>
{
tip = UIKit.GetPanel<UIDeviceTip>();
tip.Open(new UIDeviceTipData() { txt = label });
tip.Show();
});
2024-12-14 18:27:59 +08:00
}
else
{
2025-03-27 13:14:48 +08:00
tip.Open(new UIDeviceTipData() { txt = label});
tip.Show();
2024-12-14 18:27:59 +08:00
}
}
2025-02-10 10:54:47 +08:00
public void OnExit()
2024-12-14 18:27:59 +08:00
{
if (tip != null)
{
2025-03-27 13:14:48 +08:00
tip.Hide();
2024-12-14 18:27:59 +08:00
}
}
2024-12-24 13:52:04 +08:00
2025-02-10 10:54:47 +08:00
private void OnMouseExit()
{
OnExit();
}
2024-12-24 13:52:04 +08:00
private void OnMouseUpAsButton()
{
if (tip != null)
{
2025-03-27 13:14:48 +08:00
tip.Hide();
2024-12-24 13:52:04 +08:00
}
}
2024-12-14 18:27:59 +08:00
}