NLDClient-yudde/ProjectNLD/Assets/Code/Scripts/Gameplay/Game/Main.cs

71 lines
1.6 KiB
C#
Raw Normal View History

2023-12-15 19:25:08 +08:00
using System;
using System.Collections.Generic;
2024-02-21 16:24:29 +08:00
using Cysharp.Threading.Tasks;
using PhxhSDK.AOT;
2023-08-22 19:08:45 +08:00
using UnityEngine;
2024-09-09 15:20:28 +08:00
using UnityEngine.Timeline;
2023-08-22 19:08:45 +08:00
2023-10-21 11:55:23 +08:00
namespace PhxhSDK
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
{
private static Game _game;
2024-02-21 16:24:29 +08:00
private bool _isInited;
2023-08-22 19:08:45 +08:00
private void Awake()
{
DontDestroyOnLoad(gameObject);
2024-09-09 15:20:28 +08:00
ActivationTrack activationTrack = new(); // 防止被裁剪
ActivationControlPlayable activationControlPlayable = new(); // 防止被裁剪
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()
{
_isInited = false;
#if USE_YOO
await YooAssetHelper.Init();
#endif
_isInited = true;
_InitGame();
}
2023-12-15 19:25:08 +08:00
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-02-21 16:24:29 +08:00
if (!_isInited) return;
2023-08-22 19:08:45 +08:00
_game.Update(Time.deltaTime);
}
private void OnApplicationPause(bool pauseStatus)
{
2024-02-21 16:24:29 +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
}