FM/Assets/Scripts/Base/Produce/ProcedureManager.cs

97 lines
2.9 KiB
C#
Raw Normal View History

2025-04-26 21:05:13 +08:00
using System;
using System.Collections.Generic;
using UnityEngine;
namespace HK
{
public interface IProcedureManager
{
// void StartProcedure<T>() where T : IProcedure;
2025-07-02 10:24:01 +08:00
void StartProcedure(string procedureName);
2025-04-26 21:05:13 +08:00
// void ChangeProcedure<T>();
2025-07-02 10:24:01 +08:00
void ChangeProcedure(string procedureName);
2025-04-26 21:05:13 +08:00
2025-07-02 10:24:01 +08:00
IProcedure GetProcedure(string procedureName);
2025-04-26 21:05:13 +08:00
}
internal class ProcedureManager : ManagerBase<ProcedureManager>, IProcedureManager, IReference
{
2025-07-02 10:24:01 +08:00
private Dictionary<string, IProcedure> _procedures = new Dictionary<string, IProcedure>();
2025-04-26 21:05:13 +08:00
private IProcedure currentProcedure;
2025-07-02 10:24:01 +08:00
public void AddProcedure(string procedureName, ProcedureBase procedureBase)
2025-04-26 21:05:13 +08:00
{
2025-07-02 10:24:01 +08:00
procedureBase.Init();
Debug.Log($"add procedure : {procedureBase.procedureType}");
this._procedures.Add(procedureName, procedureBase);
2025-04-26 21:05:13 +08:00
}
// public override void OnUpdate(float time,params object[] data)
// {
// base.OnUpdate(time,data);
// this.currentProcedure?.OnUpdate(time);
// }
2025-07-02 10:24:01 +08:00
public void StartProcedure(string procedureName)
2025-04-26 21:05:13 +08:00
{
if (this.currentProcedure != null)
this.currentProcedure.OnLeave();
2025-07-02 10:24:01 +08:00
if (this._procedures.TryGetValue(procedureName, out var procedure))
2025-04-26 21:05:13 +08:00
{
this.currentProcedure = procedure;
this.currentProcedure.OnEnter();
}
}
2025-07-02 10:24:01 +08:00
public void ChangeProcedure(string procedureName)
2025-04-26 21:05:13 +08:00
{
if (this.currentProcedure != null)
this.currentProcedure.OnLeave();
2025-07-02 10:24:01 +08:00
if (this._procedures.TryGetValue(procedureName, out var procedure))
2025-04-26 21:05:13 +08:00
{
this.currentProcedure = procedure;
this.currentProcedure.OnEnter();
}
}
2025-07-02 10:24:01 +08:00
public IProcedure GetProcedure(string procedureName)
2025-04-26 21:05:13 +08:00
{
2025-07-02 10:24:01 +08:00
if (this._procedures.TryGetValue(procedureName, out var procedure))
2025-04-26 21:05:13 +08:00
{
return procedure;
}
return null;
}
2025-07-02 10:24:01 +08:00
public void ClearProcedures()
2025-04-26 21:05:13 +08:00
{
2025-07-02 10:24:01 +08:00
this._procedures.Clear();
}
2025-04-26 21:05:13 +08:00
2025-07-02 10:24:01 +08:00
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}");
// }
2025-04-26 21:05:13 +08:00
}
public void Dispose()
{
}
}
}