Exemplo n.º 1
0
        // Destroys the proxy game object that carries the instance of this class if one exists.
        static void DestroyProxy()
        {
            if (mInstance == null)
            {
                return;
            }

            if (!mIsToMainThreadQueueEmpty || mPauseCallbackQueue.Count > 0 || mFocusCallbackQueue.Count > 0)
            {
                return;
            }

            if (!mIsDummy)
            {
                Destroy(mInstance.gameObject);
            }

            mInstance = null;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the singleton instance of this class and a game object that carries it.
        /// This must be called once from the main thread.
        /// You can call it before accessing the <see cref="Instance"/> singleton,
        /// though <see cref="Instance"/> automatically calls this method if needed, so you can bypass this
        /// and access that property directly, provided that you're on the main thread.
        /// Also note that this method does nothing if initialization has been done before,
        /// so it's safe to call it multiple times.
        /// </summary>
        public static void Init()
        {
            if (mInstance != null)
            {
                return;
            }

            if (Application.isPlaying)
            {
                var go = new GameObject("EM_RuntimeHelper");
                go.hideFlags = HideFlags.HideAndDontSave;
                mInstance    = go.AddComponent <RuntimeHelper>();
                DontDestroyOnLoad(go);
            }
            else
            {
                mInstance = new RuntimeHelper();
                mIsDummy  = true;
            }
        }