79 lines
2.0 KiB
C#
Raw Permalink Normal View History

2024-12-14 18:27:59 +08:00
using System;
using System.IO;
using UnityEngine;
using UnityEngine.EventSystems;
namespace QFramework
{
public class StrEventCondition : ICondition
{
private static SimpleObjectPool<StrEventCondition> mSimpleObjectPool =
new SimpleObjectPool<StrEventCondition>(() => new StrEventCondition(), null, 10);
private StrEventCondition() { }
string key;
2025-03-26 14:56:09 +08:00
bool isFinished = false;
2024-12-14 18:27:59 +08:00
public static StrEventCondition Allocate(string key)
{
var conditionAction = mSimpleObjectPool.Allocate();
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
conditionAction.Deinited = false;
conditionAction.Reset();
conditionAction.key = key;
2025-03-26 14:56:09 +08:00
conditionAction.isFinished = false;
2024-12-14 18:27:59 +08:00
return conditionAction;
}
public bool Check()
{
2025-03-26 14:56:09 +08:00
return isFinished;
2024-12-14 18:27:59 +08:00
}
public bool Paused { get; set; }
public bool Deinited { get; set; }
public ulong ActionID { get; set; }
public ActionStatus Status { get; set; }
public void OnStart()
{
StringEventSystem.Global.Register(key, OnEventFnished);
}
private void OnEventFnished()
{
StringEventSystem.Global.UnRegister(key, OnEventFnished);
2025-03-26 14:56:09 +08:00
isFinished = true;
2024-12-17 18:07:20 +08:00
this.Finish();
2024-12-14 18:27:59 +08:00
}
public void OnExecute(float dt)
{
}
public void OnFinish()
{
}
public void Deinit()
{
if (!Deinited)
{
Deinited = true;
mSimpleObjectPool.Recycle(this);
}
}
public void Reset()
{
Paused = false;
Status = ActionStatus.NotStart;
}
}
public static class StrEventConditionExtension
{
public static ISequence StrEventCondition(this ISequence self, string uipath)
{
return self.Append(QFramework.StrEventCondition.Allocate(uipath));
}
}
}