1.8.0: Added AssetsOnly, SceneObjectsOnly, AssignAssetIfNull, AssignComponentIfNull
- Attributes: Added AssetsOnly, SceneObjectsOnly, AssignAssetIfNull, AssignComponentIfNull - Attributes: Replaced AssignIfNull with AssignComponentIfNull
This commit is contained in:
parent
070b82767f
commit
eb19150d98
|
|
@ -1,5 +1,4 @@
|
||||||
using System.Reflection;
|
using Module.Inspector.Editor.Utilities;
|
||||||
using Module.Inspector.Editor.Utilities;
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
|
|
@ -21,25 +20,20 @@ namespace Module.Inspector.Editor
|
||||||
if (!IsValidTarget())
|
if (!IsValidTarget())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
FieldInfo[] fields = EditorHiddenFieldUtility.Query(target);
|
EditorHiddenFieldUtility.EditableFieldInfo[] fields = EditorHiddenFieldUtility.Query(target);
|
||||||
|
|
||||||
if (fields.Length == 0)
|
if (fields.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float totalHeight = EditorHiddenFieldUtility.CalculateHeight(fields) + EditorGUIUtility.singleLineHeight * 2;
|
float totalHeight = EditorHiddenFieldUtility.CalculateHeight(fields) + EditorGUIUtility.singleLineHeight * 2;
|
||||||
GUILayout.Space(totalHeight);
|
GUILayout.Space(totalHeight);
|
||||||
|
|
||||||
var position = new Rect(0, 0, 1, 1);
|
|
||||||
|
|
||||||
if (Event.current.type == EventType.Repaint)
|
|
||||||
{
|
|
||||||
position = GUILayoutUtility.GetLastRect();
|
|
||||||
position.y -= totalHeight;
|
|
||||||
|
|
||||||
#if UNITY_2020_1_OR_NEWER
|
Rect position = GUILayoutUtility.GetLastRect();
|
||||||
position.width = EditorGUIUtility.currentViewWidth - 22.0f;
|
position.y -= totalHeight;
|
||||||
#endif
|
|
||||||
}
|
#if UNITY_2020_1_OR_NEWER
|
||||||
|
position.width = EditorGUIUtility.currentViewWidth - 22.0f;
|
||||||
|
#endif
|
||||||
|
|
||||||
position.y = position.yMax + EditorGUIUtility.singleLineHeight;
|
position.y = position.yMax + EditorGUIUtility.singleLineHeight;
|
||||||
position.height = EditorGUIUtility.singleLineHeight;
|
position.height = EditorGUIUtility.singleLineHeight;
|
||||||
|
|
|
||||||
|
|
@ -9,20 +9,20 @@ namespace Module.Inspector.Editor.Utilities
|
||||||
{
|
{
|
||||||
internal static class EditorHiddenFieldUtility
|
internal static class EditorHiddenFieldUtility
|
||||||
{
|
{
|
||||||
private static Dictionary<Type, FieldInfo[]> CACHED_TYPE_TO_PRIMARIES;
|
private static Dictionary<Type, EditableFieldInfo[]> CACHED_TYPE_TO_PRIMARIES;
|
||||||
|
|
||||||
public static FieldInfo[] Query(Object target)
|
public static EditableFieldInfo[] Query(Object target)
|
||||||
{
|
{
|
||||||
Type type = target.GetType();
|
Type type = target.GetType();
|
||||||
var att = type.GetCustomAttribute<EnableShowHiddenFieldsAttribute>();
|
var att = type.GetCustomAttribute<EnableShowHiddenFieldsAttribute>();
|
||||||
|
|
||||||
if (att == null)
|
if (att == null)
|
||||||
return new FieldInfo[0];
|
return new EditableFieldInfo[0];
|
||||||
|
|
||||||
if (CACHED_TYPE_TO_PRIMARIES == null)
|
if (CACHED_TYPE_TO_PRIMARIES == null)
|
||||||
CACHED_TYPE_TO_PRIMARIES = new Dictionary<Type, FieldInfo[]>();
|
CACHED_TYPE_TO_PRIMARIES = new Dictionary<Type, EditableFieldInfo[]>();
|
||||||
|
|
||||||
if (CACHED_TYPE_TO_PRIMARIES.TryGetValue(type, out FieldInfo[] fields))
|
if (CACHED_TYPE_TO_PRIMARIES.TryGetValue(type, out EditableFieldInfo[] fields))
|
||||||
return fields;
|
return fields;
|
||||||
|
|
||||||
fields = InternalFetch(type, att.UseFieldProperty);
|
fields = InternalFetch(type, att.UseFieldProperty);
|
||||||
|
|
@ -30,39 +30,66 @@ namespace Module.Inspector.Editor.Utilities
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float CalculateHeight(FieldInfo[] fields)
|
public static float CalculateHeight(EditableFieldInfo[] fields)
|
||||||
{
|
{
|
||||||
return EditorGUIUtility.singleLineHeight * fields.Length;
|
return EditorGUIUtility.singleLineHeight * fields.Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Draw(Rect rect, FieldInfo field, Object target)
|
public static void Draw(Rect rect, EditableFieldInfo field, Object target)
|
||||||
{
|
{
|
||||||
bool prevEnabled = GUI.enabled;
|
bool prevEnabled = GUI.enabled;
|
||||||
GUI.enabled = false;
|
GUI.enabled = field.editable;
|
||||||
string nicifiedName = ObjectNames.NicifyVariableName(field.Name);
|
string nicifiedName = ObjectNames.NicifyVariableName(field.Name);
|
||||||
|
|
||||||
if (field.FieldType == typeof(float))
|
if (field.IsType<float>())
|
||||||
EditorGUI.FloatField(rect, nicifiedName, (float)field.GetValue(target));
|
{
|
||||||
else if (field.FieldType == typeof(int))
|
float temp = EditorGUI.FloatField(rect, nicifiedName, field.GetValue<float>(target));
|
||||||
EditorGUI.IntField(rect, nicifiedName, (int)field.GetValue(target));
|
|
||||||
else if (field.FieldType == typeof(double))
|
if (field.editable)
|
||||||
EditorGUI.DoubleField(rect, nicifiedName, (double)field.GetValue(target));
|
field.SetValue(target, temp);
|
||||||
else if (field.FieldType == typeof(string))
|
}
|
||||||
EditorGUI.TextField(rect, nicifiedName, (string)field.GetValue(target));
|
else if (field.IsType<int>())
|
||||||
else if (typeof(Object).IsAssignableFrom(field.FieldType))
|
{
|
||||||
EditorGUI.ObjectField(rect, nicifiedName, (Object)field.GetValue(target), typeof(Object), true);
|
int temp = EditorGUI.IntField(rect, nicifiedName, field.GetValue<int>(target));
|
||||||
|
|
||||||
|
if (field.editable)
|
||||||
|
field.SetValue(target, temp);
|
||||||
|
}
|
||||||
|
else if (field.IsType<double>())
|
||||||
|
{
|
||||||
|
double temp = EditorGUI.DoubleField(rect, nicifiedName, field.GetValue<double>(target));
|
||||||
|
|
||||||
|
if (field.editable)
|
||||||
|
field.SetValue(target, temp);
|
||||||
|
}
|
||||||
|
else if (field.IsType<string>())
|
||||||
|
{
|
||||||
|
string temp = EditorGUI.TextField(rect, nicifiedName, field.GetValue<string>(target));
|
||||||
|
|
||||||
|
if (field.editable)
|
||||||
|
field.SetValue(target, temp);
|
||||||
|
}
|
||||||
|
else if (field.IsAssignableFrom<Object>())
|
||||||
|
{
|
||||||
|
Object temp = EditorGUI.ObjectField(rect, nicifiedName, field.GetValue<Object>(target), typeof(Object), true);
|
||||||
|
|
||||||
|
if (field.editable)
|
||||||
|
field.SetValue(target, temp);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
EditorGUI.LabelField(rect, ObjectNames.NicifyVariableName(field.Name), "Unsupported type");
|
EditorGUI.LabelField(rect, ObjectNames.NicifyVariableName(field.Name), "Unsupported type");
|
||||||
|
}
|
||||||
|
|
||||||
GUI.enabled = prevEnabled;
|
GUI.enabled = prevEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static FieldInfo[] InternalFetch(Type type, bool useFieldProperty)
|
private static EditableFieldInfo[] InternalFetch(Type type, bool useFieldProperty)
|
||||||
{
|
{
|
||||||
const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
|
const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
|
||||||
|
|
||||||
FieldInfo[] fields = type.GetFields(FLAGS);
|
FieldInfo[] fields = type.GetFields(FLAGS);
|
||||||
var list = new List<FieldInfo>(fields.Length);
|
var list = new List<EditableFieldInfo>(fields.Length);
|
||||||
|
|
||||||
for (var i = 0; i < fields.Length; i++)
|
for (var i = 0; i < fields.Length; i++)
|
||||||
{
|
{
|
||||||
|
|
@ -70,11 +97,48 @@ namespace Module.Inspector.Editor.Utilities
|
||||||
|
|
||||||
if (fi.GetCustomAttribute<NonSerializedAttribute>() == null && fi.GetCustomAttribute<HideInInspector>() == null)
|
if (fi.GetCustomAttribute<NonSerializedAttribute>() == null && fi.GetCustomAttribute<HideInInspector>() == null)
|
||||||
continue;
|
continue;
|
||||||
if (!useFieldProperty || fi.GetCustomAttribute<ShowHiddenFieldAttribute>() != null)
|
|
||||||
list.Add(fi);
|
var att = fi.GetCustomAttribute<ShowHiddenFieldAttribute>();
|
||||||
|
|
||||||
|
if (!useFieldProperty || att != null)
|
||||||
|
list.Add(new EditableFieldInfo(fi, att != null && att.editable));
|
||||||
}
|
}
|
||||||
|
|
||||||
return list.ToArray();
|
return list.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public sealed class EditableFieldInfo
|
||||||
|
{
|
||||||
|
public readonly FieldInfo fieldInfo;
|
||||||
|
public readonly bool editable;
|
||||||
|
|
||||||
|
public string Name => fieldInfo.Name;
|
||||||
|
|
||||||
|
public EditableFieldInfo(FieldInfo fieldInfo, bool editable)
|
||||||
|
{
|
||||||
|
this.fieldInfo = fieldInfo;
|
||||||
|
this.editable = editable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T GetValue<T>(object target)
|
||||||
|
{
|
||||||
|
return (T)fieldInfo.GetValue(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetValue<T>(object target, T value)
|
||||||
|
{
|
||||||
|
fieldInfo.SetValue(target, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsType<T>()
|
||||||
|
{
|
||||||
|
return fieldInfo.FieldType == typeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsAssignableFrom<T>()
|
||||||
|
{
|
||||||
|
return typeof(T).IsAssignableFrom(fieldInfo.FieldType);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
25
Editor/ValueModifiers/AssetsOnlyAttributeDrawer.cs
Normal file
25
Editor/ValueModifiers/AssetsOnlyAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Module.Inspector.Editor
|
||||||
|
{
|
||||||
|
[CustomPropertyDrawer(typeof(AssetsOnlyAttribute))]
|
||||||
|
internal sealed class AssetsOnlyAttributeDrawer : ValueModifierPropertyDrawer
|
||||||
|
{
|
||||||
|
public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property)
|
||||||
|
{
|
||||||
|
if (property.propertyType != SerializedPropertyType.ObjectReference)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Object obj = property.objectReferenceValue;
|
||||||
|
|
||||||
|
if (obj != null && !IsValid(obj))
|
||||||
|
property.objectReferenceValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsValid(Object obj)
|
||||||
|
{
|
||||||
|
return AssetDatabase.Contains(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Editor/ValueModifiers/AssetsOnlyAttributeDrawer.cs.meta
Normal file
3
Editor/ValueModifiers/AssetsOnlyAttributeDrawer.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 84b797e92aa740e4866d71c9afaa6ff2
|
||||||
|
timeCreated: 1660250173
|
||||||
43
Editor/ValueModifiers/AssignAssetIfNullAttributeDrawer.cs
Normal file
43
Editor/ValueModifiers/AssignAssetIfNullAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
using System;
|
||||||
|
using UnityEditor;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace Module.Inspector.Editor
|
||||||
|
{
|
||||||
|
[CustomPropertyDrawer(typeof(AssignAssetIfNullAttribute))]
|
||||||
|
internal sealed class AssignAssetIfNullAttributeDrawer : ValueModifierPropertyDrawer
|
||||||
|
{
|
||||||
|
public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property)
|
||||||
|
{
|
||||||
|
if (property.propertyType != SerializedPropertyType.ObjectReference)
|
||||||
|
return;
|
||||||
|
if (property.objectReferenceValue != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var att = (AssignAssetIfNullAttribute)attribute;
|
||||||
|
Type type = att.useType ? att.type : property.GetValueType();
|
||||||
|
property.objectReferenceValue = AssignAsset(type, att.filter, att.searchFolders);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Object AssignAsset(Type type, string filter, string[] folders)
|
||||||
|
{
|
||||||
|
string[] guids;
|
||||||
|
|
||||||
|
if (folders != null && folders.Length != 0)
|
||||||
|
guids = AssetDatabase.FindAssets($"{type.Name} {filter}", folders);
|
||||||
|
else
|
||||||
|
guids = AssetDatabase.FindAssets($"{type.Name} {filter}");
|
||||||
|
|
||||||
|
for (var i = 0; i < guids.Length; i++)
|
||||||
|
{
|
||||||
|
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
|
||||||
|
Object obj = AssetDatabase.LoadAssetAtPath(path, type);
|
||||||
|
|
||||||
|
if (obj != null)
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 68325a7d22ed40e2aae8e00fad5f05dc
|
||||||
|
timeCreated: 1661599398
|
||||||
|
|
@ -5,8 +5,8 @@ using Object = UnityEngine.Object;
|
||||||
|
|
||||||
namespace Module.Inspector.Editor
|
namespace Module.Inspector.Editor
|
||||||
{
|
{
|
||||||
[CustomPropertyDrawer(typeof(AssignIfNullAttribute))]
|
[CustomPropertyDrawer(typeof(AssignComponentIfNullAttribute))]
|
||||||
internal sealed class AssignIfNullAttributeDrawer : ValueModifierPropertyDrawer
|
internal sealed class AssignComponentIfNullAttributeDrawer : ValueModifierPropertyDrawer
|
||||||
{
|
{
|
||||||
public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property)
|
public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property)
|
||||||
{
|
{
|
||||||
|
|
@ -15,7 +15,7 @@ namespace Module.Inspector.Editor
|
||||||
if (property.objectReferenceValue != null)
|
if (property.objectReferenceValue != null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var att = (AssignIfNullAttribute)attribute;
|
var att = (AssignComponentIfNullAttribute)attribute;
|
||||||
Type type = att.useType ? att.type : property.GetValueType();
|
Type type = att.useType ? att.type : property.GetValueType();
|
||||||
|
|
||||||
if (!typeof(Component).IsAssignableFrom(type))
|
if (!typeof(Component).IsAssignableFrom(type))
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 38c05c2014ac40c0915f6e36df16c7e4
|
||||||
|
timeCreated: 1661600081
|
||||||
|
|
@ -1,3 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: e029b0d7c1384ab2b961e74a2bf23fe0
|
|
||||||
timeCreated: 1638695373
|
|
||||||
25
Editor/ValueModifiers/SceneObjectsOnlyAttributeDrawer.cs
Normal file
25
Editor/ValueModifiers/SceneObjectsOnlyAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Module.Inspector.Editor
|
||||||
|
{
|
||||||
|
[CustomPropertyDrawer(typeof(SceneObjectsOnlyAttribute))]
|
||||||
|
internal sealed class SceneObjectsOnlyAttributeDrawer : ValueModifierPropertyDrawer
|
||||||
|
{
|
||||||
|
public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property)
|
||||||
|
{
|
||||||
|
if (property.propertyType != SerializedPropertyType.ObjectReference)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Object obj = property.objectReferenceValue;
|
||||||
|
|
||||||
|
if (obj != null && !IsValid(obj))
|
||||||
|
property.objectReferenceValue = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsValid(Object obj)
|
||||||
|
{
|
||||||
|
return !AssetDatabase.Contains(obj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 48dbd634fecb45699637d9dfff17f8e9
|
||||||
|
timeCreated: 1660250619
|
||||||
10
README.md
10
README.md
|
|
@ -127,14 +127,20 @@ List of all value attributes:
|
||||||
|
|
||||||
* `ArrayIndex`
|
* `ArrayIndex`
|
||||||
* Clamps value between other fields array size `[0;size[`
|
* Clamps value between other fields array size `[0;size[`
|
||||||
* `AssignIfNull`
|
* `AssetsOnly`
|
||||||
|
* If value is not an asset it will be set to null
|
||||||
|
* `AssignAssetIfNull`
|
||||||
|
* If value is null will assign first asset found using AssetDatabase.FindAssets
|
||||||
|
* `AssignComponentIfNull`
|
||||||
* If value is null will either use field or custom type to get from self or children
|
* If value is null will either use field or custom type to get from self or children
|
||||||
* `LargerThanField`
|
* `LargerThanField`
|
||||||
* If value is greater than other fields value, then set value to other fields value
|
* If value is greater than other fields value, then set value to other fields value
|
||||||
* `MaxValue`
|
* `MaxValue`
|
||||||
* If value is greater than max value, then set value to max value
|
* If value is greater than max value, then set value to max value
|
||||||
* `MinValue`
|
* `MinValue`
|
||||||
* If value is less than min value, then set value to min value
|
* If value is less than min value, then set value to min value
|
||||||
|
* `SceneObjectsOnly`
|
||||||
|
* If value is an asset it will be set to null
|
||||||
* `SmallerThanField`
|
* `SmallerThanField`
|
||||||
* If value is less than other fields value, then set value to other fields value
|
* If value is less than other fields value, then set value to other fields value
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,5 +6,11 @@ namespace Module.Inspector
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||||
public sealed class ShowHiddenFieldAttribute : PropertyAttribute
|
public sealed class ShowHiddenFieldAttribute : PropertyAttribute
|
||||||
{
|
{
|
||||||
|
public readonly bool editable;
|
||||||
|
|
||||||
|
public ShowHiddenFieldAttribute(bool editable = false)
|
||||||
|
{
|
||||||
|
this.editable = editable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
Runtime/ValueModifiers/AssetsOnlyAttribute.cs
Normal file
14
Runtime/ValueModifiers/AssetsOnlyAttribute.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine.Scripting;
|
||||||
|
|
||||||
|
namespace Module.Inspector
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||||
|
public sealed class AssetsOnlyAttribute : ValueModifierPropertyAttribute
|
||||||
|
{
|
||||||
|
[Preserve]
|
||||||
|
public AssetsOnlyAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Runtime/ValueModifiers/AssetsOnlyAttribute.cs.meta
Normal file
3
Runtime/ValueModifiers/AssetsOnlyAttribute.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: dd2c5463415149c39cafdfb013ffd252
|
||||||
|
timeCreated: 1660247975
|
||||||
39
Runtime/ValueModifiers/AssignAssetIfNullAttribute.cs
Normal file
39
Runtime/ValueModifiers/AssignAssetIfNullAttribute.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Module.Inspector
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||||
|
public sealed class AssignAssetIfNullAttribute : ValueModifierPropertyAttribute
|
||||||
|
{
|
||||||
|
public readonly bool useType;
|
||||||
|
public readonly Type type;
|
||||||
|
public readonly string filter;
|
||||||
|
public readonly string[] searchFolders;
|
||||||
|
|
||||||
|
public AssignAssetIfNullAttribute(string[] searchFolders = null)
|
||||||
|
{
|
||||||
|
this.searchFolders = searchFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AssignAssetIfNullAttribute(string filter, string[] searchFolders = null)
|
||||||
|
{
|
||||||
|
this.filter = filter;
|
||||||
|
this.searchFolders = searchFolders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AssignAssetIfNullAttribute(Type type, string[] searchFolders = null)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
this.searchFolders = searchFolders;
|
||||||
|
useType = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AssignAssetIfNullAttribute(Type type, string filter, string[] searchFolders = null)
|
||||||
|
{
|
||||||
|
this.type = type;
|
||||||
|
this.filter = filter;
|
||||||
|
this.searchFolders = searchFolders;
|
||||||
|
useType = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 82c31267a89846069809fd3085f7026e
|
||||||
|
timeCreated: 1661366494
|
||||||
|
|
@ -3,30 +3,19 @@ using System;
|
||||||
namespace Module.Inspector
|
namespace Module.Inspector
|
||||||
{
|
{
|
||||||
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||||
public sealed class AssignIfNullAttribute : ValueModifierPropertyAttribute
|
public sealed class AssignComponentIfNullAttribute : ValueModifierPropertyAttribute
|
||||||
{
|
{
|
||||||
|
public readonly bool includeChildren;
|
||||||
public readonly bool useType;
|
public readonly bool useType;
|
||||||
public readonly Type type;
|
public readonly Type type;
|
||||||
public readonly bool includeChildren;
|
|
||||||
|
|
||||||
public AssignIfNullAttribute()
|
public AssignComponentIfNullAttribute(bool includeChildren = false)
|
||||||
{
|
{
|
||||||
useType = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AssignIfNullAttribute(bool includeChildren)
|
|
||||||
{
|
|
||||||
useType = false;
|
|
||||||
this.includeChildren = includeChildren;
|
this.includeChildren = includeChildren;
|
||||||
|
useType = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AssignIfNullAttribute(Type type)
|
public AssignComponentIfNullAttribute(Type type, bool includeChildren = false)
|
||||||
{
|
|
||||||
this.type = type;
|
|
||||||
useType = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AssignIfNullAttribute(Type type, bool includeChildren)
|
|
||||||
{
|
{
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.includeChildren = includeChildren;
|
this.includeChildren = includeChildren;
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 50df169977e042c4bfb5dcf29b06c86c
|
||||||
|
timeCreated: 1661598908
|
||||||
|
|
@ -1,11 +0,0 @@
|
||||||
fileFormatVersion: 2
|
|
||||||
guid: dfd8ecaea012b084f994832dd519d850
|
|
||||||
MonoImporter:
|
|
||||||
externalObjects: {}
|
|
||||||
serializedVersion: 2
|
|
||||||
defaultReferences: []
|
|
||||||
executionOrder: 0
|
|
||||||
icon: {instanceID: 0}
|
|
||||||
userData:
|
|
||||||
assetBundleName:
|
|
||||||
assetBundleVariant:
|
|
||||||
14
Runtime/ValueModifiers/SceneObjectsOnlyAttribute.cs
Normal file
14
Runtime/ValueModifiers/SceneObjectsOnlyAttribute.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
using UnityEngine.Scripting;
|
||||||
|
|
||||||
|
namespace Module.Inspector
|
||||||
|
{
|
||||||
|
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)]
|
||||||
|
public sealed class SceneObjectsOnlyAttribute : ValueModifierPropertyAttribute
|
||||||
|
{
|
||||||
|
[Preserve]
|
||||||
|
public SceneObjectsOnlyAttribute()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
3
Runtime/ValueModifiers/SceneObjectsOnlyAttribute.cs.meta
Normal file
3
Runtime/ValueModifiers/SceneObjectsOnlyAttribute.cs.meta
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: a5113fd42950401b823cee1be6f3450b
|
||||||
|
timeCreated: 1660250588
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "com.module.inspector",
|
"name": "com.module.inspector",
|
||||||
"version": "1.7.0",
|
"version": "1.8.0",
|
||||||
"displayName": "Module.Inspector",
|
"displayName": "Module.Inspector",
|
||||||
"description": "Custom inspector with various useful property drawers",
|
"description": "Custom inspector with various useful property drawers",
|
||||||
"unity": "2019.2",
|
"unity": "2019.2",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue