76 lines
1.9 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 VarCondition : ICondition
{
private static SimpleObjectPool<VarCondition> mSimpleObjectPool =
new SimpleObjectPool<VarCondition>(() => new VarCondition(), null, 10);
private VarCondition() { }
public GameObject obj = null;
string key;
float value;
public static VarCondition Allocate(string key, string value)
{
var conditionAction = mSimpleObjectPool.Allocate();
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
conditionAction.Deinited = false;
conditionAction.Reset();
conditionAction.key = key;
float.TryParse(value, out conditionAction.value);
return conditionAction;
}
public bool Check()
{
return VarController.Instance.Get(key) == value;
}
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;
obj = null;
mSimpleObjectPool.Recycle(this);
}
}
public void Reset()
{
Paused = false;
Status = ActionStatus.NotStart;
}
}
public static class VarConditionExtension
{
public static ISequence VarCondition(this ISequence self, string key,string value)
{
return self.Append(QFramework.VarCondition.Allocate(key,value));
}
}
}