// ***********************************************************************
// Assembly : Unity
// Author : Kimch
// Created :
//
// Last Modified By : Kimch
// Last Modified On :
// ***********************************************************************
//
//
// ***********************************************************************
namespace G
{
using System;
using System.Collections.Generic;
using F;
using F.Fsm;
using UnityEngine;
///
/// 游戏初始状态
///
public class GameStateInitial : GameFsmState
{
///
///
///
///
private static List GetRegisterTypes()
{
//
Type[] allTypes = null;
var execAssembly = System.Reflection.Assembly.GetExecutingAssembly();
if (execAssembly != null)
{
allTypes = execAssembly.GetTypes();
}
if (allTypes == null)
return null;
var proxyType = typeof(F.GameProxy);
var retTypes = new List();
foreach (var type in allTypes)
{
if (type.IsSubclassOf(proxyType))
{
retTypes.Add(type);
}
}
return retTypes;
}
private static void GetRegisterTypes(List proxyTypes, List commandTypes)
{
Type[] allTypes = null;
var execAssembly = System.Reflection.Assembly.GetExecutingAssembly();
if (execAssembly != null)
{
allTypes = execAssembly.GetTypes();
}
if (allTypes == null)
return;
var proxyType = typeof(F.GameProxy);
var commandType = typeof(F.GameCommand);
foreach (var type in allTypes)
{
if (type.IsSubclassOf(proxyType))
{
proxyTypes.Add(type);
continue;
}
if (type.IsSubclassOf(commandType))
{
commandTypes.Add(type);
continue;
}
}
}
///
///
///
///
///
public static List AutoRegisterProxy(List types)
{
var proxyRoot = new GameObject("GameProxies");
UnityEngine.Object.DontDestroyOnLoad(proxyRoot);
var gameProxies = new List();
var moduleTypes = types;
if (moduleTypes != null && moduleTypes.Count > 0)
{
foreach (var moduleType in moduleTypes)
{
var module = proxyRoot.AddComponent(moduleType) /*new GameObject(moduleType.Name, moduleType).GetComponent(moduleType)*/ as GameProxy;// (GameProxy)Activator.CreateInstance(mt);
//module.transform.SetParent(proxyRoot.transform, false);
gameProxies.Add(module);
}
}
return gameProxies;
}
protected override void OnEnter(IFsm fsm)
{
//KPlatform.Instance.Init();
if (KFramework.GameFacade.Init(AutoRegisterProxy(GetRegisterTypes())))
{
//注册全局事件
KFramework.GameFacade.RegisterCommand(GlobalDefine.EVENT_BUTTON_CLICK, ButtonClickCommand.CreateCommand);
KFramework.GameFacade.RegisterCommand(GlobalDefine.EVENT_SHOW_TOAST, ShowToastCommand.CreateCommand);
KFramework.GameFacade.RegisterCommand(GlobalDefine.EVENT_DAILY_LOGIN, DailyLoginCommand.CreateCommand);
KFramework.GameFacade.RegisterCommand(GlobalDefine.EVENT_WEEKLY_LOGIN, DailyLoginCommand.CreateCommand);
//执行初始化
KStatistics.Instance.ReportEvent_GameInit(2, "fsm_init", 0, 0);
}
}
protected override void OnExit(IFsm fsm)
{
}
protected override void Update(IFsm fsm, float delta)
{
if (AssetProxy.Instance.initialized)
{
fsm.ChangeState();
}
}
}
}