Update GameModule

Update GameModule
This commit is contained in:
ALEXTANG
2023-04-03 20:42:54 +08:00
parent 3d13d5c8e5
commit aa6455f23e
3 changed files with 94 additions and 18 deletions

View File

@@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameMain : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using TEngine;
using UnityEngine;
/// <summary>
/// 游戏模块
/// </summary>
public class GameModule:MonoBehaviour
{
#region BaseComponents
/// <summary>
/// 获取游戏基础组件。
/// </summary>
public static RootComponent Base { get; private set; }
/// <summary>
/// 获取调试组件。
/// </summary>
public static DebuggerComponent Debugger { get; private set; }
/// <summary>
/// 获取有限状态机组件。
/// </summary>
public static FsmComponent Fsm { get; private set; }
/// <summary>
/// 获取对象池组件。
/// </summary>
public static ObjectPoolComponent ObjectPool { get; private set; }
/// <summary>
/// 获取资源组件。
/// </summary>
public static ResourceComponent Resource { get; private set; }
/// <summary>
/// 获取配置组件。
/// </summary>
public static SettingComponent Setting { get; private set; }
/// <summary>
/// 获取界面组件。
/// </summary>
public static UIComponent UI { get; private set; }
#endregion
/// <summary>
/// 初始化系统框架模块
/// </summary>
public static void InitFrameWorkComponents()
{
Base = Get<RootComponent>();
Debugger = Get<DebuggerComponent>();
Fsm = Get<FsmComponent>();
ObjectPool = Get<ObjectPoolComponent>();
Resource = Get<ResourceComponent>();
Setting = Get<SettingComponent>();
UI = Get<UIComponent>();
}
public static void InitCustomComponents()
{
}
private static readonly Dictionary<Type, GameFrameworkComponent> s_Components = new Dictionary<Type, GameFrameworkComponent>();
public static T Get<T>()where T : GameFrameworkComponent
{
Type type = typeof(T);
if (s_Components.ContainsKey(type))
{
return s_Components[type] as T;
}
T component = TEngine.GameEntry.GetComponent<T>();
Log.Assert(condition:component != null,$"{typeof(T)} is null");
s_Components.Add(type,component);
return component;
}
public void Start()
{
Log.Info("GameModule Active");
InitFrameWorkComponents();
InitCustomComponents();
}
}