94 lines
2.5 KiB
C#
94 lines
2.5 KiB
C#
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)
|
|
{
|
|
#if VR
|
|
if (uiPath.Contains("UIRoot/"))
|
|
{
|
|
uiPath = uiPath.Replace("UIRoot/", "UIRoot/ZCameraRig/ZCanvas/");
|
|
}
|
|
#endif
|
|
obj = Utility.FindObj(uiPath);
|
|
}
|
|
#if VR
|
|
if (obj != null && Input.GetMouseButtonUp(0))
|
|
#else
|
|
if (obj != null && Input.GetMouseButtonUp(0) && EventSystem.current.IsPointerOverGameObject())
|
|
#endif
|
|
{
|
|
return obj == EventSystem.current.currentSelectedGameObject;
|
|
}
|
|
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()
|
|
{
|
|
}
|
|
|
|
public void OnExecute(float dt)
|
|
{
|
|
if (Check())
|
|
{
|
|
this.Finish();
|
|
}
|
|
}
|
|
|
|
public void OnFinish()
|
|
{
|
|
}
|
|
|
|
public void Deinit()
|
|
{
|
|
if (!Deinited)
|
|
{
|
|
Deinited = true;
|
|
mCondition = null;
|
|
obj = null;
|
|
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));
|
|
}
|
|
}
|
|
} |