2025-03-27 13:14:48 +08:00

97 lines
2.1 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("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.Hide();
}
}
}
#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()
{
OnEnter();
}
public void OnEnter()
{
tip = UIKit.GetPanel<UIDeviceTip>();
if (tip == null)
{
Debug.LogError($"{gameObject}:Tip");
UIKit.OpenPanelAsync<UIDeviceTip>(UILevel.PopUI).ToAction().StartGlobal(() =>
{
tip = UIKit.GetPanel<UIDeviceTip>();
tip.Open(new UIDeviceTipData() { txt = label });
tip.Show();
});
}
else
{
tip.Open(new UIDeviceTipData() { txt = label});
tip.Show();
}
}
public void OnExit()
{
if (tip != null)
{
tip.Hide();
}
}
private void OnMouseExit()
{
OnExit();
}
private void OnMouseUpAsButton()
{
if (tip != null)
{
tip.Hide();
}
}
}