111 lines
3.2 KiB
C#
111 lines
3.2 KiB
C#
|
using Thousandto.Core.Base;
|
|||
|
using Thousandto.Core.Support;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using FLogger = UnityEngine.Gonbest.MagicCube.FLogger;
|
|||
|
|
|||
|
namespace Thousandto.Code.Logic
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 游戏状态系统
|
|||
|
/// </summary>
|
|||
|
public class GameStateSystem: BaseStateSystem
|
|||
|
{
|
|||
|
#region//私有变量
|
|||
|
//所有状态集合
|
|||
|
private IGameState[] _statesCache = null;
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//继承
|
|||
|
/// <summary>
|
|||
|
/// 初始化
|
|||
|
/// </summary>
|
|||
|
protected override void OnInitialize()
|
|||
|
{
|
|||
|
//FLogger.DebugLog("InitGameSate");
|
|||
|
try
|
|||
|
{
|
|||
|
_statesCache = new IGameState[(int)GameStateId.Count];
|
|||
|
_statesCache[(int)GameStateId.PreLoad] = new PreLoadState(GameStateId.PreLoad);
|
|||
|
_statesCache[(int)GameStateId.Login] = new LoginState(GameStateId.Login);
|
|||
|
_statesCache[(int)GameStateId.SceneLoading] = new SceneLoadingState(GameStateId.SceneLoading);
|
|||
|
_statesCache[(int)GameStateId.World] = new WorldState(GameStateId.World);
|
|||
|
_statesCache[(int)GameStateId.RetToLogin] = new RetToLoginState(GameStateId.RetToLogin);
|
|||
|
_statesCache[(int)GameStateId.RetToUpdate] = new RetToUpdateState(GameStateId.RetToUpdate);
|
|||
|
for (int i = 0; i < (int)GameStateId.Count; ++i)
|
|||
|
{
|
|||
|
if (_statesCache[i] != null)
|
|||
|
{
|
|||
|
_statesCache[i].Load();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//最新进行资源预加载
|
|||
|
ChangeState((int)GameStateId.PreLoad);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
FLogger.DebugLogException(e);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 反初始化
|
|||
|
/// </summary>
|
|||
|
protected override void OnUnInitialize()
|
|||
|
{
|
|||
|
if (Fsm != null)
|
|||
|
{
|
|||
|
Fsm.Clear();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 通过id获取游戏状态
|
|||
|
/// </summary>
|
|||
|
/// <param name="id"></param>
|
|||
|
/// <returns></returns>
|
|||
|
protected override IGameState OnGetStateById(int id)
|
|||
|
{
|
|||
|
if (id < _statesCache.Length)
|
|||
|
return _statesCache[id];
|
|||
|
return null;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 切换状态
|
|||
|
/// </summary>
|
|||
|
/// <param name="stateId"></param>
|
|||
|
/// <param name="arg"></param>
|
|||
|
protected override void OnChangeState(int stateId, object arg)
|
|||
|
{
|
|||
|
if (Fsm != null)
|
|||
|
Fsm.ChangeState(stateId, arg);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 处理状态消息
|
|||
|
/// </summary>
|
|||
|
/// <param name="msg"></param>
|
|||
|
protected override void OnHandlerMessage(object msg)
|
|||
|
{
|
|||
|
if (Fsm != null)
|
|||
|
Fsm.HandlerMessage(msg);
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 更新fsm
|
|||
|
/// </summary>
|
|||
|
/// <param name="dt"></param>
|
|||
|
protected override void OnUpdate(float dt)
|
|||
|
{
|
|||
|
if (Fsm != null)
|
|||
|
Fsm.Update(dt);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|