86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
namespace QFramework
|
|
{
|
|
internal class ScriptAction : IAction
|
|
{
|
|
|
|
|
|
public System.Action OnFinished { get; set; }
|
|
|
|
|
|
private ScriptAction()
|
|
{
|
|
}
|
|
|
|
private static readonly SimpleObjectPool<ScriptAction> mPool =
|
|
new SimpleObjectPool<ScriptAction>(() => new ScriptAction(), null, 10);
|
|
|
|
public string prefabPath;
|
|
string finishedEvent;
|
|
string name;
|
|
public static ScriptAction Allocate(string name, string prefabPath, string finishedEvent, System.Action OnFinished = null)
|
|
{
|
|
var retNode = mPool.Allocate();
|
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
|
retNode.Deinited = false;
|
|
retNode.Reset();
|
|
retNode.OnFinished = OnFinished;
|
|
retNode.finishedEvent = finishedEvent;
|
|
retNode.prefabPath = prefabPath;
|
|
retNode.name = name;
|
|
return retNode;
|
|
}
|
|
|
|
|
|
public ulong ActionID { get; set; }
|
|
public ActionStatus Status { get; set; }
|
|
|
|
public void OnStart()
|
|
{
|
|
StringEventSystem.Global.Register(finishedEvent, OnCustomFinished);
|
|
GameObject obj = GameObject.Instantiate(Resources.Load($"CustomAction/{prefabPath}").As<GameObject>());
|
|
obj.name = name;
|
|
}
|
|
|
|
private void OnCustomFinished()
|
|
{
|
|
StringEventSystem.Global.UnRegister(finishedEvent, OnCustomFinished);
|
|
this.Finish();
|
|
}
|
|
|
|
public void OnExecute(float dt)
|
|
{
|
|
|
|
}
|
|
|
|
public void OnFinish()
|
|
{
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Status = ActionStatus.NotStart;
|
|
Paused = false;
|
|
}
|
|
|
|
public bool Paused { get; set; }
|
|
|
|
public void Deinit()
|
|
{
|
|
if (!Deinited)
|
|
{
|
|
OnFinished = null;
|
|
Deinited = true;
|
|
mPool.Recycle(this);
|
|
}
|
|
}
|
|
|
|
public bool Deinited { get; set; }
|
|
}
|
|
|
|
|
|
} |