此為自動產生繼承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>

, , ,

狼翔月影 發表在 痞客邦 PIXNET 留言(0) 人氣()