2024-11-06 13:33:47 +08:00
|
|
|
using Gameplay.Data;
|
|
|
|
|
using PhxhSDK;
|
2024-02-21 16:24:29 +08:00
|
|
|
using PhxhSDK.AOT;
|
2023-08-22 19:08:45 +08:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
2024-11-06 13:33:47 +08:00
|
|
|
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
|
|
|
{
|
2024-11-06 13:33:47 +08:00
|
|
|
private Game _game;
|
2024-02-21 16:24:29 +08:00
|
|
|
|
2024-11-06 13:33:47 +08:00
|
|
|
public bool isInited
|
2023-08-22 19:08:45 +08:00
|
|
|
{
|
2024-11-06 13:33:47 +08:00
|
|
|
get;
|
|
|
|
|
private set;
|
2024-02-21 16:24:29 +08:00
|
|
|
}
|
|
|
|
|
|
2024-11-06 13:33:47 +08:00
|
|
|
public EGameStartType startType = EGameStartType.Normal;
|
|
|
|
|
public string startParam = "";
|
|
|
|
|
|
2024-02-21 16:24:29 +08:00
|
|
|
private void _InitGame()
|
|
|
|
|
{
|
|
|
|
|
SDKManager.GetSingleton().InitEarly();
|
2023-08-22 19:08:45 +08:00
|
|
|
_game = new MyGame();
|
|
|
|
|
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
|
|
|
}
|
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()
|
|
|
|
|
{
|
2024-11-06 13:33:47 +08:00
|
|
|
isInited = false;
|
2024-02-21 16:24:29 +08:00
|
|
|
#if USE_YOO
|
|
|
|
|
await YooAssetHelper.Init();
|
|
|
|
|
#endif
|
2024-11-06 13:33:47 +08:00
|
|
|
isInited = true;
|
2024-02-21 16:24:29 +08:00
|
|
|
_InitGame();
|
|
|
|
|
}
|
2023-12-15 19:25:08 +08:00
|
|
|
|
2024-11-19 12:49:28 +08:00
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
#if SDK_BILIBILI
|
2024-11-19 14:01:05 +08:00
|
|
|
if(!gameObject.TryGetComponent<GSCSdkInterface>(out _))
|
|
|
|
|
gameObject.AddComponent<GSCSdkInterface>();
|
|
|
|
|
|
2024-11-19 12:49:28 +08:00
|
|
|
if(!gameObject.TryGetComponent<GSCCallbackListerner>(out _))
|
|
|
|
|
gameObject.AddComponent<GSCCallbackListerner>();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-22 19:08:45 +08:00
|
|
|
private void Start()
|
|
|
|
|
{
|
2024-02-21 16:24:29 +08:00
|
|
|
_InitAsync();
|
2023-08-22 19:08:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
2024-11-06 13:33:47 +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)
|
|
|
|
|
{
|
2024-11-06 13:33:47 +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
|
|
|
}
|