using Axibug;
using Axibug.Fsm;
using Axibug.Procedure;
using System;
using System.Collections;
using UnityEngine;
namespace Axibug.Runtime
{
///
/// 流程组件。
///
[DisallowMultipleComponent]
[AddComponentMenu("Axibug/Procedure")]
public sealed class ProcedureComponent : GameComponent
{
private IProcedureManager m_ProcedureManager = null;
private ProcedureBase m_EntranceProcedure = null;
[SerializeField]
private string[] m_AvailableProcedureTypeNames = null;
[SerializeField]
private string m_EntranceProcedureTypeName = null;
///
/// 获取当前流程。
///
public ProcedureBase CurrentProcedure
{
get
{
return m_ProcedureManager.CurrentProcedure;
}
}
///
/// 获取当前流程持续时间。
///
public float CurrentProcedureTime
{
get
{
return m_ProcedureManager.CurrentProcedureTime;
}
}
///
/// 游戏框架组件初始化。
///
protected override void Awake()
{
base.Awake();
m_ProcedureManager = FrameworkEntry.GetModule();
if (m_ProcedureManager == null)
{
Log.Fatal("Procedure manager is invalid.");
return;
}
}
private IEnumerator Start()
{
ProcedureBase[] procedures = new ProcedureBase[m_AvailableProcedureTypeNames.Length];
for (int i = 0; i < m_AvailableProcedureTypeNames.Length; i++)
{
Type procedureType = Utility.Assembly.GetType(m_AvailableProcedureTypeNames[i]);
if (procedureType == null)
{
Log.Error("Can not find procedure type '{0}'.", m_AvailableProcedureTypeNames[i]);
yield break;
}
procedures[i] = (ProcedureBase)Activator.CreateInstance(procedureType);
if (procedures[i] == null)
{
Log.Error("Can not create procedure instance '{0}'.", m_AvailableProcedureTypeNames[i]);
yield break;
}
if (m_EntranceProcedureTypeName == m_AvailableProcedureTypeNames[i])
{
m_EntranceProcedure = procedures[i];
}
}
if (m_EntranceProcedure == null)
{
Log.Error("Entrance procedure is invalid.");
yield break;
}
m_ProcedureManager.Initialize(FrameworkEntry.GetModule(), procedures);
yield return new WaitForEndOfFrame();
m_ProcedureManager.StartProcedure(m_EntranceProcedure.GetType());
}
///
/// 是否存在流程。
///
/// 要检查的流程类型。
/// 是否存在流程。
public bool HasProcedure() where T : ProcedureBase
{
return m_ProcedureManager.HasProcedure();
}
///
/// 是否存在流程。
///
/// 要检查的流程类型。
/// 是否存在流程。
public bool HasProcedure(Type procedureType)
{
return m_ProcedureManager.HasProcedure(procedureType);
}
///
/// 获取流程。
///
/// 要获取的流程类型。
/// 要获取的流程。
public ProcedureBase GetProcedure() where T : ProcedureBase
{
return m_ProcedureManager.GetProcedure();
}
///
/// 获取流程。
///
/// 要获取的流程类型。
/// 要获取的流程。
public ProcedureBase GetProcedure(Type procedureType)
{
return m_ProcedureManager.GetProcedure(procedureType);
}
}
}