Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

Multi-scene support for storage systems #201

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Assets/FullInspector2/Core/Editor/IBehaviorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void Edit(Rect rect, UnityObject behavior) {
EditorGUIUtility.labelWidth = fiGUI.PushLabelWidth(GUIContent.none, rect.width);

// Run the editor
OnEdit(rect, (TBehavior)behavior, fiPersistentMetadata.GetMetadataFor(behavior));
OnEdit(rect, (TBehavior)behavior, fiPersistentMetadata.GetMetadataFor(new fiUnityObjectReference(behavior, tryRestore: false)));

EditorGUIUtility.labelWidth = savedLabelWidth;

Expand All @@ -99,7 +99,7 @@ public void Edit(Rect rect, UnityObject behavior) {
}

public float GetHeight(UnityObject behavior) {
return OnGetHeight((TBehavior)behavior, fiPersistentMetadata.GetMetadataFor(behavior));
return OnGetHeight((TBehavior)behavior, fiPersistentMetadata.GetMetadataFor(new fiUnityObjectReference(behavior, tryRestore: false)));
}
}
}
21 changes: 10 additions & 11 deletions Assets/FullInspector2/Core/Editor/fiAutoCleanMissingScripts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,19 @@ public static void AutoCleanupMissingScripts() {
// NOTE: If this approach doesn't work, then we can use
// RemoveComponent with the specific component type to
// remove. This is more similar to how RemoveMetadata works.
fiEditorUtility.RemoveMissingScripts(fiPersistentEditorStorage.SceneStorage);
EditorUtility.SetDirty(fiPersistentEditorStorage.SceneStorage);
fiEditorUtility.RemoveMissingScripts(fiPersistentEditorStorage.PrefabStorage);
foreach (var storage in fiPersistentEditorStorage.GetAllCachedSceneStorages()) {
fiEditorUtility.RemoveMissingScripts(storage.gameObject);
EditorUtility.SetDirty(storage);
}

fiEditorUtility.RemoveMissingScripts(fiPersistentEditorStorage.PrefabStorage.gameObject);
EditorUtility.SetDirty(fiPersistentEditorStorage.PrefabStorage);

if (fiPrefabManager.Storage != null) {
fiEditorUtility.RemoveMissingScripts(fiPrefabManager.Storage.gameObject);
EditorUtility.SetDirty(fiPrefabManager.Storage);
}
if (fiSceneManager.Storage != null) {
fiEditorUtility.RemoveMissingScripts(fiSceneManager.Storage.gameObject);
EditorUtility.SetDirty(fiSceneManager.Storage);
if (fiStorageManager.PrefabStorage != null) {
fiEditorUtility.RemoveMissingScripts(fiStorageManager.PrefabStorage .gameObject);
EditorUtility.SetDirty(fiStorageManager.PrefabStorage );
}
});
}
}
}
}
30 changes: 18 additions & 12 deletions Assets/FullInspector2/Core/Editor/fiCommonSerializedObjectEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,12 @@ public void OnDisable() {
BehaviorEditor.Get(target.GetType()).OnEditorDeactivate(target);
}

private static void ShowBackupButton(UnityObject target) {
if (target is CommonBaseBehavior == false) {
private static void ShowBackupButton(fiUnityObjectReference target) {
if (target.Target is CommonBaseBehavior == false) {
return;
}

var behavior = (CommonBaseBehavior)target;

if (fiStorageManager.HasBackups(behavior)) {
if (fiStorageManager.HasBackups(target)) {
// TODO: find a better location for these calls
fiStorageManager.MigrateStorage();
fiStorageManager.RemoveInvalidBackups();
Expand All @@ -129,16 +127,18 @@ private static void ShowBackupButton(UnityObject target) {
GUILayout.Space(marginVertical);
GUI.Box(boxed, GUIContent.none);


{
List<fiSerializedObject> toRemove = new List<fiSerializedObject>();

GUILayout.BeginVertical(GUILayout.ExpandWidth(true));
fiBackupEditorGUILayout.DrawBackupsFor(behavior, toRemove);
fiBackupEditorGUILayout.DrawBackupsFor(target, toRemove);
GUILayout.EndVertical();

foreach (fiSerializedObject rem in toRemove) {
fiStorageManager.RemoveBackup(rem);
}

}

GUILayout.Space(marginVertical);
Expand Down Expand Up @@ -169,6 +169,7 @@ private static void DrawOpenScriptButton(UnityObject element) {
/* TODO: Support replacing the script with another one.
if (newScript != monoScript &&
element is MonoBehaviour && element is ISerializedObject) {

var root = ((MonoBehaviour)element).gameObject;
var newInstance = root.AddComponent(newScript.GetClass());
var newSerialized = new SerializedObject(newInstance);
Expand Down Expand Up @@ -209,15 +210,15 @@ private static void CheckForNewBaseBehaviorType(Type type) {
// 5. When these objects are next serialized, they will use the
// incorrect prefab data. Null check, sometimes there is no prefab
// state.
if (fiPrefabManager.Storage == null || fiPrefabManager.Storage.SeenBaseBehaviors == null)
if (fiStorageManager.PrefabStorage == null || fiStorageManager.PrefabStorage .SeenBaseBehaviors == null)
return;

if (fiPrefabManager.Storage.SeenBaseBehaviors.Contains(type.CSharpName()) == false) {
if (fiStorageManager.PrefabStorage .SeenBaseBehaviors.Contains(type.CSharpName()) == false) {
fiLog.Log(typeof(fiCommonSerializedObjectEditor),
"Saving all BaseBehaviors of type " + type.CSharpName());

fiPrefabManager.Storage.SeenBaseBehaviors.Add(type.CSharpName());
EditorUtility.SetDirty(fiPrefabManager.Storage);
fiStorageManager.PrefabStorage .SeenBaseBehaviors.Add(type.CSharpName());
EditorUtility.SetDirty(fiStorageManager.PrefabStorage );
fiSaveManager.SaveAll(type);
}
}
Expand Down Expand Up @@ -266,8 +267,13 @@ public static void ShowInspectorForSerializedObject(UnityObject[] targets) {
}
}

private fiUnityObjectReference _fiUnityObjectReference;
public override void OnInspectorGUI() {
ShowBackupButton(target);
if (_fiUnityObjectReference == null) {
_fiUnityObjectReference = new fiUnityObjectReference(target, tryRestore: false);
}

ShowBackupButton(_fiUnityObjectReference);
ShowInspectorForSerializedObject(targets);
}

Expand All @@ -290,4 +296,4 @@ public override void OnPreviewSettings() {
}
}
}
}
}
38 changes: 22 additions & 16 deletions Assets/FullInspector2/Core/Editor/fiLateBindingsBinder.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEngine;
using UnityEditor.SceneManagement;

namespace FullInspector.Internal {

// note: See the docs on fiLateBindings This is just the actual injection
// code which only gets run if we're in an editor
// note: See the docs on fiLateBindings
// This is just the actual injection code which only gets run if we're in an editor
//
// note: If there is ever a binding that doesn't occur quickly enough, then
// we can use reflection to discover it immediately
// note: If there is ever a binding that doesn't occur quickly enough, then we can use
// reflection to discover it immediately

[InitializeOnLoad]
public class fiLateBindingsBinder {
static fiLateBindingsBinder() {
fiLateBindings._Bindings._AssetDatabase_LoadAssetAtPath = AssetDatabase.LoadAssetAtPath;
fiLateBindings._Bindings._AssetDatabase_SaveAssets = AssetDatabase.SaveAssets;


fiLateBindings._Bindings._EditorApplication_isPlaying = () => EditorApplication.isPlaying;
fiLateBindings._Bindings._EditorApplication_isCompilingOrChangingToPlayMode = () => EditorApplication.isCompiling || EditorApplication.isPlayingOrWillChangePlaymode;
Expand All @@ -26,24 +27,22 @@ static fiLateBindingsBinder() {
};
EditorApplication.update += updateFn;
};
fiLateBindings._Bindings._EditorApplication_Callbacks = new List<Action>();
fiLateBindings._Bindings._EditorApplication_CallbacksToBeAdded = new List<Action>();
fiLateBindings._Bindings._EditorApplication_CallbacksToBeRemoved = new List<Action>();
fiLateBindings._Bindings._EditorApplication_AddUpdateAction = a => fiLateBindings._Bindings._EditorApplication_CallbacksToBeAdded.Add(a);
fiLateBindings._Bindings._EditorApplication_RemUpdateAction = a => fiLateBindings._Bindings._EditorApplication_CallbacksToBeRemoved.Add(a);
EditorApplication.update -= OnEditorUpdate;
EditorApplication.update += OnEditorUpdate;

fiLateBindings._Bindings._EditorApplication_AddUpdateAction = a => EditorApplication.update += new EditorApplication.CallbackFunction(a);
fiLateBindings._Bindings._EditorApplication_RemUpdateAction = a => EditorApplication.update -= new EditorApplication.CallbackFunction(a);
fiLateBindings._Bindings._EditorApplication_timeSinceStartup = () => EditorApplication.timeSinceStartup;


fiLateBindings._Bindings._EditorPrefs_GetString = EditorPrefs.GetString;
fiLateBindings._Bindings._EditorPrefs_SetString = EditorPrefs.SetString;


fiLateBindings._Bindings._EditorUtility_SetDirty = EditorUtility.SetDirty;
fiLateBindings._Bindings._SceneManagement_EditorSceneManager_MarkSceneDirty = EditorSceneManager.MarkSceneDirty;
fiLateBindings._Bindings._EditorUtility_InstanceIdToObject = EditorUtility.InstanceIDToObject;
fiLateBindings._Bindings._EditorUtility_IsPersistent = EditorUtility.IsPersistent;
fiLateBindings._Bindings._EditorUtility_CreateGameObjectWithHideFlags = (name, flags) => EditorUtility.CreateGameObjectWithHideFlags(name, flags);


fiLateBindings._Bindings._EditorGUI_BeginChangeCheck = EditorGUI.BeginChangeCheck;
fiLateBindings._Bindings._EditorGUI_EndChangeCheck = EditorGUI.EndChangeCheck;
fiLateBindings._Bindings._EditorGUI_BeginDisabledGroup = EditorGUI.BeginDisabledGroup;
Expand All @@ -54,33 +53,40 @@ static fiLateBindingsBinder() {
fiLateBindings._Bindings._EditorGUI_Popup = EditorGUI.Popup;
fiLateBindings._Bindings._EditorGUI_Slider = EditorGUI.Slider;


fiLateBindings.EditorGUIUtility.standardVerticalSpacing = EditorGUIUtility.standardVerticalSpacing;
fiLateBindings.EditorGUIUtility.singleLineHeight = EditorGUIUtility.singleLineHeight;


fiLateBindings._Bindings._EditorStyles_label = () => EditorStyles.label;
fiLateBindings._Bindings._EditorStyles_foldout = () => EditorStyles.foldout;


fiLateBindings._Bindings._fiEditorGUI_PushHierarchyMode = state => fiEditorGUI.PushHierarchyMode(state);
fiLateBindings._Bindings._fiEditorGUI_PopHierarchyMode = () => fiEditorGUI.PopHierarchyMode();


fiLateBindings._Bindings._PrefabUtility_CreatePrefab = (string path, GameObject template) => PrefabUtility.CreatePrefab(path, template);
fiLateBindings._Bindings._PrefabUtility_IsPrefab = unityObj => PrefabUtility.GetPrefabType(unityObj) == PrefabType.Prefab;
fiLateBindings._Bindings._PrefabUtility_IsPrefabInstance = unityObj => PrefabUtility.GetPrefabType(unityObj) == PrefabType.PrefabInstance;


fiLateBindings._Bindings._PropertyEditor_Edit =
(objType, attrs, rect, label, obj, metadata, skippedEditors) =>
PropertyEditor.Get(objType, attrs).SkipUntilNot(skippedEditors).Edit(rect, label, obj, metadata);
fiLateBindings._Bindings._PropertyEditor_GetElementHeight =
(objType, attrs, label, obj, metadata, skippedEditors) =>
PropertyEditor.Get(objType, attrs).SkipUntilNot(skippedEditors).GetElementHeight(label, obj, metadata);


fiLateBindings._Bindings._PropertyEditor_EditSkipUntilNot =
(skipUntilNot, objType, attrs, rect, label, obj, metadata) =>
PropertyEditor.Get(objType, attrs).SkipUntilNot(skipUntilNot).Edit(rect, label, obj, metadata);
fiLateBindings._Bindings._PropertyEditor_GetElementHeightSkipUntilNot =
(skipUntilNot, objType, attrs, label, obj, metadata) =>
PropertyEditor.Get(objType, attrs).SkipUntilNot(skipUntilNot).GetElementHeight(label, obj, metadata);


fiLateBindings._Bindings._Selection_activeObject = () => Selection.activeObject;
fiLateBindings._Bindings._Selection_activeSelection = () => {
if (Selection.activeObject is GameObject)
Expand Down Expand Up @@ -116,4 +122,4 @@ public static void EnsureLoaded() {
// no-op, but it ensures that the static constructor has executed
}
}
}
}
5 changes: 4 additions & 1 deletion Assets/FullInspector2/Core/Editor/fiSaveManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ public static void RestoreAll() {

[MenuItem("Window/Full Inspector/Developer/Remove Metadata", priority = 2)]
public static void RemoveMetadata() {
fiUtility.DestroyObject(fiPersistentEditorStorage.SceneStorage);
foreach (var storage in fiPersistentEditorStorage.GetAllCachedSceneStorages()) {
fiUtility.DestroyObject(storage);
}

fiUtility.DestroyObject(fiPersistentEditorStorage.PrefabStorage);
}

Expand Down
22 changes: 22 additions & 0 deletions Assets/FullInspector2/Core/fiLateBindings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityObject = UnityEngine.Object;

namespace FullInspector.Internal {
Expand All @@ -16,6 +17,7 @@ namespace FullInspector.Internal {
public static class fiLateBindings {
public static class _Bindings {
public static Func<string, Type, UnityObject> _AssetDatabase_LoadAssetAtPath;
public static Action _AssetDatabase_SaveAssets;

public static Func<bool> _EditorApplication_isPlaying;
public static Func<bool> _EditorApplication_isCompilingOrChangingToPlayMode;
Expand All @@ -31,6 +33,7 @@ public static class _Bindings {
public static Action<string, string> _EditorPrefs_SetString;

public static Action<UnityObject> _EditorUtility_SetDirty;
public static Func<Scene, bool> _SceneManagement_EditorSceneManager_MarkSceneDirty;
public static Func<int, UnityObject> _EditorUtility_InstanceIdToObject;
public static Func<UnityObject, bool> _EditorUtility_IsPersistent;
public static Func<string, HideFlags, GameObject> _EditorUtility_CreateGameObjectWithHideFlags;
Expand Down Expand Up @@ -81,6 +84,12 @@ public static UnityObject LoadAssetAtPath(string path, Type type) {
}
return null;
}

public static void SaveAssets() {
if (VerifyBinding("AssetDatabase.SaveAssets", _Bindings._AssetDatabase_SaveAssets)) {
_Bindings._AssetDatabase_SaveAssets();
}
}
}

public static class EditorApplication {
Expand Down Expand Up @@ -179,6 +188,19 @@ public static GameObject CreateGameObjectWithHideFlags(string name, HideFlags hi
}
}


public static class SceneManagement {
public static class EditorSceneManager {
public static bool MarkSceneDirty(Scene scene) {
if (VerifyBinding("EditorSceneManager.MarkSceneDirty", _Bindings._SceneManagement_EditorSceneManager_MarkSceneDirty)) {
return _Bindings._SceneManagement_EditorSceneManager_MarkSceneDirty(scene);
}

return false;
}
}
}

public static class EditorGUI {
public static void BeginChangeCheck() {
if (VerifyBinding("EditorGUI.BeginChangeCheck", _Bindings._EditorGUI_BeginDisabledGroup)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.Collections.Generic;
using FullInspector.Internal;
using FullInspector.Internal;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityObject = UnityEngine.Object;
Expand All @@ -10,15 +10,22 @@ namespace FullInspector.BackupService {
/// viewer.
/// </summary>
public class fiBackupEditorGUILayout {
public static void DrawBackupsFor(UnityObject target, List<fiSerializedObject> toRemove) {

public static void DrawBackupsFor(fiUnityObjectReference target, List<fiSerializedObject> toRemove) {
bool showSpace = false;

fiEditorGUI.PushHierarchyMode(false);

fiGraphMetadata metadata = fiPersistentMetadata.GetMetadataFor(target);

foreach (fiSerializedObject backup in fiStorageManager.SerializedObjects) {
if (backup.Target.Target != target) {
var t = target.Target as CommonBaseBehavior;
if (t == null) {
return;
}

var backups = fiBackupManager.GetBackupsFor(t);
foreach (fiSerializedObject backup in backups) {
if (!Equals(backup.Target, target)) {
continue;
}

Expand Down Expand Up @@ -88,7 +95,7 @@ public static void DisplayDeserializedObject(fiDeserializedObject obj, fiGraphMe

string label = member.InspectedProperty.DisplayName;
if (member.ShouldRestore.Enabled) {
editor.FirstEditor.EditWithGUILayout(new GUIContent(label), member.Value, metadata.Enter(label, null));
editor.FirstEditor.EditWithGUILayout(new GUIContent(label), member.Value, metadata.Enter(label, metadata.Context));
}
else {
GUILayout.Label(new GUIContent(label + " (will not restore)"));
Expand All @@ -107,4 +114,4 @@ public static void DisplayDeserializedObject(fiDeserializedObject obj, fiGraphMe
EditorGUILayout.EndHorizontal();
}
}
}
}
Loading