com.alicizax.unity/Runtime/Base/Module/GameEntry.cs
陈思海 bf0d8340af init
2025-02-07 16:04:12 +08:00

95 lines
3.1 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace AlicizaX.Runtime
{
public static class GameEntry
{
private static readonly GameFrameworkLinkedList<GameFrameworkComponent> GameFrameworkComponents = new GameFrameworkLinkedList<GameFrameworkComponent>();
/// <summary>
/// 获取游戏框架组件。
/// </summary>
/// <typeparam name="T">要获取的游戏框架组件类型。</typeparam>
/// <returns>要获取的游戏框架组件。</returns>
public static T GetComponent<T>() where T : GameFrameworkComponent
{
return (T)GetComponent(typeof(T));
}
/// <summary>
/// 获取游戏框架组件。
/// </summary>
/// <param name="type">要获取的游戏框架组件类型。</param>
/// <returns>要获取的游戏框架组件。</returns>
public static GameFrameworkComponent GetComponent(Type type)
{
LinkedListNode<GameFrameworkComponent> current = GameFrameworkComponents.First;
while (current != null)
{
if (current.Value.GetType() == type)
{
return current.Value;
}
current = current.Next;
}
return null;
}
/// <summary>
/// 获取游戏框架组件。
/// </summary>
/// <param name="typeName">要获取的游戏框架组件类型名称。</param>
/// <returns>要获取的游戏框架组件。</returns>
public static GameFrameworkComponent GetComponent(string typeName)
{
LinkedListNode<GameFrameworkComponent> current = GameFrameworkComponents.First;
while (current != null)
{
Type type = current.Value.GetType();
if (type.FullName == typeName || type.Name == typeName)
{
return current.Value;
}
current = current.Next;
}
return null;
}
/// <summary>
/// 注册游戏框架组件。
/// </summary>
/// <param name="gameFrameworkComponent">要注册的游戏框架组件。</param>
public static void RegisterComponent(GameFrameworkComponent gameFrameworkComponent)
{
if (gameFrameworkComponent == null)
{
Log.Error("Game Framework component is invalid.");
return;
}
Type type = gameFrameworkComponent.GetType();
LinkedListNode<GameFrameworkComponent> current = GameFrameworkComponents.First;
while (current != null)
{
if (current.Value.GetType() == type)
{
Log.Error("Game Framework component type '{0}' is already exist.", type.FullName);
return;
}
current = current.Next;
}
GameFrameworkComponents.AddLast(gameFrameworkComponent);
}
}
}