97 lines
2.9 KiB
C#
97 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace HK
|
|
{
|
|
public interface IProcedureManager
|
|
{
|
|
// void StartProcedure<T>() where T : IProcedure;
|
|
void StartProcedure(string procedureName);
|
|
|
|
// void ChangeProcedure<T>();
|
|
void ChangeProcedure(string procedureName);
|
|
|
|
IProcedure GetProcedure(string procedureName);
|
|
}
|
|
|
|
internal class ProcedureManager : ManagerBase<ProcedureManager>, IProcedureManager, IReference
|
|
{
|
|
private Dictionary<string, IProcedure> _procedures = new Dictionary<string, IProcedure>();
|
|
private IProcedure currentProcedure;
|
|
|
|
|
|
public void AddProcedure(string procedureName, ProcedureBase procedureBase)
|
|
{
|
|
procedureBase.Init();
|
|
Debug.Log($"add procedure : {procedureBase.procedureType}");
|
|
this._procedures.Add(procedureName, procedureBase);
|
|
}
|
|
|
|
// public override void OnUpdate(float time,params object[] data)
|
|
// {
|
|
// base.OnUpdate(time,data);
|
|
// this.currentProcedure?.OnUpdate(time);
|
|
// }
|
|
|
|
public void StartProcedure(string procedureName)
|
|
{
|
|
if (this.currentProcedure != null)
|
|
this.currentProcedure.OnLeave();
|
|
|
|
if (this._procedures.TryGetValue(procedureName, out var procedure))
|
|
{
|
|
this.currentProcedure = procedure;
|
|
this.currentProcedure.OnEnter();
|
|
}
|
|
}
|
|
|
|
public void ChangeProcedure(string procedureName)
|
|
{
|
|
if (this.currentProcedure != null)
|
|
this.currentProcedure.OnLeave();
|
|
|
|
if (this._procedures.TryGetValue(procedureName, out var procedure))
|
|
{
|
|
this.currentProcedure = procedure;
|
|
this.currentProcedure.OnEnter();
|
|
}
|
|
}
|
|
|
|
public IProcedure GetProcedure(string procedureName)
|
|
{
|
|
if (this._procedures.TryGetValue(procedureName, out var procedure))
|
|
{
|
|
return procedure;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void ClearProcedures()
|
|
{
|
|
this._procedures.Clear();
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
// var types = new List<(Type, ProcedureAttribute)>();
|
|
// AssemblyManager.GetTypesInhertType(typeof(ProcedureBase), types);
|
|
// foreach (var (type, procedureAttribute) in types)
|
|
// {
|
|
// var procedureType = procedureAttribute.ProcedureType;
|
|
// _procedures.Add(procedureType, (IProcedure)Activator.CreateInstance(type, false));
|
|
// }
|
|
//
|
|
// foreach (var procedureBase in _procedures.Values)
|
|
// {
|
|
// procedureBase.Init();
|
|
// Debug.Log($"add procedure : {procedureBase.procedureType}");
|
|
// }
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
} |