NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/GameWrapper/Main.cs

91 lines
2.0 KiB
C#
Raw Normal View History

using PhxhSDK;
2024-02-21 16:24:29 +08:00
using PhxhSDK.AOT;
2025-05-19 17:28:24 +08:00
using PhxhSDK.AOT.Aspect;
2025-04-28 17:38:49 +08:00
using System;
using System.Reflection;
2023-08-22 19:08:45 +08:00
using UnityEngine;
namespace Gameplay
2023-08-22 19:08:45 +08:00
{
2023-10-19 15:00:19 +08:00
public class Main : SingletonMono<Main>
2023-08-22 19:08:45 +08:00
{
2025-04-28 17:38:49 +08:00
private const string GAME_TYPE_NAME = "MyGame, GamePlay";
private Game _game;
2024-02-21 16:24:29 +08:00
public bool isInited
2023-08-22 19:08:45 +08:00
{
get;
private set;
2024-02-21 16:24:29 +08:00
}
private void _InitGame()
{
SDKManager.GetSingleton().InitEarly();
2025-04-28 17:38:49 +08:00
Type type = Type.GetType(GAME_TYPE_NAME);
if (null == type)
{
Debug.LogError($"{GAME_TYPE_NAME} Type found");
return;
}
_game = Activator.CreateInstance(type) as Game;
2023-08-22 19:08:45 +08:00
if (_game == null)
{
2023-10-21 11:55:23 +08:00
DebugUtil.LogError("PhxhSDK.Main: no game instance created");
2023-08-22 19:08:45 +08:00
}
2025-04-28 17:38:49 +08:00
2023-10-19 15:00:19 +08:00
SDKManager.GetSingleton().Init();
2023-08-22 19:08:45 +08:00
_game.Init();
2024-02-21 16:24:29 +08:00
_game.Start();
2023-08-22 19:08:45 +08:00
}
2024-02-21 16:24:29 +08:00
private async void _InitAsync()
{
isInited = false;
2024-02-21 16:24:29 +08:00
#if USE_YOO
await YooAssetHelper.Init();
#endif
isInited = true;
2024-02-21 16:24:29 +08:00
_InitGame();
}
2023-12-15 19:25:08 +08:00
2023-08-22 19:08:45 +08:00
private void Start()
{
2025-05-19 17:28:24 +08:00
if (null == AspectManager.Instance)
gameObject.AddComponent<AspectManager>();
2025-05-07 12:15:40 +08:00
#if DEBUG || DEVELOPMENT_BUILD
Debug.unityLogger.logEnabled = true;
#else
Debug.unityLogger.logEnabled = false;
#endif
2024-02-21 16:24:29 +08:00
_InitAsync();
2023-08-22 19:08:45 +08:00
}
private void Update()
{
2025-04-28 17:38:49 +08:00
if (!isInited)
return;
2023-08-22 19:08:45 +08:00
_game.Update(Time.deltaTime);
2024-11-13 16:57:46 +08:00
SDKManager.Instance.Update();
2023-08-22 19:08:45 +08:00
}
private void OnApplicationPause(bool pauseStatus)
{
2025-04-28 17:38:49 +08:00
if (!isInited)
return;
2023-08-22 19:08:45 +08:00
_game.OnApplicationPause(pauseStatus);
}
private void OnDestroy()
{
_game.Release();
2023-10-19 15:00:19 +08:00
SDKManager.Instance.Release();
2023-08-22 19:08:45 +08:00
}
}
2023-10-19 15:00:19 +08:00
}