73 lines
1.8 KiB
C#
73 lines
1.8 KiB
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace QFramework
|
|
{
|
|
public class InputCondition : ICondition
|
|
{
|
|
|
|
private static SimpleObjectPool<InputCondition> mSimpleObjectPool =
|
|
new SimpleObjectPool<InputCondition>(() => new InputCondition(), null, 10);
|
|
|
|
private InputCondition() { }
|
|
string key;
|
|
public static InputCondition Allocate(string key)
|
|
{
|
|
var conditionAction = mSimpleObjectPool.Allocate();
|
|
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
|
|
conditionAction.Deinited = false;
|
|
conditionAction.Reset();
|
|
conditionAction.key = key;
|
|
return conditionAction;
|
|
}
|
|
public bool Check()
|
|
{
|
|
KeyCode code = Enum.Parse<KeyCode>(key);
|
|
return Input.GetKeyUp(code);
|
|
}
|
|
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;
|
|
mSimpleObjectPool.Recycle(this);
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Paused = false;
|
|
Status = ActionStatus.NotStart;
|
|
}
|
|
}
|
|
|
|
public static class InputConditionExtension
|
|
{
|
|
public static ISequence InputCondition(this ISequence self, string uipath)
|
|
{
|
|
return self.Append(QFramework.InputCondition.Allocate(uipath));
|
|
}
|
|
}
|
|
} |