26 lines
774 B
C#
26 lines
774 B
C#
|
/********************************************************************
|
|||
|
文件: SingletonForMono.cs
|
|||
|
作者: 梦语
|
|||
|
邮箱: 1982614048@qq.com
|
|||
|
创建时间: 2024/03/29 17:28:19
|
|||
|
最后修改: 梦语
|
|||
|
最后修改时间: 2024/04/03 16:06:20
|
|||
|
功能: Mono单例(手动挂载到物体上,继承mono的单例需自己保证唯一性)
|
|||
|
*********************************************************************/
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
public class SingletonForMono<T> : MonoBehaviour where T : MonoBehaviour
|
|||
|
{
|
|||
|
private static T m_instance;
|
|||
|
|
|||
|
public static T Inst { get => m_instance; }
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
m_instance = this as T;
|
|||
|
Init();
|
|||
|
Debug.Log("初始化" + this.GetType().Name + "成功!");
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void Init() { }
|
|||
|
}
|