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

arrow
arrow
    文章標籤
    abstract template unity c#
    全站熱搜

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