2025-03-20 17:31:29 +08:00
|
|
|
using GCSeries.Core.Input;
|
2024-12-14 18:27:59 +08:00
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
|
|
|
|
namespace QFramework
|
|
|
|
|
{
|
|
|
|
|
public class UIClickCondition : ICondition
|
|
|
|
|
{
|
|
|
|
|
private Func<bool> mCondition;
|
|
|
|
|
|
|
|
|
|
private static SimpleObjectPool<UIClickCondition> mSimpleObjectPool =
|
|
|
|
|
new SimpleObjectPool<UIClickCondition>(() => new UIClickCondition(), null, 10);
|
|
|
|
|
|
|
|
|
|
private UIClickCondition() { }
|
|
|
|
|
public GameObject obj = null;
|
|
|
|
|
string uiPath = string.Empty;
|
|
|
|
|
public static UIClickCondition Allocate(string uiPath)
|
|
|
|
|
{
|
|
|
|
|
var conditionAction = mSimpleObjectPool.Allocate();
|
|
|
|
|
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
|
|
|
|
|
conditionAction.Deinited = false;
|
|
|
|
|
conditionAction.Reset();
|
|
|
|
|
conditionAction.mCondition = conditionAction.Check;
|
|
|
|
|
conditionAction.uiPath = uiPath;
|
|
|
|
|
return conditionAction;
|
|
|
|
|
}
|
|
|
|
|
public bool Check()
|
|
|
|
|
{
|
|
|
|
|
if (obj == null)
|
|
|
|
|
{
|
2025-03-20 13:21:32 +08:00
|
|
|
#if VR
|
|
|
|
|
if (uiPath.Contains("UIRoot/"))
|
|
|
|
|
{
|
|
|
|
|
uiPath = uiPath.Replace("UIRoot/", "UIRoot/ZCameraRig/ZCanvas/");
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-12-14 18:27:59 +08:00
|
|
|
obj = Utility.FindObj(uiPath);
|
|
|
|
|
}
|
2025-03-20 17:31:29 +08:00
|
|
|
#if !VR
|
2024-12-14 18:27:59 +08:00
|
|
|
if (obj != null && Input.GetMouseButtonUp(0) && EventSystem.current.IsPointerOverGameObject())
|
|
|
|
|
{
|
|
|
|
|
return obj == EventSystem.current.currentSelectedGameObject;
|
|
|
|
|
}
|
2025-03-20 17:31:29 +08:00
|
|
|
#endif
|
2024-12-14 18:27:59 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
public bool Paused { get; set; }
|
|
|
|
|
public bool Deinited { get; set; }
|
|
|
|
|
public ulong ActionID { get; set; }
|
|
|
|
|
public ActionStatus Status { get; set; }
|
|
|
|
|
public void OnStart()
|
|
|
|
|
{
|
2025-03-20 17:31:29 +08:00
|
|
|
#if VR
|
|
|
|
|
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
|
|
|
|
|
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnClick.AddListener(OnClick);
|
|
|
|
|
#endif
|
2024-12-14 18:27:59 +08:00
|
|
|
}
|
|
|
|
|
|
2025-03-20 17:31:29 +08:00
|
|
|
#if VR
|
|
|
|
|
private void OnClick(ZPointer arg0, int arg1, GameObject arg2)
|
|
|
|
|
{
|
|
|
|
|
if (this.obj != null && this.obj == arg2)
|
|
|
|
|
{
|
|
|
|
|
this.Finish();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2024-12-14 18:27:59 +08:00
|
|
|
public void OnExecute(float dt)
|
|
|
|
|
{
|
|
|
|
|
if (Check())
|
|
|
|
|
{
|
|
|
|
|
this.Finish();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnFinish()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Deinit()
|
|
|
|
|
{
|
|
|
|
|
if (!Deinited)
|
|
|
|
|
{
|
2025-03-20 17:31:29 +08:00
|
|
|
UIRoot.Instance.transform.Find("ZMouse").GetComponent<ZPointer>().OnClick.RemoveListener(OnClick);
|
|
|
|
|
UIRoot.Instance.transform.Find("ZStylus").GetComponent<ZPointer>().OnClick.RemoveListener(OnClick);
|
2024-12-14 18:27:59 +08:00
|
|
|
Deinited = true;
|
|
|
|
|
mCondition = null;
|
2024-12-18 10:58:52 +08:00
|
|
|
obj = null;
|
2024-12-14 18:27:59 +08:00
|
|
|
mSimpleObjectPool.Recycle(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
{
|
|
|
|
|
Paused = false;
|
|
|
|
|
Status = ActionStatus.NotStart;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class UIClickConditionExtension
|
|
|
|
|
{
|
|
|
|
|
public static ISequence UIClickCondition(this ISequence self, string uipath)
|
|
|
|
|
{
|
|
|
|
|
return self.Append(QFramework.UIClickCondition.Allocate(uipath));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|