此为自动产生继承monobehavior物件

using UnityEngine;

public abstract class xxx<T> : MonoBehaviour where T : MonoBehaviour
{
static T m_Instance = null;

static public T Create() { return Instance; }

static public T Instance
{
get
{
if( m_Instance == null )
{
var gameObj = GameObject.Find( "#Daemon" );
if( gameObj == null ) gameObj = new GameObject( "#Daemon" );
Object.DontDestroyOnLoad( gameObj );
m_Instance = gameObj.AddComponent<T>();
}
return m_Instance;
}
}

public virtual void OnApplicationQuit ()
{
m_Instance = null;
}
}

 

使用方式

public class test: CDaemon<IdolCallManager>

相关文章