예제 #1
0
 void Awake()
 {
     if (instance == null)
     {
         instance = this.GetComponent <WebSocketReceiver>();
     }
     DontDestroyOnLoad(this.gameObject);
 }
예제 #2
0
        /// <summary>
        /// 如果没有Receiver物体,用这个函数创建
        /// </summary>
        public static void AutoCreateInstance()
        {
            GameObject go = GameObject.Find("/WebSocketReceiver");

            if (go == null)
            {
                go = new GameObject("WebSocketReceiver");
            }

            if (go.GetComponent <WebSocketReceiver>() == null)
            {
                go.AddComponent <WebSocketReceiver>();
            }

            instance = go.GetComponent <WebSocketReceiver>();
        }