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;

          }

    }

}

相关文章
相关标签/搜索