Files
Ultimate-Fishing-Simulator-…/Assets/Scripts/Assembly-CSharp/RootMotion/LazySingleton.cs
2026-03-04 09:37:33 +08:00

29 lines
473 B
C#

using UnityEngine;
namespace RootMotion
{
public abstract class LazySingleton<T> : MonoBehaviour where T : LazySingleton<T>
{
private static T sInstance;
public static bool hasInstance => sInstance != null;
public static T instance
{
get
{
if (sInstance == null)
{
sInstance = new GameObject(typeof(T).ToString()).AddComponent<T>();
}
return sInstance;
}
}
protected virtual void Awake()
{
sInstance = (T)this;
}
}
}