Ejemplo n.º 1
0
    static void PlaymodeStateChanged()
        #endif
    {
        // This is called when we press the Play button, but before serialisation takes place.
        if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
        {
            var go = GameObject.Find("Easy Save 3 Manager");
            var defaultSettings = ES3EditorUtility.GetDefaultSettings();
            if (go == null && !defaultSettings.addMgrToSceneAutomatically)
            {
                return;
            }

            AddManagerToScene();

            if (defaultSettings.autoUpdateReferences)
            {
                _refMgr.GenerateReferences();
                _refMgr.GeneratePrefabReferences();
            }
            _autoSaveMgr.UpdateAutoSaves();

            AssetDatabase.Refresh();
        }
    }
Ejemplo n.º 2
0
    public static GameObject AddManagerToScene()
    {
        if (_refMgr != null)
        {
            return(_refMgr.gameObject);
        }

        var mgr = GameObject.Find("Easy Save 3 Manager");

        if (mgr == null)
        {
            mgr = new GameObject("Easy Save 3 Manager");
            var inspectorInfo = mgr.AddComponent <ES3InspectorInfo>();
            inspectorInfo.message = "The Easy Save 3 Manager is required in any scenes which use Easy Save, and is automatically added to your scene when you enter Play mode.\n\nTo stop this from automatically being added to your scene, go to 'Window > Easy Save 3 > Settings' and deselect the 'Auto Add Manager to Scene' checkbox.";

            _refMgr      = mgr.AddComponent <ES3ReferenceMgr>();
            _autoSaveMgr = mgr.AddComponent <ES3AutoSaveMgr>();

            foreach (var obj in EditorSceneManager.GetActiveScene().GetRootGameObjects())
            {
                if (obj != mgr && !changedSinceLastSave.Contains(obj))
                {
                    changedSinceLastSave.Enqueue(obj);
                }
            }

            _refMgr.GeneratePrefabReferences();

            Undo.RegisterCreatedObjectUndo(mgr, "Enabled Easy Save for Scene");
        }
        else
        {
            _refMgr = mgr.GetComponent <ES3ReferenceMgr>();
            if (_refMgr == null)
            {
                _refMgr = mgr.AddComponent <ES3ReferenceMgr>();
                Undo.RegisterCreatedObjectUndo(_refMgr, "Enabled Easy Save for Scene");
            }

            _autoSaveMgr = mgr.GetComponent <ES3AutoSaveMgr>();
            if (_autoSaveMgr == null)
            {
                _autoSaveMgr = mgr.AddComponent <ES3AutoSaveMgr>();
                Undo.RegisterCreatedObjectUndo(_autoSaveMgr, "Enabled Easy Save for Scene");
            }
        }
        return(mgr);
    }
Ejemplo n.º 3
0
    public static void RefreshReferences()
    {
        if (_defaultSettings == null)
        {
            _defaultSettings = ES3EditorUtility.GetDefaultSettings();
        }

        if (_defaultSettings.addMgrToSceneAutomatically)
        {
            if (_refMgr == null)
            {
                AddManagerToScene();
            }
        }

        if (_defaultSettings.autoUpdateReferences && _refMgr != null)
        {
            _refMgr.GenerateReferences();
            _refMgr.GeneratePrefabReferences();
        }
    }