private void Reset()
        {
            //Note on threading: Because we don't wait for other threads to finish, we might be stealing function delegates from under their nose if Unity doesn't happen to close them yet.
            //On Preloaded mode this leads to NullReferenceException, but on Lazy mode the DLL and function would be just reloaded so we would up with loaded DLL after game exit.
            //Thankfully thread safety with Lazy mode is not implemented yet.

            if (DllManipulator.Options != null) // Check that we have initialized
            {
                DllManipulator.Reset();
            }
            _singletonInstance = null;
        }
        private void OnEnable()
        {
#if UNITY_EDITOR
            if (_singletonInstance != null)
            {
                if (EditorApplication.isPlaying)
                {
                    Destroy(gameObject);
                }
                else if (_singletonInstance != this)
                {
                    enabled = false; //Don't destroy as the user may be editing a Prefab
                }
                return;
            }
            _singletonInstance = this;

            if (EditorApplication.isPlaying)
            {
                DontDestroyOnLoad(gameObject);
            }

            if (EditorApplication.isPlaying || Options.enableInEditMode)
            {
                Initialize();
                AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
            }

            // Ensure update is called every frame in edit mode, ExecuteInEditMode only calls Update when the scene changes
            if (!EditorApplication.isPlaying && Options.enableInEditMode)
            {
                EditorApplication.update += Update;
            }
#else
            if (Options.onlyInEditor)
            {
                return;
            }

            if (_singletonInstance != null)
            {
                Destroy(gameObject);
                return;
            }
            _singletonInstance = this;

            DontDestroyOnLoad(gameObject);
            Initialize();
#endif
        }
Example #3
0
        private void OnDestroy()
        {
            if (_singletonInstance == this)
            {
                //Note on threading: Because we don't wait for other threads to finish, we might be stealing function delegates from under their nose if Unity doesn't happen to close them yet.
                //On Preloaded mode this leads to NullReferenceException, but on Lazy mode the DLL and function would be just reloaded so we would up with loaded DLL after game exit.
                //Thankfully thread safety with Lazy mode is not implemented yet.

                DllManipulator.UnloadAll();
                DllManipulator.ForgetAllDlls();
                DllManipulator.ClearCrashLogs();
                _singletonInstance = null;
            }
        }
Example #4
0
        private void OnEnable()
        {
#if UNITY_EDITOR
            if (_singletonInstance != null)
            {
                if (EditorApplication.isPlaying)
                {
                    Destroy(gameObject);
                }
                else
                {
                    enabled = false; //Don't destroy as the user may be editing a Prefab
                }
                return;
            }
            _singletonInstance = this;

            if (EditorApplication.isPlaying)
            {
                DontDestroyOnLoad(gameObject);
            }

            if (EditorApplication.isPlaying || Options.enableInEditMode)
            {
                Initialize();
            }
#else
            if (Options.onlyInEditor)
            {
                return;
            }

            if (_singletonInstance != null)
            {
                Destroy(gameObject);
                return;
            }
            _singletonInstance = this;

            DontDestroyOnLoad(gameObject);
            Initialize();
#endif
        }