Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.
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)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using FullSerializer;
using UnityEditor;
using UnityEngine;
using System.Reflection;

namespace FullInspector.Internal {
public class fiGenericPropertyDrawerPropertyEditor<TContainer, T> : PropertyEditor<T>
Expand Down Expand Up @@ -147,28 +148,45 @@ public override string ToString() {
}
}

private static readonly PropertyDrawerContainer[] _propertyDrawers;
private static readonly List<PropertyDrawerContainer> _propertyDrawers = new List<PropertyDrawerContainer>();

static fiGenericPropertyDrawerPropertyEditorManager() {
_propertyDrawers =
(from assembly in fiRuntimeReflectionUtility.GetAllEditorAssemblies()
from type in assembly.GetTypesWithoutException()

let attrs = type.GetCustomAttributes(typeof(CustomPropertyDrawer), true)
where attrs != null

// Do not generate bindings for various the PropertyDrawer
// binders
where type != typeof(fiInspectorOnly_PropertyDrawer)
where type != typeof(fiValuePropertyDrawer)

from CustomPropertyDrawer attr in attrs

select new PropertyDrawerContainer {
// Unity renamed these fields after 4.3
IsInherited = fiRuntimeReflectionUtility.ReadFields<CustomPropertyDrawer, bool>(attr, "m_UseForChildren", "useForChildren"),
PropertyType = fiRuntimeReflectionUtility.ReadFields<CustomPropertyDrawer, Type>(attr, "m_Type", "Type", "type") // Unity sure likes to rename things...
}).ToArray();
Assembly[] assemblies = fiRuntimeReflectionUtility.GetAllEditorAssembliesAsArray();
for (int i = 0; i < assemblies.Length; i++) {
Type[] types = assemblies[i].GetTypesWithoutException();
for (var j = 0; j < types.Length; j++) {
var type = types[j];
if (type == typeof(fiInspectorOnly_PropertyDrawer) || type == typeof(fiValuePropertyDrawer)) {
continue;
}

var attrs = type.GetCustomAttributes(typeof(CustomPropertyDrawer), true) as CustomPropertyDrawer[];
if (attrs == null) {
continue;
}

for (int k = 0; k < attrs.Length; k++) {
var attr = attrs[k];
if (attr == null) {
continue;
}

var container = new PropertyDrawerContainer() {
// Unity renamed these fields after 4.3
IsInherited =
fiRuntimeReflectionUtility.ReadFields<CustomPropertyDrawer, bool>(
attr,
"m_UseForChildren",
"useForChildren"),
PropertyType = fiRuntimeReflectionUtility.ReadFields<CustomPropertyDrawer, Type>(attr, "m_Type", "Type", "type")

// Unity sure likes to rename things...
};

_propertyDrawers.Add(container);
}
}
}
}

private static bool HasPropertyDrawer(Type type) {
Expand Down
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 );
}
});
}
}
}
}
34 changes: 18 additions & 16 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,23 +210,19 @@ 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);
}
}

public static void ShowInspectorForSerializedObject(UnityObject target) {
ShowInspectorForSerializedObject(new[] { target });
}

public static void ShowInspectorForSerializedObject(UnityObject[] targets) {
CheckForNewBaseBehaviorType(targets[0].GetType());
DrawOpenScriptButton(targets[0]);
Expand Down Expand Up @@ -266,8 +263,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 +292,4 @@ public override void OnPreviewSettings() {
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ namespace FullInspector.Internal {
[CanEditMultipleObjects]
[CustomEditor(typeof(MonoBehaviour), true)]
public class fiInspectorOnly_MonoBehaviourEditor : Editor {
private readonly UnityEngine.Object[] _targetArr = new UnityEngine.Object[1];
public override void OnInspectorGUI() {
if (fsPortableReflection.HasAttribute<fiInspectorOnlyAttribute>(target.GetType()) || target is tkCustomEditor) {
fiCommonSerializedObjectEditor.ShowInspectorForSerializedObject(target);
_targetArr[0] = target;
fiCommonSerializedObjectEditor.ShowInspectorForSerializedObject(_targetArr);
}
else {
base.OnInspectorGUI();
Expand Down
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
11 changes: 9 additions & 2 deletions Assets/FullInspector2/Core/Utility/fiAssemblyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
using System;
using System.Reflection;
using System.Collections.Generic;

namespace FullInspector.Internal {
public static class fiAssemblyExtensions {
private static Type[] s_EmptyArray = { };
private static readonly Type[] s_EmptyArray = { };
private static readonly Dictionary<Assembly, Type[]> s_assemblyTotypeCache = new Dictionary<Assembly, Type[]>();

public static Type[] GetTypesWithoutException(this Assembly assembly) {
try {
return assembly.GetTypes();
Type[] types;
if (!s_assemblyTotypeCache.TryGetValue(assembly, out types)) {
s_assemblyTotypeCache[assembly] = types = assembly.GetTypes();
}

return types;
}
catch {
return s_EmptyArray;
Expand Down
Loading