添加场景、对应场景代码
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameFramework
|
||||
{
|
||||
/// <summary>
|
||||
/// 持久化单例基类。跨场景保留(DontDestroyOnLoad),重复实例自动销毁。
|
||||
/// 管理器(AudioManager / ScoreManager / GameManager / SceneLoader)都继承它。
|
||||
/// </summary>
|
||||
public class PersistentSingleton<T> : MonoBehaviour where T : Component
|
||||
{
|
||||
public static T Instance { get; private set; }
|
||||
|
||||
protected virtual void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this as T;
|
||||
}
|
||||
else if (Instance != this)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user