在Launch中初始化GameSys
在GameSys中初始化游戏中各具体内容(系统、管理器……)
Launch.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Launch : MonoBehaviour
{
private void Start()
{
Init();
}
private void OnDestroy()
{
MyDestroy();
}
private void Init()
{
GameSys.Init();
}
private void MyDestroy()
{
GameSys.Instance?.MyDestroy();
}
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
private static void CreateLaunch()
{
var go = new GameObject(nameof(Launch)).AddComponent<Launch>();
}
}
GameSys.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameSys
{
public static GameSys Instance { get; private set; }
private GameSys()
{
// 初始化游戏内各具体内容
}
public static void Init()
{
if (Instance == null)
{
Instance = new GameSys();
}
}
public void MyDestroy()
{
Instance = null;
}
}
网友评论