99 lines
2.4 KiB
C#
99 lines
2.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace QFramework
|
|
{
|
|
public interface IAnyAction : ISequence
|
|
{
|
|
|
|
}
|
|
internal class AnyAction : IAnyAction
|
|
{
|
|
private AnyAction(){}
|
|
|
|
private static SimpleObjectPool<AnyAction> mSimpleObjectPool =
|
|
new SimpleObjectPool<AnyAction>(() => new AnyAction(), null, 5);
|
|
|
|
private List<IAction> mActions = ListPool<IAction>.Get();
|
|
|
|
private int mFinishedCount = 0;
|
|
|
|
public static AnyAction Allocate()
|
|
{
|
|
var AnyAction = mSimpleObjectPool.Allocate();
|
|
AnyAction.ActionID = ActionKit.ID_GENERATOR++;
|
|
AnyAction.Deinited = false;
|
|
AnyAction.Reset();
|
|
return AnyAction;
|
|
}
|
|
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)
|
|
{
|
|
for (var i = mFinishedCount; i < mActions.Count; i++)
|
|
{
|
|
if (!mActions[i].Execute(dt)) continue;
|
|
this.Finish();
|
|
}
|
|
}
|
|
|
|
public void OnFinish()
|
|
{
|
|
}
|
|
|
|
public ISequence Append(IAction action)
|
|
{
|
|
mActions.Add(action);
|
|
return this;
|
|
}
|
|
|
|
public void Deinit()
|
|
{
|
|
|
|
if (!Deinited)
|
|
{
|
|
Deinited = true;
|
|
|
|
foreach (var action in mActions)
|
|
{
|
|
action.Deinit();
|
|
}
|
|
|
|
|
|
mActions.Clear();
|
|
|
|
mSimpleObjectPool.Recycle(this);
|
|
}
|
|
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Status = ActionStatus.NotStart;
|
|
mFinishedCount = 0;
|
|
Paused = false;
|
|
foreach (var action in mActions)
|
|
{
|
|
action.Reset();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public static class AnyActionExtension
|
|
{
|
|
public static ISequence AnyAction(this ISequence self, Action<ISequence> AnyActionSetting)
|
|
{
|
|
var AnyAction = QFramework.AnyAction.Allocate();
|
|
AnyActionSetting(AnyAction);
|
|
return self.Append(AnyAction);
|
|
}
|
|
}
|
|
} |