2025-05-18 01:04:31 +08:00
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// Assembly : Unity
|
|
|
|
|
// Author : Kimch
|
|
|
|
|
// Created :
|
|
|
|
|
//
|
|
|
|
|
// Last Modified By : Kimch
|
|
|
|
|
// Last Modified On :
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
// <copyright file= "GameStateInitial" company=""></copyright>
|
|
|
|
|
// <summary></summary>
|
|
|
|
|
// ***********************************************************************
|
|
|
|
|
namespace G
|
|
|
|
|
{
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using F;
|
|
|
|
|
using F.Fsm;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 游戏初始状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class GameStateInitial : GameFsmState
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
private static List<Type> 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<Type>();
|
|
|
|
|
foreach (var type in allTypes)
|
|
|
|
|
{
|
|
|
|
|
if (type.IsSubclassOf(proxyType))
|
|
|
|
|
{
|
|
|
|
|
retTypes.Add(type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return retTypes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void GetRegisterTypes(List<Type> proxyTypes, List<Type> 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="types"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static List<GameProxy> AutoRegisterProxy(List<Type> types)
|
|
|
|
|
{
|
|
|
|
|
var proxyRoot = new GameObject("GameProxies");
|
|
|
|
|
UnityEngine.Object.DontDestroyOnLoad(proxyRoot);
|
|
|
|
|
|
|
|
|
|
var gameProxies = new List<GameProxy>();
|
|
|
|
|
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<GameFsm> 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);
|
|
|
|
|
|
2025-06-23 00:44:29 +08:00
|
|
|
|
// 这俩全局注册暂时没用
|
2025-05-18 01:04:31 +08:00
|
|
|
|
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<GameFsm> fsm)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update(IFsm<GameFsm> fsm, float delta)
|
|
|
|
|
{
|
|
|
|
|
if (AssetProxy.Instance.initialized)
|
|
|
|
|
{
|
|
|
|
|
fsm.ChangeState<GameStateLogin>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|