public static GameObject AddManagerToScene() { var go = GameObject.Find("Easy Save 3 Manager"); if (go == null) { go = new GameObject("Easy Save 3 Manager"); var inspectorInfo = go.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 = go.AddComponent <ES3ReferenceMgr>(); _autoSaveMgr = go.AddComponent <ES3AutoSaveMgr>(); Undo.RegisterCreatedObjectUndo(go, "Enabled Easy Save for Scene"); } else { _refMgr = go.GetComponent <ES3ReferenceMgr>(); if (_refMgr == null) { _refMgr = go.AddComponent <ES3ReferenceMgr>(); Undo.RegisterCreatedObjectUndo(_refMgr, "Enabled Easy Save for Scene"); } _autoSaveMgr = go.GetComponent <ES3AutoSaveMgr>(); if (_autoSaveMgr == null) { _autoSaveMgr = go.AddComponent <ES3AutoSaveMgr>(); Undo.RegisterCreatedObjectUndo(_autoSaveMgr, "Enabled Easy Save for Scene"); } } return(go); }
public void GeneratePrefabReferences() { if (this.gameObject.scene.name != null) { return; } // Create a new reference list so that any objects which are no longer dependencies are removed. var tempLocalRefs = new ES3RefIdDictionary(); // Add the GameObject's dependencies to the reference list. foreach (var obj in ES3ReferenceMgr.CollectDependencies(this.gameObject)) { var dependency = (UnityEngine.Object)obj; if (obj == null || !ES3ReferenceMgr.CanBeSaved(dependency)) { continue; } var id = Get(dependency); // If we're adding a new reference, do an Undo.RecordObject to ensure it persists. if (id == -1) { Undo.RecordObject(this, "Update Easy Save 3 Prefab"); EditorUtility.SetDirty(this); } tempLocalRefs.Add(dependency, id == -1 ? GetNewRefID() : id); } localRefs = tempLocalRefs; }
public void GeneratePrefabReferences() { #if UNITY_2018_3_OR_NEWER var prefabType = PrefabUtility.GetPrefabInstanceStatus(this.gameObject); if (prefabType != PrefabInstanceStatus.NotAPrefab && prefabType != PrefabInstanceStatus.MissingAsset) { return; } #else var prefabType = PrefabUtility.GetPrefabType(this.gameObject); if (prefabType != PrefabType.Prefab && prefabType != PrefabType.MissingPrefabInstance) { return; } #endif // Get GameObject and it's children and add them to the reference list. foreach (var obj in EditorUtility.CollectDependencies(new UnityEngine.Object[] { this })) { if (obj == null || !ES3ReferenceMgr.CanBeSaved(obj)) { continue; } if (this.Get(obj) == -1) { Undo.RecordObject(this, "Update Easy Save 3 Prefab"); EditorUtility.SetDirty(this); Add(obj); } } }
static void AddGameObjectsAndComponentsToManager() { if (refMgr != null) { foreach (var obj in EditorUtility.CollectDeepHierarchy(SceneManager.GetActiveScene().GetRootGameObjects())) { // If this object can be saved, add it to the reference manager. if (ES3ReferenceMgr.CanBeSaved(obj)) { refMgr.Add(obj); } } refMgr.AddPrefabsToManager(); } }
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); }
public void GeneratePrefabReferences() { #if UNITY_2018_3_OR_NEWER if (this.gameObject.scene.name != null || UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null) #else if (this.gameObject.scene.name != null) #endif { return; } // Create a new reference list so that any objects which are no longer dependencies are removed. var tempLocalRefs = new ES3RefIdDictionary(); // Get dependencies of children also. var transforms = GetComponentsInChildren <Transform>(); var gos = new GameObject[transforms.Length]; for (int i = 0; i < transforms.Length; i++) { gos[i] = transforms[i].gameObject; } bool addedNewReference = false; // Add the GameObject's dependencies to the reference list. foreach (var obj in ES3ReferenceMgr.CollectDependencies(gos)) { var dependency = (UnityEngine.Object)obj; if (obj == null || !ES3ReferenceMgr.CanBeSaved(dependency)) { continue; } var id = Get(dependency); // If we're adding a new reference, do an Undo.RecordObject to ensure it persists. if (id == -1) { addedNewReference = true; Undo.RecordObject(this, "Update Easy Save 3 Prefab"); EditorUtility.SetDirty(this); } tempLocalRefs.Add(dependency, id == -1 ? GetNewRefID() : id); } if (addedNewReference || tempLocalRefs.Count != localRefs.Count) { localRefs = tempLocalRefs; } }
public long Add(UnityEngine.Object obj) { long id; if (localRefs.TryGetValue(obj, out id)) { return(id); } if (!ES3ReferenceMgr.CanBeSaved(obj)) { return(-1); } id = GetNewRefID(); localRefs.Add(obj, id); return(id); }
public long GetOrAdd(UnityEngine.Object obj) { if (Application.isPlaying) { ES3Debug.LogError("GetOrAdd can only be called in the Editor, not during runtime"); return(-1); } var id = Get(obj); if (id == -1 && UnityEditor.AssetDatabase.Contains(obj) && ES3ReferenceMgr.CanBeSaved(obj)) { id = ES3ReferenceMgrBase.GetNewRefID(); refId.Add(obj, id); UnityEditor.EditorUtility.SetDirty(this); } return(id); }
static UndoPropertyModification[] PostProcessModifications(UndoPropertyModification[] modifications) { if (refMgr != null) { // For each property which has had an Undo registered ... foreach (var mod in modifications) { // If this property change is an object reference, and the Component this change has been made to is in the scene, not in Assets ... if (mod.currentValue != null && mod.currentValue.objectReference != null && mod.currentValue.target != null && !AssetDatabase.Contains(mod.currentValue.target)) { // If this object reference can be saved ... if (ES3ReferenceMgr.CanBeSaved(mod.currentValue.objectReference)) { // Add it to the reference manager refMgr.Add(mod.currentValue.objectReference); } } } } return(modifications); }
public void GeneratePrefabReferences() { #if UNITY_2018_3_OR_NEWER var prefabType = PrefabUtility.GetPrefabInstanceStatus(this.gameObject); if (prefabType != PrefabInstanceStatus.NotAPrefab && prefabType != PrefabInstanceStatus.MissingAsset) { return; } #else var prefabType = PrefabUtility.GetPrefabType(this.gameObject); if (prefabType != PrefabType.Prefab && prefabType != PrefabType.MissingPrefabInstance) { return; } #endif // Create a new reference list so that any objects which are no longer dependencies are removed. var tempLocalRefs = new ES3RefIdDictionary(); // Add the GameObject's dependencies to the reference list. foreach (var obj in ES3ReferenceMgr.CollectDependencies(this.gameObject)) { var dependency = (UnityEngine.Object)obj; if (obj == null || !ES3ReferenceMgr.CanBeSaved(dependency)) { continue; } var id = Get(dependency); // If we're adding a new reference, do an Undo.RecordObject to ensure it persists. if (id == -1) { Undo.RecordObject(this, "Update Easy Save 3 Prefab"); EditorUtility.SetDirty(this); } tempLocalRefs.Add(dependency, id == -1 ? GetNewRefID() : id); } localRefs = tempLocalRefs; }
private static ES3ReferenceMgr GetReferenceMgr() { if (_refMgr == null) { var refMgrs = GameObject.FindObjectsOfType <ES3ReferenceMgr>(); if (refMgrs.Length > 1) { Debug.LogError("More than one ES3ReferenceMgr in scene."); } else if (refMgrs.Length == 1) { _refMgr = refMgrs[0]; } else { if (ES3EditorUtility.GetDefaultSettings().addMgrToSceneAutomatically) { _refMgr = ES3ReferenceMgrEditor.AddManagerToScene(); } } } return(_refMgr); }
public long GetOrAdd(UnityEngine.Object obj) { var id = Get(obj); // Only add items to global references when it's not playing. if (!Application.isPlaying && id == -1 && UnityEditor.AssetDatabase.Contains(obj) && ES3ReferenceMgr.CanBeSaved(obj)) { id = ES3ReferenceMgrBase.GetNewRefID(); refId.Add(obj, id); UnityEditor.EditorUtility.SetDirty(this); } return(id); }