Unity小白文——單例的定義

當類繼承與MonoBehaviour時this

public class TestSingle : MonoBehaviour繼承

{get

      public static TestSingle Instance;io

 

     void Awake()class

   {static

        Instance = this ;vi

   }new

}return

 

當類不繼承與MonoBehaviour時void

public class TestSingle :

{

     public static TestSingle instance;

     public static TestSingle Instance

    {

          get

          {

              if(instance == null)

                  instance = new TestSingle();

               return instance;

          }

    }

}

相關文章
相關標籤/搜索