diff --git a/Editor.meta b/Editor.meta new file mode 100644 index 0000000..84d52ca --- /dev/null +++ b/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9631ae317a3e9894987ef0394a83e49d +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AbstractMethodDrawer.cs b/Editor/AbstractMethodDrawer.cs new file mode 100644 index 0000000..9f68292 --- /dev/null +++ b/Editor/AbstractMethodDrawer.cs @@ -0,0 +1,72 @@ +using System.Reflection; +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + public abstract class AbstractMethodDrawer + { + public void OnGUI(Rect position, Object target, MethodInfo method) + { + EditorMethodUtility.Result result = EditorMethodUtility.Query(method); + EAccessType accessType = GetAccessType(target, method, result); + + if (accessType == EAccessType.Hidden) + return; + + if (result.decorator != null) + { + var rect = new Rect(position); + rect.height = result.decorator.drawer.GetHeight(result.decorator.attribute); + result.decorator.drawer.Draw(rect, result.decorator.attribute); + + position.height -= rect.height; + position.y += rect.height; + } + + bool prevEnabled = GUI.enabled; + GUI.enabled = accessType == EAccessType.Enabled; + + if (result.draw != null) + { + if (!result.draw.drawer.Draw(position, result.draw.attribute, target, method)) + EditorGUI.LabelField(position, method.Name, result.draw.drawer.GetErrorMessage()); + } + + GUI.enabled = prevEnabled; + } + + public float GetHeight(Object target, MethodInfo method) + { + EditorMethodUtility.Result result = EditorMethodUtility.Query(method); + EAccessType accessType = GetAccessType(target, method, result); + + if (accessType == EAccessType.Hidden) + return 0.0f; + + float height = EditorGUIUtility.singleLineHeight; + + if (result.decorator != null) + height += result.decorator.drawer.GetHeight(result.decorator.attribute); + + return height; + } + + private EAccessType GetAccessType(Object target, MethodInfo method, EditorMethodUtility.Result result) + { + if (result.accessModifiers.Count == 0) + return EAccessType.Enabled; + + EAccessType accessType = 0; + + for (var i = 0; i < result.accessModifiers.Count; i++) + { + EditorMethodUtility.ResultValue value = result.accessModifiers[i]; + accessType = value.drawer.GetAccessType(value.attribute, target, method, accessType); + } + + return accessType; + } + } +} \ No newline at end of file diff --git a/Editor/AbstractMethodDrawer.cs.meta b/Editor/AbstractMethodDrawer.cs.meta new file mode 100644 index 0000000..a75387c --- /dev/null +++ b/Editor/AbstractMethodDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 85c9c674ca2f9684e908299eb744003b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AbstractPropertyDrawer.cs b/Editor/AbstractPropertyDrawer.cs new file mode 100644 index 0000000..3847fc9 --- /dev/null +++ b/Editor/AbstractPropertyDrawer.cs @@ -0,0 +1,63 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + public abstract class AbstractPropertyDrawer : PropertyDrawer + { + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + EditorPropertyUtility.Result result = EditorPropertyUtility.Query(fieldInfo); + EAccessType accessType = GetAccessType(property, result); + + if (accessType == EAccessType.Hidden) + return; + + label.tooltip = result.tooltip; + bool prevEnabled = GUI.enabled; + GUI.enabled = accessType == EAccessType.Enabled; + + if (result.draw != null) + { + if (!result.draw.drawer.Draw(position, result.draw.attribute, property, label, result)) + EditorGUI.LabelField(position, label, result.draw.drawer.GetErrorMessage(property)); + } + else + { + EditorGUI.PropertyField(position, property, label, true); + } + + GUI.enabled = prevEnabled; + + for (var i = 0; i < result.valueModifiers.Count; i++) + { + EditorPropertyUtility.ResultValue value = result.valueModifiers[i]; + value.drawer.Modify(value.attribute, property); + } + } + + public override float GetPropertyHeight(SerializedProperty property, GUIContent label) + { + EditorPropertyUtility.Result result = EditorPropertyUtility.Query(fieldInfo); + EAccessType accessType = GetAccessType(property, result); + return accessType != EAccessType.Hidden ? EditorGUI.GetPropertyHeight(property, label) : 0.0f; + } + + private EAccessType GetAccessType(SerializedProperty property, EditorPropertyUtility.Result result) + { + if (result.accessModifiers.Count == 0) + return EAccessType.Enabled; + + EAccessType accessType = 0; + + for (var i = 0; i < result.accessModifiers.Count; i++) + { + EditorPropertyUtility.ResultValue value = result.accessModifiers[i]; + accessType = value.drawer.GetAccessType(value.attribute, property, accessType); + } + + return accessType; + } + } +} \ No newline at end of file diff --git a/Editor/AbstractPropertyDrawer.cs.meta b/Editor/AbstractPropertyDrawer.cs.meta new file mode 100644 index 0000000..ce954d4 --- /dev/null +++ b/Editor/AbstractPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ebb1fc3d392a82042a858ac883eca766 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifierMethodDrawer.cs b/Editor/AccessModifierMethodDrawer.cs new file mode 100644 index 0000000..b82057b --- /dev/null +++ b/Editor/AccessModifierMethodDrawer.cs @@ -0,0 +1,10 @@ +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + public abstract class AccessModifierMethodDrawer : AbstractMethodDrawer + { + public abstract EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType); + } +} \ No newline at end of file diff --git a/Editor/AccessModifierMethodDrawer.cs.meta b/Editor/AccessModifierMethodDrawer.cs.meta new file mode 100644 index 0000000..5896f81 --- /dev/null +++ b/Editor/AccessModifierMethodDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a50e42f517c92654a87605522f40d195 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifierPropertyDrawer.cs b/Editor/AccessModifierPropertyDrawer.cs new file mode 100644 index 0000000..661fb1e --- /dev/null +++ b/Editor/AccessModifierPropertyDrawer.cs @@ -0,0 +1,9 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + public abstract class AccessModifierPropertyDrawer : AbstractPropertyDrawer + { + public abstract EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType); + } +} \ No newline at end of file diff --git a/Editor/AccessModifierPropertyDrawer.cs.meta b/Editor/AccessModifierPropertyDrawer.cs.meta new file mode 100644 index 0000000..ef5d1ee --- /dev/null +++ b/Editor/AccessModifierPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 09d80e9b13b703243a0ab5a617d37bd9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers.meta b/Editor/AccessModifiers.meta new file mode 100644 index 0000000..7986aa1 --- /dev/null +++ b/Editor/AccessModifiers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 1b4c05f846705b04a90e7915c297d3b7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerDisable.cs b/Editor/AccessModifiers/DrawerDisable.cs new file mode 100644 index 0000000..564d8cb --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisable.cs @@ -0,0 +1,13 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(Disable))] + internal sealed class DrawerDisable : AccessModifierPropertyDrawer + { + public override EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType) + { + return currentAccessType == EAccessType.Enabled ? EAccessType.ReadOnly : currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerDisable.cs.meta b/Editor/AccessModifiers/DrawerDisable.cs.meta new file mode 100644 index 0000000..2c15c21 --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2316fa6e2ad8e9a42bdb9ed80642dc59 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerDisableField.cs b/Editor/AccessModifiers/DrawerDisableField.cs new file mode 100644 index 0000000..d4ec153 --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableField.cs @@ -0,0 +1,18 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(DisableField))] + internal sealed class DrawerDisableField : AccessModifierPropertyDrawer + { + public override EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType) + { + var att = (DisableField)attribute; + + if (currentAccessType == EAccessType.Enabled && property.IsSiblingValue(att.fieldName, att.fieldValue, att.useFieldValue)) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerDisableField.cs.meta b/Editor/AccessModifiers/DrawerDisableField.cs.meta new file mode 100644 index 0000000..751eefd --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9ec3d1bd46217bb4fad7a327db680308 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerDisableFieldInPlayMode.cs b/Editor/AccessModifiers/DrawerDisableFieldInPlayMode.cs new file mode 100644 index 0000000..3f36c5f --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableFieldInPlayMode.cs @@ -0,0 +1,17 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(DisableFieldInPlayMode))] + internal sealed class DrawerDisableFieldInPlayMode : AccessModifierPropertyDrawer + { + public override EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType) + { + if (currentAccessType == EAccessType.Enabled && Application.isPlaying) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerDisableFieldInPlayMode.cs.meta b/Editor/AccessModifiers/DrawerDisableFieldInPlayMode.cs.meta new file mode 100644 index 0000000..a0c9946 --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableFieldInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3ec994dc0b7f864468db321f5835e8cd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerDisableMethod.cs b/Editor/AccessModifiers/DrawerDisableMethod.cs new file mode 100644 index 0000000..74263f6 --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableMethod.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using Module.Inspector.Editor.Utilities; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(DisableMethod))] + internal sealed class DrawerDisableMethod : AccessModifierMethodDrawer + { + public override EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType) + { + var att = (DisableMethod)attribute; + + if (currentAccessType == EAccessType.Enabled && EditorSerializedPropertyUtility.IsValue(target, att.fieldName, att.fieldValue, att.useFieldValue)) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerDisableMethod.cs.meta b/Editor/AccessModifiers/DrawerDisableMethod.cs.meta new file mode 100644 index 0000000..14a2678 --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 07430432f9a75d4438828e69575e934a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerDisableMethodInPlayMode.cs b/Editor/AccessModifiers/DrawerDisableMethodInPlayMode.cs new file mode 100644 index 0000000..0814041 --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableMethodInPlayMode.cs @@ -0,0 +1,17 @@ +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(DisableMethodInPlayMode))] + internal sealed class DrawerDisableMethodInPlayMode : AccessModifierMethodDrawer + { + public override EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType) + { + if (currentAccessType == EAccessType.Enabled && Application.isPlaying) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerDisableMethodInPlayMode.cs.meta b/Editor/AccessModifiers/DrawerDisableMethodInPlayMode.cs.meta new file mode 100644 index 0000000..338c6b0 --- /dev/null +++ b/Editor/AccessModifiers/DrawerDisableMethodInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b8fdd66054fd39f4bb0ce7e8c9adda2c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerEnableField.cs b/Editor/AccessModifiers/DrawerEnableField.cs new file mode 100644 index 0000000..1e94494 --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableField.cs @@ -0,0 +1,18 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(EnableField))] + internal sealed class DrawerEnableField : AccessModifierPropertyDrawer + { + public override EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType) + { + var att = (EnableField)attribute; + + if (currentAccessType == EAccessType.Enabled && !property.IsSiblingValue(att.fieldName, att.fieldValue, att.useFieldValue)) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerEnableField.cs.meta b/Editor/AccessModifiers/DrawerEnableField.cs.meta new file mode 100644 index 0000000..d8c1886 --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9b0a6e090f984d149b527950fe2e7dd5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerEnableFieldInPlayMode.cs b/Editor/AccessModifiers/DrawerEnableFieldInPlayMode.cs new file mode 100644 index 0000000..167cd52 --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableFieldInPlayMode.cs @@ -0,0 +1,17 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(EnableFieldInPlayMode))] + internal sealed class DrawerEnableFieldInPlayMode : AccessModifierPropertyDrawer + { + public override EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType) + { + if (currentAccessType == EAccessType.Enabled && !Application.isPlaying) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerEnableFieldInPlayMode.cs.meta b/Editor/AccessModifiers/DrawerEnableFieldInPlayMode.cs.meta new file mode 100644 index 0000000..1a3287b --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableFieldInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04f4d99527d9e864ab1e2f31c3b1d1c8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerEnableMethod.cs b/Editor/AccessModifiers/DrawerEnableMethod.cs new file mode 100644 index 0000000..41f3cd9 --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableMethod.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using Module.Inspector.Editor.Utilities; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(EnableMethod))] + internal sealed class DrawerEnableMethod : AccessModifierMethodDrawer + { + public override EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType) + { + var att = (EnableMethod)attribute; + + if (currentAccessType == EAccessType.Enabled && !EditorSerializedPropertyUtility.IsValue(target, att.fieldName, att.fieldValue, att.useFieldValue)) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerEnableMethod.cs.meta b/Editor/AccessModifiers/DrawerEnableMethod.cs.meta new file mode 100644 index 0000000..5d561bb --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 84998c5d066c48449be3941bff24c9ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerEnableMethodInPlayMode.cs b/Editor/AccessModifiers/DrawerEnableMethodInPlayMode.cs new file mode 100644 index 0000000..81800e9 --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableMethodInPlayMode.cs @@ -0,0 +1,17 @@ +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(EnableMethodInPlayMode))] + internal sealed class DrawerEnableMethodInPlayMode : AccessModifierMethodDrawer + { + public override EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType) + { + if (currentAccessType == EAccessType.Enabled && !Application.isPlaying) + currentAccessType = EAccessType.ReadOnly; + + return currentAccessType; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerEnableMethodInPlayMode.cs.meta b/Editor/AccessModifiers/DrawerEnableMethodInPlayMode.cs.meta new file mode 100644 index 0000000..3e634be --- /dev/null +++ b/Editor/AccessModifiers/DrawerEnableMethodInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 32d72b7d351e15e4ab0b9575d6c9d5b8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerHideField.cs b/Editor/AccessModifiers/DrawerHideField.cs new file mode 100644 index 0000000..49125d0 --- /dev/null +++ b/Editor/AccessModifiers/DrawerHideField.cs @@ -0,0 +1,22 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(HideField))] + internal sealed class DrawerHideField : AccessModifierPropertyDrawer + { + public override EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType) + { + if (currentAccessType != EAccessType.Hidden && GetHideValue(attribute, property)) + currentAccessType = EAccessType.Hidden; + + return currentAccessType; + } + + private static bool GetHideValue(AccessModifierPropertyAttribute attribute, SerializedProperty sp) + { + var att = (HideField)attribute; + return string.IsNullOrEmpty(att.fieldName) || sp.IsSiblingValue(att.fieldName, att.fieldValue, att.useFieldValue); + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerHideField.cs.meta b/Editor/AccessModifiers/DrawerHideField.cs.meta new file mode 100644 index 0000000..488f024 --- /dev/null +++ b/Editor/AccessModifiers/DrawerHideField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 732135ced1df7c44789c998f46fc6721 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerHideInNormalInspector.cs b/Editor/AccessModifiers/DrawerHideInNormalInspector.cs new file mode 100644 index 0000000..0e49af5 --- /dev/null +++ b/Editor/AccessModifiers/DrawerHideInNormalInspector.cs @@ -0,0 +1,14 @@ +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(HideInNormalInspector))] + internal sealed class DrawerHideInNormalInspector : AccessModifierMethodDrawer + { + public override EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType) + { + return EAccessType.Hidden; + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerHideInNormalInspector.cs.meta b/Editor/AccessModifiers/DrawerHideInNormalInspector.cs.meta new file mode 100644 index 0000000..54f84fb --- /dev/null +++ b/Editor/AccessModifiers/DrawerHideInNormalInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 496445fc2cf9fd240a488bbfb7705445 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerHideMethod.cs b/Editor/AccessModifiers/DrawerHideMethod.cs new file mode 100644 index 0000000..b9407f1 --- /dev/null +++ b/Editor/AccessModifiers/DrawerHideMethod.cs @@ -0,0 +1,24 @@ +using System.Reflection; +using Module.Inspector.Editor.Utilities; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(HideMethod))] + internal sealed class DrawerHideMethod : AccessModifierMethodDrawer + { + public override EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType) + { + if (currentAccessType != EAccessType.Hidden && GetHideValue(attribute, target)) + currentAccessType = EAccessType.Hidden; + + return currentAccessType; + } + + private static bool GetHideValue(AccessModifierMethodAttribute attribute, Object target) + { + var att = (HideMethod)attribute; + return string.IsNullOrEmpty(att.fieldName) || EditorSerializedPropertyUtility.IsValue(target, att.fieldName, att.fieldValue, att.useFieldValue); + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerHideMethod.cs.meta b/Editor/AccessModifiers/DrawerHideMethod.cs.meta new file mode 100644 index 0000000..dbe1629 --- /dev/null +++ b/Editor/AccessModifiers/DrawerHideMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4686038179cf33344a8a6dec3179b932 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerShowField.cs b/Editor/AccessModifiers/DrawerShowField.cs new file mode 100644 index 0000000..6b43e02 --- /dev/null +++ b/Editor/AccessModifiers/DrawerShowField.cs @@ -0,0 +1,22 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(ShowField))] + internal sealed class DrawerShowField : AccessModifierPropertyDrawer + { + public override EAccessType GetAccessType(AccessModifierPropertyAttribute attribute, SerializedProperty property, EAccessType currentAccessType) + { + if (currentAccessType != EAccessType.Hidden && !GetVisibleValue(attribute, property)) + currentAccessType = EAccessType.Hidden; + + return currentAccessType; + } + + private static bool GetVisibleValue(AccessModifierPropertyAttribute attribute, SerializedProperty sp) + { + var att = (ShowField)attribute; + return sp.IsSiblingValue(att.fieldName, att.fieldValue, att.useFieldValue); + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerShowField.cs.meta b/Editor/AccessModifiers/DrawerShowField.cs.meta new file mode 100644 index 0000000..aea2f11 --- /dev/null +++ b/Editor/AccessModifiers/DrawerShowField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7e4fa1a32ce6ef14ca13bf140184ae12 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/AccessModifiers/DrawerShowMethod.cs b/Editor/AccessModifiers/DrawerShowMethod.cs new file mode 100644 index 0000000..a1a799a --- /dev/null +++ b/Editor/AccessModifiers/DrawerShowMethod.cs @@ -0,0 +1,24 @@ +using System.Reflection; +using Module.Inspector.Editor.Utilities; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(ShowMethod))] + internal sealed class DrawerShowMethod : AccessModifierMethodDrawer + { + public override EAccessType GetAccessType(AccessModifierMethodAttribute attribute, Object target, MethodInfo methodInfo, EAccessType currentAccessType) + { + if (currentAccessType != EAccessType.Hidden && !GetVisibleValue(attribute, target)) + currentAccessType = EAccessType.Hidden; + + return currentAccessType; + } + + private static bool GetVisibleValue(AccessModifierMethodAttribute attribute, Object target) + { + var att = (ShowMethod)attribute; + return EditorSerializedPropertyUtility.IsValue(target, att.fieldName, att.fieldValue, att.useFieldValue); + } + } +} \ No newline at end of file diff --git a/Editor/AccessModifiers/DrawerShowMethod.cs.meta b/Editor/AccessModifiers/DrawerShowMethod.cs.meta new file mode 100644 index 0000000..caf757c --- /dev/null +++ b/Editor/AccessModifiers/DrawerShowMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e66db62cd711351498512295d52b893a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/CustomMethodDrawerAttribute.cs b/Editor/CustomMethodDrawerAttribute.cs new file mode 100644 index 0000000..88610bd --- /dev/null +++ b/Editor/CustomMethodDrawerAttribute.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector.Editor +{ + [AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = false)] + internal sealed class CustomMethodDrawer : Attribute + { + internal readonly Type type; + + public CustomMethodDrawer(Type type) + { + this.type = type; + } + } +} \ No newline at end of file diff --git a/Editor/CustomMethodDrawerAttribute.cs.meta b/Editor/CustomMethodDrawerAttribute.cs.meta new file mode 100644 index 0000000..94db181 --- /dev/null +++ b/Editor/CustomMethodDrawerAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 01267e432205df340b4b6f463f28d10e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/DecoratorMethodDrawer.cs b/Editor/DecoratorMethodDrawer.cs new file mode 100644 index 0000000..cbe5672 --- /dev/null +++ b/Editor/DecoratorMethodDrawer.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +namespace Module.Inspector.Editor +{ + public abstract class DecoratorMethodDrawer : AbstractMethodDrawer + { + public abstract bool Draw(Rect position, DecoratorMethodAttribute attribute); + public abstract float GetHeight(DecoratorMethodAttribute attribute); + } +} \ No newline at end of file diff --git a/Editor/DecoratorMethodDrawer.cs.meta b/Editor/DecoratorMethodDrawer.cs.meta new file mode 100644 index 0000000..8879e1e --- /dev/null +++ b/Editor/DecoratorMethodDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3e42594d91afa7a468cefa6e58e45dfa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Decorators.meta b/Editor/Decorators.meta new file mode 100644 index 0000000..982ec67 --- /dev/null +++ b/Editor/Decorators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: df76db5adb2d9db49b4b56e133a41397 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Decorators/DrawerHorizontalLine.cs b/Editor/Decorators/DrawerHorizontalLine.cs new file mode 100644 index 0000000..ba8b535 --- /dev/null +++ b/Editor/Decorators/DrawerHorizontalLine.cs @@ -0,0 +1,40 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(HorizontalLine))] + public sealed class DrawerHorizontalLine : DecoratorDrawer + { + private const float LINE_HEIGHT = 1.0f; + private const float VERTICAL_SPACING = 4.0f; + + public override void OnGUI(Rect position) + { + var att = (HorizontalLine)attribute; + + // Title + if (!string.IsNullOrEmpty(att.title)) + { + var style = new GUIStyle(GUI.skin.label) + { + fontStyle = FontStyle.Bold + }; + + EditorGUI.LabelField(position, att.title, style); + } + + // Line + Color oldColor = GUI.color; + GUI.color = GUI.skin.label.normal.textColor; + var rect = new Rect(position.x, position.yMax - LINE_HEIGHT - VERTICAL_SPACING, position.width, LINE_HEIGHT); + GUI.DrawTexture(rect, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill); + GUI.color = oldColor; + } + + public override float GetHeight() + { + return base.GetHeight() + VERTICAL_SPACING; + } + } +} \ No newline at end of file diff --git a/Editor/Decorators/DrawerHorizontalLine.cs.meta b/Editor/Decorators/DrawerHorizontalLine.cs.meta new file mode 100644 index 0000000..6674be8 --- /dev/null +++ b/Editor/Decorators/DrawerHorizontalLine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f4e57076f58a444468405664e6419b6c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Decorators/DrawerMethodHeader.cs b/Editor/Decorators/DrawerMethodHeader.cs new file mode 100644 index 0000000..2969b4b --- /dev/null +++ b/Editor/Decorators/DrawerMethodHeader.cs @@ -0,0 +1,32 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(MethodHeader))] + public sealed class DrawerMethodHeader : DecoratorMethodDrawer + { + public override bool Draw(Rect position, DecoratorMethodAttribute attribute) + { + var att = (MethodHeader)attribute; + + if (string.IsNullOrEmpty(att.title)) + return false; + + var style = new GUIStyle(GUI.skin.label) + { + fontStyle = FontStyle.Bold, + alignment = TextAnchor.LowerLeft + }; + + EditorGUI.LabelField(position, att.title, style); + return true; + } + + public override float GetHeight(DecoratorMethodAttribute attribute) + { + var att = (MethodHeader)attribute; + return !string.IsNullOrEmpty(att.title) ? EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing : 0.0f; + } + } +} \ No newline at end of file diff --git a/Editor/Decorators/DrawerMethodHeader.cs.meta b/Editor/Decorators/DrawerMethodHeader.cs.meta new file mode 100644 index 0000000..c459318 --- /dev/null +++ b/Editor/Decorators/DrawerMethodHeader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 05076317e0ef8ff409d10caede0335a2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/DrawerMethodDrawer.cs b/Editor/DrawerMethodDrawer.cs new file mode 100644 index 0000000..afbb002 --- /dev/null +++ b/Editor/DrawerMethodDrawer.cs @@ -0,0 +1,11 @@ +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + public abstract class DrawerMethodDrawer : AbstractMethodDrawer + { + public abstract bool Draw(Rect position, DrawerMethodAttribute attribute, Object target, MethodInfo methodInfo); + public abstract string GetErrorMessage(); + } +} \ No newline at end of file diff --git a/Editor/DrawerMethodDrawer.cs.meta b/Editor/DrawerMethodDrawer.cs.meta new file mode 100644 index 0000000..d2e3a51 --- /dev/null +++ b/Editor/DrawerMethodDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 949e32ae16f265c4b84659f66c60b086 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/DrawerPropertyDrawer.cs b/Editor/DrawerPropertyDrawer.cs new file mode 100644 index 0000000..6019c20 --- /dev/null +++ b/Editor/DrawerPropertyDrawer.cs @@ -0,0 +1,12 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + public abstract class DrawerPropertyDrawer : AbstractPropertyDrawer + { + public abstract bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result); + public abstract string GetErrorMessage(SerializedProperty property); + } +} \ No newline at end of file diff --git a/Editor/DrawerPropertyDrawer.cs.meta b/Editor/DrawerPropertyDrawer.cs.meta new file mode 100644 index 0000000..4ccf42f --- /dev/null +++ b/Editor/DrawerPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 798fbdcc1b4452a4985c4f9d7393a5f5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers.meta b/Editor/Drawers.meta new file mode 100644 index 0000000..db71629 --- /dev/null +++ b/Editor/Drawers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d90bced66263817419bf0f3e7d2f3de5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerEnumFlag.cs b/Editor/Drawers/DrawerEnumFlag.cs new file mode 100644 index 0000000..7d36e61 --- /dev/null +++ b/Editor/Drawers/DrawerEnumFlag.cs @@ -0,0 +1,33 @@ +using System; +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(EnumFlag))] + internal sealed class DrawerEnumFlag : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.Enum) + return false; + + Type type = property.GetValueType(); + + EditorGUI.BeginProperty(position, label, property); + { + var e = (Enum)Enum.ToObject(type, property.intValue); + e = EditorGUI.EnumFlagsField(position, label, e); + property.intValue = Convert.ToInt32(e); + } + EditorGUI.EndProperty(); + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports enum"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerEnumFlag.cs.meta b/Editor/Drawers/DrawerEnumFlag.cs.meta new file mode 100644 index 0000000..a7b2f6b --- /dev/null +++ b/Editor/Drawers/DrawerEnumFlag.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 87df0640e8498c44fb2dde2702ef30fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerFilePath.cs b/Editor/Drawers/DrawerFilePath.cs new file mode 100644 index 0000000..b677624 --- /dev/null +++ b/Editor/Drawers/DrawerFilePath.cs @@ -0,0 +1,50 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(FilePath))] + internal sealed class DrawerFilePath : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + var att = (FilePath)attribute; + + EditorGUI.BeginProperty(position, label, property); + { + const float WIDTH = 80; + + var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); + var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); + + EditorGUI.PropertyField(rect0, property, label); + + if (GUI.Button(rect1, "Find")) + { + string path = EditorUtility.OpenFilePanel("File", "Assets/", att.extension); + + if (!string.IsNullOrEmpty(path)) + { + if (!att.useAbsolute && path.StartsWith(Application.dataPath)) + path = path.Remove(0, Application.dataPath.Length - 6); + + property.stringValue = path; + property.serializedObject.ApplyModifiedProperties(); + } + } + } + EditorGUI.EndProperty(); + return true; + } + + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports strings"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerFilePath.cs.meta b/Editor/Drawers/DrawerFilePath.cs.meta new file mode 100644 index 0000000..8541514 --- /dev/null +++ b/Editor/Drawers/DrawerFilePath.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bc4ff235b2ee1fa409b5d2e2de824159 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerFolderPath.cs b/Editor/Drawers/DrawerFolderPath.cs new file mode 100644 index 0000000..5b84d32 --- /dev/null +++ b/Editor/Drawers/DrawerFolderPath.cs @@ -0,0 +1,49 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(FolderPath))] + internal sealed class DrawerFolderPath : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + var att = (FolderPath)attribute; + + EditorGUI.BeginProperty(position, label, property); + { + const float WIDTH = 80; + + var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); + var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); + + EditorGUI.PropertyField(rect0, property, label); + + if (GUI.Button(rect1, "Find")) + { + string path = EditorUtility.OpenFolderPanel("Folder", "Assets/", string.Empty); + + if (!string.IsNullOrEmpty(path)) + { + if (!att.useAbsolute && path.StartsWith(Application.dataPath)) + path = path.Remove(0, Application.dataPath.Length - 6); + + property.stringValue = path; + property.serializedObject.ApplyModifiedProperties(); + } + } + } + EditorGUI.EndProperty(); + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports strings"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerFolderPath.cs.meta b/Editor/Drawers/DrawerFolderPath.cs.meta new file mode 100644 index 0000000..77124ab --- /dev/null +++ b/Editor/Drawers/DrawerFolderPath.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d7135fc5f0bd8a54cb9378694247551d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerIntToEnum.cs b/Editor/Drawers/DrawerIntToEnum.cs new file mode 100644 index 0000000..24ddcb0 --- /dev/null +++ b/Editor/Drawers/DrawerIntToEnum.cs @@ -0,0 +1,64 @@ +using System; +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(IntToEnum))] + internal sealed class DrawerIntToEnum : DrawerPropertyDrawer + { + private GUIContent[] names; + private int[] values; + + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.Integer) + return false; + + var att = (IntToEnum)attribute; + FetchLayerNames(att); + + EditorGUI.BeginChangeCheck(); + EditorGUI.BeginProperty(position, label, property); + { + int index = Array.IndexOf(values, property.intValue); + int newIndex = EditorGUI.Popup(position, label, index, names); + + if (newIndex != -1 && index != newIndex) + property.intValue = values[newIndex]; + } + EditorGUI.EndProperty(); + bool changed = EditorGUI.EndChangeCheck(); + + if (changed) + property.serializedObject.ApplyModifiedProperties(); + + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports integers"; + } + + private void FetchLayerNames(IntToEnum attribute) + { + if (names != null) + return; + + Type type = attribute.GetValidType(); + string[] arrNames = Enum.GetNames(type); + Array arrValues = Enum.GetValues(type); + + names = new GUIContent[arrNames.Length]; + values = new int[arrValues.Length]; + + for (var i = 0; i < names.Length; i++) + { + names[i] = new GUIContent(arrNames[i]); + values[i] = Convert.ToInt32(arrValues.GetValue(i)); + } + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerIntToEnum.cs.meta b/Editor/Drawers/DrawerIntToEnum.cs.meta new file mode 100644 index 0000000..5bc1bc8 --- /dev/null +++ b/Editor/Drawers/DrawerIntToEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3b20e9cb8fa0894f9a41a0fff58cb8b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerIntToLayer.cs b/Editor/Drawers/DrawerIntToLayer.cs new file mode 100644 index 0000000..4b57e27 --- /dev/null +++ b/Editor/Drawers/DrawerIntToLayer.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(IntToLayer))] + internal sealed class DrawerIntToLayer : DrawerPropertyDrawer + { + private static GUIContent[] NAMES; + private static int[] INDICES; + + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.Integer) + return false; + + FetchLayerNames(); + + EditorGUI.BeginChangeCheck(); + EditorGUI.BeginProperty(position, label, property); + { + int index = Array.IndexOf(INDICES, property.intValue); + int newIndex = EditorGUI.Popup(position, label, index, NAMES); + + if (newIndex != -1 && index != newIndex) + property.intValue = INDICES[newIndex]; + } + EditorGUI.EndProperty(); + bool changed = EditorGUI.EndChangeCheck(); + + if (changed) + property.serializedObject.ApplyModifiedProperties(); + + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports integers"; + } + + private static void FetchLayerNames() + { + if (NAMES != null) + return; + + var listNames = new List(32); + var listIndices = new List(32); + + for (var i = 0; i < 32; i++) + { + string name = LayerMask.LayerToName(i); + + if (string.IsNullOrEmpty(name)) + continue; + + listNames.Add(new GUIContent(name)); + listIndices.Add(i); + } + + NAMES = listNames.ToArray(); + INDICES = listIndices.ToArray(); + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerIntToLayer.cs.meta b/Editor/Drawers/DrawerIntToLayer.cs.meta new file mode 100644 index 0000000..afea749 --- /dev/null +++ b/Editor/Drawers/DrawerIntToLayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d256c1ba203028245a0d8bffc2f1558b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerMethodButton.cs b/Editor/Drawers/DrawerMethodButton.cs new file mode 100644 index 0000000..45aca67 --- /dev/null +++ b/Editor/Drawers/DrawerMethodButton.cs @@ -0,0 +1,25 @@ +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomMethodDrawer(typeof(MethodButton))] + internal sealed class DrawerMethodButton : DrawerMethodDrawer + { + public override bool Draw(Rect position, DrawerMethodAttribute attribute, Object target, MethodInfo methodInfo) + { + var att = (MethodButton)attribute; + string name = string.IsNullOrEmpty(att.name) ? methodInfo.Name : att.name; + + if (GUI.Button(position, name)) + methodInfo.Invoke(methodInfo.IsStatic ? null : target, null); + + return true; + } + + public override string GetErrorMessage() + { + return string.Empty; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerMethodButton.cs.meta b/Editor/Drawers/DrawerMethodButton.cs.meta new file mode 100644 index 0000000..0aaec85 --- /dev/null +++ b/Editor/Drawers/DrawerMethodButton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ed6fa023ff3f3434aadacc9aa3594459 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerNaming.cs b/Editor/Drawers/DrawerNaming.cs new file mode 100644 index 0000000..6b0c7c2 --- /dev/null +++ b/Editor/Drawers/DrawerNaming.cs @@ -0,0 +1,42 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(Naming))] + internal sealed class DrawerNaming : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + var att = (Naming)attribute; + + EditorGUI.BeginProperty(position, label, property); + { + const float WIDTH = 80; + + var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); + var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); + + EditorGUI.PropertyField(rect0, property); + + if (GUI.Button(rect1, "Go")) + { + string str = EditorNamingUtility.ConvertTo(att.type, property.stringValue); + property.stringValue = str; + property.serializedObject.ApplyModifiedProperties(); + } + } + EditorGUI.EndProperty(); + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports strings"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerNaming.cs.meta b/Editor/Drawers/DrawerNaming.cs.meta new file mode 100644 index 0000000..065fc65 --- /dev/null +++ b/Editor/Drawers/DrawerNaming.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8cecc94b8bbefe64d824ba528b4e99a1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerPercentage.cs b/Editor/Drawers/DrawerPercentage.cs new file mode 100644 index 0000000..b9121e4 --- /dev/null +++ b/Editor/Drawers/DrawerPercentage.cs @@ -0,0 +1,42 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(Percentage))] + internal sealed class DrawerPercentage : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.Float) + return false; + + EditorGUI.BeginChangeCheck(); + EditorGUI.BeginProperty(position, label, property); + { + float v = property.floatValue * 100.0f; + string str = EditorGUI.TextField(position, label, v.ToString("0.0") + "%"); + str = str.Replace('%', ' ').Trim(); + + if (float.TryParse(str, out float temp)) + v = temp; + + v *= 0.01f; + property.floatValue = v; + } + EditorGUI.EndProperty(); + bool changed = EditorGUI.EndChangeCheck(); + + if (changed) + property.serializedObject.ApplyModifiedProperties(); + + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports float"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerPercentage.cs.meta b/Editor/Drawers/DrawerPercentage.cs.meta new file mode 100644 index 0000000..7ba5934 --- /dev/null +++ b/Editor/Drawers/DrawerPercentage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5fccdfb1ef2fe074aa547033c1433c06 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerPopupFromConst.cs b/Editor/Drawers/DrawerPopupFromConst.cs new file mode 100644 index 0000000..d282a25 --- /dev/null +++ b/Editor/Drawers/DrawerPopupFromConst.cs @@ -0,0 +1,72 @@ +using System; +using System.Linq; +using System.Reflection; +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(PopupFromConst))] + internal sealed class DrawerPopupFromConst : DrawerPropertyDrawer + { + private GUIContent[] names; + private string[] values; + + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + var att = (PopupFromConst)attribute; + FetchConstArray(att); + + EditorGUI.BeginChangeCheck(); + EditorGUI.BeginProperty(position, label, property); + { + int index = Array.IndexOf(values, property.stringValue); + int newIndex = EditorGUI.Popup(position, label, index, names); + + if (newIndex != -1 && index != newIndex) + property.stringValue = values[newIndex]; + } + EditorGUI.EndProperty(); + bool changed = EditorGUI.EndChangeCheck(); + + if (changed) + property.serializedObject.ApplyModifiedProperties(); + + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports integers"; + } + + private void FetchConstArray(PopupFromConst attribute) + { + if (names != null) + return; + + FieldInfo[] fields = attribute.type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) + .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(string)) + .ToArray(); + + names = new GUIContent[fields.Length + 1]; + values = new string[fields.Length + 1]; + + names[0] = new GUIContent("-- Empty --"); + values[0] = string.Empty; + + for (var i = 0; i < fields.Length; i++) + { + FieldInfo fi = fields[i]; + var value = (string)fi.GetValue(null); + + names[i + 1] = new GUIContent(value); + values[i + 1] = value; + } + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerPopupFromConst.cs.meta b/Editor/Drawers/DrawerPopupFromConst.cs.meta new file mode 100644 index 0000000..b1283d8 --- /dev/null +++ b/Editor/Drawers/DrawerPopupFromConst.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8a5a9feab54affb45bde1a4eda91d439 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerQuaternionToEuler.cs b/Editor/Drawers/DrawerQuaternionToEuler.cs new file mode 100644 index 0000000..4067080 --- /dev/null +++ b/Editor/Drawers/DrawerQuaternionToEuler.cs @@ -0,0 +1,36 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(QuaternionToEuler))] + internal sealed class DrawerQuaternionToEuler : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.Quaternion) + return false; + + EditorGUI.BeginChangeCheck(); + EditorGUI.BeginProperty(position, label, property); + { + Vector3 euler = property.quaternionValue.eulerAngles; + Vector3 temp = EditorGUI.Vector3Field(position, label, euler); + property.quaternionValue = Quaternion.Euler(temp); + } + EditorGUI.EndProperty(); + bool changed = EditorGUI.EndChangeCheck(); + + if (changed) + property.serializedObject.ApplyModifiedProperties(); + + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports quaternions"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerQuaternionToEuler.cs.meta b/Editor/Drawers/DrawerQuaternionToEuler.cs.meta new file mode 100644 index 0000000..a801b65 --- /dev/null +++ b/Editor/Drawers/DrawerQuaternionToEuler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8954c2ee521537a49a53bf4de92575e7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerSceneDropdown.cs b/Editor/Drawers/DrawerSceneDropdown.cs new file mode 100644 index 0000000..7aab226 --- /dev/null +++ b/Editor/Drawers/DrawerSceneDropdown.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(SceneDropdown))] + internal sealed class DrawerSceneDropdown : DrawerPropertyDrawer + { + private static GUIContent[] NAMES; + private static string[] PATHS; + + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + FetchScenes(); + + EditorGUI.BeginChangeCheck(); + EditorGUI.BeginProperty(position, label, property); + { + int index = Array.IndexOf(PATHS, property.stringValue); + int newIndex = EditorGUI.Popup(position, label, index, NAMES); + + if (newIndex != -1 && index != newIndex) + property.stringValue = PATHS[newIndex]; + } + EditorGUI.EndProperty(); + bool changed = EditorGUI.EndChangeCheck(); + + if (changed) + property.serializedObject.ApplyModifiedProperties(); + + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports strings"; + } + + private static string ToSceneName(string path) + { + return !string.IsNullOrEmpty(path) ? path.Substring(7, path.Length - 13).Replace('/', '\\') : string.Empty; + } + + private static void FetchScenes() + { + if (NAMES != null) + return; + + EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes; + var listNames = new List(scenes.Length); + var listPaths = new List(scenes.Length); + + for (var i = 0; i < scenes.Length; i++) + { + string path = scenes[i].path; + + if (string.IsNullOrEmpty(path)) + continue; + + listNames.Add(new GUIContent(ToSceneName(path))); + listPaths.Add(path); + } + + NAMES = listNames.ToArray(); + PATHS = listPaths.ToArray(); + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerSceneDropdown.cs.meta b/Editor/Drawers/DrawerSceneDropdown.cs.meta new file mode 100644 index 0000000..2ef15b1 --- /dev/null +++ b/Editor/Drawers/DrawerSceneDropdown.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dff7a960f4e593145a913cd65ed37da1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerSlider.cs b/Editor/Drawers/DrawerSlider.cs new file mode 100644 index 0000000..8f2c6e4 --- /dev/null +++ b/Editor/Drawers/DrawerSlider.cs @@ -0,0 +1,134 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(Slider))] + internal sealed class DrawerSlider : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + var min = result.GetValueModifier(); + var max = result.GetValueModifier(); + + if (min == null || max == null) + return false; + + switch (property.propertyType) + { + case SerializedPropertyType.Integer: + case SerializedPropertyType.Float: + DrawRange(position, property, label, min, max); + break; + case SerializedPropertyType.Vector2: + case SerializedPropertyType.Vector2Int: + DrawerMinMax(position, property, label, min, max); + break; + default: + return false; + } + + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + switch (property.propertyType) + { + case SerializedPropertyType.Integer: + case SerializedPropertyType.Float: + case SerializedPropertyType.Vector2: + case SerializedPropertyType.Vector2Int: + return "Requires MinValue and MaxValue"; + } + + return "Only supports integer, float, vector2 and vector2int"; + } + + private void DrawRange(Rect position, SerializedProperty property, GUIContent label, MinValue minValue, MaxValue maxValue) + { + int indentLevel = EditorGUI.indentLevel; + float indentSpacing = indentLevel * 15.0f; + EditorGUI.indentLevel = 0; + + EditorGUI.BeginProperty(position, label, property); + { + float xMin = position.x + indentSpacing; + var r0 = new Rect(xMin, position.y, EditorGUIUtility.labelWidth - indentSpacing + 2.0f, position.height); + var r1 = new Rect(r0.xMax, r0.y, position.width - r0.width - indentSpacing, r0.height); + + EditorGUI.LabelField(r0, label); + + switch (property.propertyType) + { + case SerializedPropertyType.Integer: + property.intValue = EditorGUI.IntSlider(r1, property.intValue, minValue.intValue, maxValue.intValue); + break; + case SerializedPropertyType.Float: + property.floatValue = EditorGUI.Slider(r1, property.floatValue, minValue.floatValue, maxValue.floatValue); + break; + } + } + EditorGUI.EndProperty(); + EditorGUI.indentLevel = indentLevel; + } + + private void DrawerMinMax(Rect position, SerializedProperty property, GUIContent label, MinValue min, MaxValue max) + { + const float FLOAT_WIDTH = 50.0f; + const float FLOAT_SPACING = 8.0f; + + int indentLevel = EditorGUI.indentLevel; + float indentSpacing = indentLevel * 15.0f; + EditorGUI.indentLevel = 0; + + EditorGUI.BeginProperty(position, label, property); + { + float xMin = position.x + indentSpacing; + float width = position.width - indentSpacing; + + var r0 = new Rect(xMin, position.y, EditorGUIUtility.labelWidth - indentSpacing + 2.0f, position.height); + var r1 = new Rect(r0.xMax, r0.y, FLOAT_WIDTH, r0.height); + var r2 = new Rect(r1.xMax + FLOAT_SPACING, r1.y, width - r0.width - (FLOAT_WIDTH + FLOAT_SPACING) * 2, r1.height); + var r3 = new Rect(r2.xMax + FLOAT_SPACING, r2.y, FLOAT_WIDTH, r2.height); + + EditorGUI.LabelField(r0, label); + + switch (property.propertyType) + { + case SerializedPropertyType.Vector2: + Vector2 v = property.vector2Value; + float minValue = v.x; + float maxValue = v.y; + + minValue = EditorGUI.FloatField(r1, minValue); + maxValue = EditorGUI.FloatField(r3, maxValue); + EditorGUI.MinMaxSlider(r2, ref minValue, ref maxValue, min.floatValue, max.floatValue); + + v.x = minValue; + v.y = maxValue; + + property.vector2Value = v; + break; + case SerializedPropertyType.Vector2Int: + Vector2Int v2Int = property.vector2IntValue; + float minIntValue = v2Int.x; + float maxIntValue = v2Int.y; + + minIntValue = EditorGUI.IntField(r1, Mathf.RoundToInt(minIntValue)); + maxIntValue = EditorGUI.IntField(r3, Mathf.RoundToInt(maxIntValue)); + EditorGUI.MinMaxSlider(r2, ref minIntValue, ref maxIntValue, min.floatValue, max.floatValue); + + v2Int.x = Mathf.RoundToInt(minIntValue); + v2Int.y = Mathf.RoundToInt(maxIntValue); + + property.vector2IntValue = v2Int; + break; + } + } + EditorGUI.EndProperty(); + EditorGUI.indentLevel = indentLevel; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerSlider.cs.meta b/Editor/Drawers/DrawerSlider.cs.meta new file mode 100644 index 0000000..f40dc77 --- /dev/null +++ b/Editor/Drawers/DrawerSlider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 485f79e819f053d41b57536ca476ec1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerStringToField.cs b/Editor/Drawers/DrawerStringToField.cs new file mode 100644 index 0000000..af8a896 --- /dev/null +++ b/Editor/Drawers/DrawerStringToField.cs @@ -0,0 +1,38 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(StringToField))] + internal sealed class DrawerStringToField : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + var att = (StringToField)attribute; + + EditorGUI.BeginProperty(position, label, property); + { + const float WIDTH = 80; + + var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); + var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); + + EditorGUI.PropertyField(rect0, property, label); + + if (GUI.Button(rect1, "Find")) + EditorWindowStringToField.Open(att.type, property); + } + EditorGUI.EndProperty(); + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports strings"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerStringToField.cs.meta b/Editor/Drawers/DrawerStringToField.cs.meta new file mode 100644 index 0000000..4869501 --- /dev/null +++ b/Editor/Drawers/DrawerStringToField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fef0de5c591508a43ad30e46920f7e08 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerStringToType.cs b/Editor/Drawers/DrawerStringToType.cs new file mode 100644 index 0000000..259384f --- /dev/null +++ b/Editor/Drawers/DrawerStringToType.cs @@ -0,0 +1,39 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(StringToType))] + internal sealed class DrawerStringToType : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + var att = (StringToType)attribute; + + EditorGUI.BeginProperty(position, label, property); + { + const float WIDTH = 80; + + var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); + var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height); + + EditorGUI.PropertyField(rect0, property, label); + + if (GUI.Button(rect1, "Find")) + EditorWindowStringToType.Open(att.assignableFrom, property); + + } + EditorGUI.EndProperty(); + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports strings"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerStringToType.cs.meta b/Editor/Drawers/DrawerStringToType.cs.meta new file mode 100644 index 0000000..3864b27 --- /dev/null +++ b/Editor/Drawers/DrawerStringToType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5bd5ab3cdc645674d84151133c5b5b78 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Drawers/DrawerUrlGoTo.cs b/Editor/Drawers/DrawerUrlGoTo.cs new file mode 100644 index 0000000..c9fc856 --- /dev/null +++ b/Editor/Drawers/DrawerUrlGoTo.cs @@ -0,0 +1,36 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(UrlGoTo))] + internal sealed class DrawerUrlGoTo : DrawerPropertyDrawer + { + public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result) + { + if (property.propertyType != SerializedPropertyType.String) + return false; + + EditorGUI.BeginProperty(position, label, property); + { + const float WIDTH = 80; + + var r0 = new Rect(position.x, position.y, position.width - WIDTH, position.height); + var r1 = new Rect(r0.xMax, r0.y, WIDTH, r0.height); + + EditorGUI.PropertyField(r0, property, label); + + if (GUI.Button(r1, "Go")) + Application.OpenURL(property.stringValue); + } + EditorGUI.EndProperty(); + return true; + } + + public override string GetErrorMessage(SerializedProperty property) + { + return "Only supports strings"; + } + } +} \ No newline at end of file diff --git a/Editor/Drawers/DrawerUrlGoTo.cs.meta b/Editor/Drawers/DrawerUrlGoTo.cs.meta new file mode 100644 index 0000000..271594e --- /dev/null +++ b/Editor/Drawers/DrawerUrlGoTo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c78fde2b0fd08fa42ae7a1c8ee72a0e5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Enums.meta b/Editor/Enums.meta new file mode 100644 index 0000000..82f32a4 --- /dev/null +++ b/Editor/Enums.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ceee61977f5a0e74abc8a7387abf9440 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Enums/EAccessType.cs b/Editor/Enums/EAccessType.cs new file mode 100644 index 0000000..2e38195 --- /dev/null +++ b/Editor/Enums/EAccessType.cs @@ -0,0 +1,9 @@ +namespace Module.Inspector.Editor +{ + public enum EAccessType : byte + { + Enabled, + Hidden, + ReadOnly, + } +} \ No newline at end of file diff --git a/Editor/Enums/EAccessType.cs.meta b/Editor/Enums/EAccessType.cs.meta new file mode 100644 index 0000000..b02c3c3 --- /dev/null +++ b/Editor/Enums/EAccessType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a1b0d189dd82df440bf3328e0086c0c5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Extensions.meta b/Editor/Extensions.meta new file mode 100644 index 0000000..9ff1ac7 --- /dev/null +++ b/Editor/Extensions.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5e03154e5871d7140ad3a7193d223d81 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Extensions/SerializedPropertyExtension.cs b/Editor/Extensions/SerializedPropertyExtension.cs new file mode 100644 index 0000000..c0651a0 --- /dev/null +++ b/Editor/Extensions/SerializedPropertyExtension.cs @@ -0,0 +1,430 @@ +using System; +using System.Reflection; +using System.Runtime.CompilerServices; +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace Module.Inspector.Editor +{ + public static class SerializedPropertyExtension + { + public enum ECompareType : byte { False, True, Unknown }; + + public static SerializedProperty GetParent(this SerializedProperty sp) + { + string propertyPath = GetRootPath(sp.propertyPath); + return !propertyPath.Equals(sp.propertyPath) ? sp.serializedObject.FindProperty(propertyPath) : null; + } + + public static SerializedProperty GetSibling(this SerializedProperty sp, string fieldName) + { + string propertyPath = GetRootPath(sp.propertyPath); + + if (string.IsNullOrEmpty(propertyPath)) + propertyPath = fieldName; + else + propertyPath += "." + fieldName; + + return sp.serializedObject.FindProperty(propertyPath); + } + + public static SerializedProperty GetRelativeProperty(this SerializedProperty sp, string relativePath) + { + SerializedProperty rp = sp; + string[] split = relativePath.Split('/'); + + for (var i = 0; i < split.Length; i++) + { + rp = split[i].Equals("PARENT") ? GetParent(rp) : GetSibling(rp, split[i]); + + if (rp == null) + break; + } + + return rp; + } + + public static bool IsSiblingValue(this SerializedProperty sp, string siblingFieldName, object siblingFieldValue, bool useFieldValue) + { + if (string.IsNullOrEmpty(siblingFieldName)) + return false; + + SerializedProperty spSibling = sp.GetRelativeProperty(siblingFieldName); + return EditorSerializedPropertyUtility.IsValue(spSibling, siblingFieldValue, useFieldValue); + } + + public static ECompareType IsGreaterOrEqualToSiblingValue(this SerializedProperty sp, string siblingFieldName) + { + if (string.IsNullOrEmpty(siblingFieldName)) + return ECompareType.Unknown; + + SerializedProperty spSibling = sp.GetRelativeProperty(siblingFieldName); + + if (spSibling == null) + return ECompareType.Unknown; + if (spSibling.propertyType != sp.propertyType) + return ECompareType.Unknown; + + if (sp.propertyType == SerializedPropertyType.Integer) + return sp.IsGreaterOrEqualToSiblingValue(siblingFieldName, sp.intValue); + if (sp.propertyType == SerializedPropertyType.Float) + return sp.IsGreaterOrEqualToSiblingValue(siblingFieldName, sp.floatValue); + if (sp.propertyType == SerializedPropertyType.Enum) + return sp.IsGreaterOrEqualToSiblingValue(siblingFieldName, sp.intValue); + + return ECompareType.Unknown; + } + + public static ECompareType IsGreaterOrEqualToSiblingValue(this SerializedProperty sp, string siblingFieldName, object siblingFieldValue) + { + if (string.IsNullOrEmpty(siblingFieldName)) + return ECompareType.Unknown; + + SerializedProperty spSibling = sp.GetRelativeProperty(siblingFieldName); + + if (spSibling == null) + return ECompareType.Unknown; + + if (spSibling.propertyType == SerializedPropertyType.Integer && siblingFieldValue is int i) + return spSibling.intValue <= i ? ECompareType.True : ECompareType.False; + if (spSibling.propertyType == SerializedPropertyType.Float && siblingFieldValue is float f) + return spSibling.floatValue <= f ? ECompareType.True : ECompareType.False; + if (spSibling.propertyType == SerializedPropertyType.Enum && siblingFieldValue is int e) + return spSibling.intValue <= e ? ECompareType.True : ECompareType.False; + + return ECompareType.Unknown; + } + + public static ECompareType IsSmallerOrEqualToSiblingValue(this SerializedProperty sp, string siblingFieldName) + { + if (string.IsNullOrEmpty(siblingFieldName)) + return ECompareType.Unknown; + + SerializedProperty spSibling = sp.GetRelativeProperty(siblingFieldName); + + if (spSibling == null) + return ECompareType.Unknown; + if (spSibling.propertyType != sp.propertyType) + return ECompareType.Unknown; + + if (sp.propertyType == SerializedPropertyType.Integer) + return sp.IsSmallerOrEqualToSiblingValue(siblingFieldName, sp.intValue); + if (sp.propertyType == SerializedPropertyType.Float) + return sp.IsSmallerOrEqualToSiblingValue(siblingFieldName, sp.floatValue); + if (sp.propertyType == SerializedPropertyType.Enum) + return sp.IsSmallerOrEqualToSiblingValue(siblingFieldName, sp.intValue); + + return ECompareType.Unknown; + } + + public static ECompareType IsSmallerOrEqualToSiblingValue(this SerializedProperty sp, string siblingFieldName, object siblingFieldValue) + { + if (string.IsNullOrEmpty(siblingFieldName)) + return ECompareType.Unknown; + + SerializedProperty spSibling = sp.GetRelativeProperty(siblingFieldName); + + if (spSibling == null) + return ECompareType.Unknown; + + if (spSibling.propertyType == SerializedPropertyType.Integer && siblingFieldValue is int i) + return spSibling.intValue >= i ? ECompareType.True : ECompareType.False; + if (spSibling.propertyType == SerializedPropertyType.Float && siblingFieldValue is float f) + return spSibling.floatValue >= f ? ECompareType.True : ECompareType.False; + if (spSibling.propertyType == SerializedPropertyType.Enum && siblingFieldValue is int e) + return spSibling.intValue >= e ? ECompareType.True : ECompareType.False; + + return ECompareType.Unknown; + } + + public static void SetValueTo(this SerializedProperty sp, SerializedProperty other) + { + if (sp.propertyType != other.propertyType) + return; + + switch (sp.propertyType) + { + case SerializedPropertyType.LayerMask: + case SerializedPropertyType.Integer: + case SerializedPropertyType.Enum: + sp.intValue = other.intValue; + break; + case SerializedPropertyType.Boolean: + sp.boolValue = other.boolValue; + break; + case SerializedPropertyType.Float: + sp.floatValue = other.floatValue; + break; + case SerializedPropertyType.String: + sp.stringValue = other.stringValue; + break; + case SerializedPropertyType.Color: + sp.colorValue = other.colorValue; + break; + case SerializedPropertyType.ObjectReference: + sp.objectReferenceValue = other.objectReferenceValue; + break; + case SerializedPropertyType.Vector2: + sp.vector2Value = other.vector2Value; + break; + case SerializedPropertyType.Vector3: + sp.vector3Value = other.vector3Value; + break; + case SerializedPropertyType.Vector4: + sp.vector4Value = other.vector4Value; + break; + case SerializedPropertyType.Rect: + sp.rectValue = other.rectValue; + break; + case SerializedPropertyType.AnimationCurve: + sp.animationCurveValue = other.animationCurveValue; + break; + case SerializedPropertyType.Bounds: + sp.boundsValue = other.boundsValue; + break; + case SerializedPropertyType.Quaternion: + sp.quaternionValue = other.quaternionValue; + break; + case SerializedPropertyType.Vector2Int: + sp.vector2IntValue = other.vector2IntValue; + break; + case SerializedPropertyType.Vector3Int: + sp.vector3IntValue = other.vector3IntValue; + break; + case SerializedPropertyType.RectInt: + sp.rectIntValue = other.rectIntValue; + break; + case SerializedPropertyType.BoundsInt: + sp.boundsIntValue = other.boundsIntValue; + break; + } + } + + public static bool TrySetValueTo(this SerializedProperty sp, object value, bool allowDuplicate) + { + if (sp.isArray && sp.propertyType != SerializedPropertyType.String) + { + if (!allowDuplicate && sp.Contains(value)) + return true; + + Type type = value.GetType(); + + if (!type.IsArray) + { + sp.InsertArrayElementAtIndex(sp.arraySize); + sp = sp.GetArrayElementAtIndex(sp.arraySize - 1); + } + } + + switch (sp.propertyType) + { + case SerializedPropertyType.LayerMask: + case SerializedPropertyType.Integer: + case SerializedPropertyType.Enum: + if (!(value is int i)) + return false; + + sp.intValue = i; + return true; + case SerializedPropertyType.Boolean: + if (!(value is bool b)) + return false; + + sp.boolValue = b; + return true; + case SerializedPropertyType.Float: + if (!(value is float f)) + return false; + + sp.floatValue = f; + return true; + case SerializedPropertyType.String: + if (!(value is string str)) + return false; + + sp.stringValue = str; + return true; + case SerializedPropertyType.Color: + if (!(value is Color c)) + return false; + + sp.colorValue = c; + return true; + case SerializedPropertyType.ObjectReference: + if (!(value is Object o)) + return false; + + sp.objectReferenceValue = o; + return true; + case SerializedPropertyType.Vector2: + if (!(value is Vector2 v2)) + return false; + + sp.vector2Value = v2; + return true; + case SerializedPropertyType.Vector3: + if (!(value is Vector3 v3)) + return false; + + sp.vector3Value = v3; + return true; + case SerializedPropertyType.Vector4: + if (!(value is Vector4 v4)) + return false; + + sp.vector4Value = v4; + return true; + case SerializedPropertyType.Rect: + if (!(value is Rect r)) + return false; + + sp.rectValue = r; + return true; + case SerializedPropertyType.AnimationCurve: + if (!(value is AnimationCurve ac)) + return false; + + sp.animationCurveValue = ac; + return true; + case SerializedPropertyType.Bounds: + if (!(value is Bounds bounds)) + return false; + + sp.boundsValue = bounds; + return true; + case SerializedPropertyType.Quaternion: + if (!(value is Quaternion q)) + return false; + + sp.quaternionValue = q; + return true; + case SerializedPropertyType.Vector2Int: + if (!(value is Vector2Int v2i)) + return false; + + sp.vector2IntValue = v2i; + return true; + case SerializedPropertyType.Vector3Int: + if (!(value is Vector3Int v3i)) + return false; + + sp.vector3IntValue = v3i; + return true; + case SerializedPropertyType.RectInt: + if (!(value is RectInt ri)) + return false; + + sp.rectIntValue = ri; + return true; + case SerializedPropertyType.BoundsInt: + if (!(value is BoundsInt bi)) + return false; + + sp.boundsIntValue = bi; + return true; + } + + return false; + } + + private static bool Contains(this SerializedProperty sp, object value) + { + if (sp.isArray) + { + for (var i = 0; i < sp.arraySize; i++) + { + SerializedProperty temp = sp.GetArrayElementAtIndex(i); + + if (temp.Contains(value)) + return true; + } + } + else + { + try + { + switch (sp.propertyType) + { + case SerializedPropertyType.LayerMask: + case SerializedPropertyType.Integer: + case SerializedPropertyType.Enum: + return Convert.ToInt32(value) == sp.intValue; + case SerializedPropertyType.Boolean: + return Convert.ToBoolean(value) == sp.boolValue; + case SerializedPropertyType.Float: + return Mathf.Approximately(Convert.ToSingle(value), sp.floatValue); + case SerializedPropertyType.String: + return Convert.ToString(value).Equals(sp.stringValue); + case SerializedPropertyType.ObjectReference: + if (!(value is Object)) + return false; + + return sp.objectReferenceValue == (Object)value; + } + } + catch (Exception e) + { + Debug.LogException(e); + } + } + + return false; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static string GetRootPath(string propertyPath) + { + int lastIndex = propertyPath.LastIndexOf('.'); + return lastIndex != -1 ? propertyPath.Remove(lastIndex) : string.Empty; + } + + public static T GetValue(this SerializedProperty property) where T : class + { + return property.GetValue() as T; + } + + private static object GetValue(this SerializedProperty property) + { + object obj = property.serializedObject.targetObject; + + foreach (string path in property.propertyPath.Split('.')) + { + Type type = obj.GetType(); + FieldInfo field = type.GetField(path); + obj = field.GetValue(obj); + } + + return obj; + } + + public static Type GetValueType(this SerializedProperty property) + { + object obj = property.serializedObject.targetObject; + Type type = null; + + foreach (string path in property.propertyPath.Split('.')) + { + type = obj.GetType(); + FieldInfo field = type.GetField(path); + obj = field.GetValue(obj); + type = field.FieldType; + } + + return type; + } + + public static void SetArray(this SerializedProperty property, T[] array) where T : Object + { + property.ClearArray(); + + for (var i = 0; i < array.Length; i++) + { + property.InsertArrayElementAtIndex(i); + SerializedProperty sp = property.GetArrayElementAtIndex(i); + sp.objectReferenceValue = array[i]; + } + } + } +} \ No newline at end of file diff --git a/Editor/Extensions/SerializedPropertyExtension.cs.meta b/Editor/Extensions/SerializedPropertyExtension.cs.meta new file mode 100644 index 0000000..4e28c5c --- /dev/null +++ b/Editor/Extensions/SerializedPropertyExtension.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7c74edadbcd71ad4aa3293e00a4d4d47 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Module.Inspector.Editor.asmdef b/Editor/Module.Inspector.Editor.asmdef new file mode 100644 index 0000000..bc91b21 --- /dev/null +++ b/Editor/Module.Inspector.Editor.asmdef @@ -0,0 +1,18 @@ +{ + "name": "Module.Inspector.Editor", + "rootNamespace": "Module.Inspector.Editor", + "references": [ + "GUID:a58be6d007e5e434ebc9bf7f902990a7" + ], + "includePlatforms": [ + "Editor" + ], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Editor/Module.Inspector.Editor.asmdef.meta b/Editor/Module.Inspector.Editor.asmdef.meta new file mode 100644 index 0000000..b10a1c7 --- /dev/null +++ b/Editor/Module.Inspector.Editor.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2002c0ac45f161445a6fa998a273f22a +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ObjectEditor.cs b/Editor/ObjectEditor.cs new file mode 100644 index 0000000..93776fc --- /dev/null +++ b/Editor/ObjectEditor.cs @@ -0,0 +1,68 @@ +using Module.Inspector.Editor.Utilities; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CanEditMultipleObjects] + [CustomEditor(typeof(Object), true, isFallback = true)] + public sealed class ObjectEditor : UnityEditor.Editor + { + public override void OnInspectorGUI() + { + DrawDefaultInspector(); + DrawMethodInspector(); + } + + private void DrawMethodInspector() + { + if (!IsValidMethodTarget()) + return; + + EditorMethodUtility.ResultPrimary[] primaries = EditorMethodUtility.QueryPrimary(target); + + float totalHeight = CalculateMethodHeight(primaries); + GUILayout.Space(totalHeight); + + var position = new Rect(0, 0, 1, 1); + + if (Event.current.type == EventType.Repaint) + { + position = GUILayoutUtility.GetLastRect(); + position.y -= totalHeight; + } + + position.y = position.yMax + EditorGUIUtility.singleLineHeight; + position.height = 0.0f; + + for (var i = 0; i < primaries.Length; i++) + { + EditorMethodUtility.ResultPrimary primary = primaries[i]; + + float height = primary.drawer.GetHeight(target, primary.methodInfo); + position.height = height; + + primary.drawer.OnGUI(position, target, primary.methodInfo); + position.y += height; + } + } + + private float CalculateMethodHeight(EditorMethodUtility.ResultPrimary[] primaries) + { + float total = EditorGUIUtility.singleLineHeight; + + for (var i = 0; i < primaries.Length; i++) + { + EditorMethodUtility.ResultPrimary primary = primaries[i]; + total += primary.drawer.GetHeight(target, primary.methodInfo); + } + + return total; + } + + private bool IsValidMethodTarget() + { + return target != null && targets.Length == 1; + } + } +} \ No newline at end of file diff --git a/Editor/ObjectEditor.cs.meta b/Editor/ObjectEditor.cs.meta new file mode 100644 index 0000000..20bb536 --- /dev/null +++ b/Editor/ObjectEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bd743fb74f77a5f40936b202ff6f35d4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities.meta b/Editor/Utilities.meta new file mode 100644 index 0000000..75a75c4 --- /dev/null +++ b/Editor/Utilities.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 743152a66f1aba046b489eb2b8907a29 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/EditorMethodUtility.cs b/Editor/Utilities/EditorMethodUtility.cs new file mode 100644 index 0000000..69d1cf8 --- /dev/null +++ b/Editor/Utilities/EditorMethodUtility.cs @@ -0,0 +1,233 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; + +namespace Module.Inspector.Editor.Utilities +{ + internal static class EditorMethodUtility + { + private static Dictionary CACHED_TYPE_TO_PRIMARIES; + private static Dictionary CACHED_RESULTS; + private static Dictionary CACHED_ATT_TO_DRAWER; + + private static void InitializeCache() + { + if (CACHED_ATT_TO_DRAWER != null) + return; + + CACHED_ATT_TO_DRAWER = new Dictionary(); + + Type baseDrawerType = typeof(AbstractMethodDrawer); + var assembly = Assembly.GetAssembly(baseDrawerType); + Type[] types = assembly.GetTypes(); + + for (var i = 0; i < types.Length; i++) + { + Type type = types[i]; + + if (type.IsAbstract || !baseDrawerType.IsAssignableFrom(type)) + continue; + + IList attributes = type.GetCustomAttributesData(); + + for (var j = 0; j < attributes.Count; j++) + { + CustomAttributeData attData = attributes[j]; + IList arguments = attData.ConstructorArguments; + + for (var k = 0; k < arguments.Count; k++) + { + if (arguments[k].Value is Type argType) + CACHED_ATT_TO_DRAWER.Add(argType, type); + } + } + } + } + + public static ResultPrimary[] QueryPrimary(Object target) + { + InitializeCache(); + + if (CACHED_TYPE_TO_PRIMARIES == null) + CACHED_TYPE_TO_PRIMARIES = new Dictionary(); + + Type type = target.GetType(); + + if (CACHED_TYPE_TO_PRIMARIES.TryGetValue(type, out ResultPrimary[] primaries)) + return primaries; + + primaries = InternalFetchPrimary(type); + CACHED_TYPE_TO_PRIMARIES.Add(type, primaries); + return primaries; + } + + public static Result Query(MethodInfo methodInfo) + { + InitializeCache(); + + if (CACHED_RESULTS == null) + CACHED_RESULTS = new Dictionary(); + + if (CACHED_RESULTS.TryGetValue(methodInfo, out Result result)) + return result; + + result = InternalFetchProperties(methodInfo); + + if (result != null) + CACHED_RESULTS.Add(methodInfo, result); + + return result; + } + + private static ResultPrimary[] InternalFetchPrimary(Type type) + { + const BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; + + MethodInfo[] methods = type.GetMethods(FLAGS) + .Where(m => m.GetParameters().Length == 0) + .ToArray(); + + var list = new List(methods.Length); + + for (var i = 0; i < methods.Length; i++) + { + Result result = Query(methods[i]); + + if (result != null) + list.Add(new ResultPrimary(methods[i], result)); + } + + return list.ToArray(); + } + + private static Result InternalFetchProperties(MethodInfo methodInfo) + { + ResultValue drawer = null; + ResultValue decorator = null; + var accessModifiers = new List>(2); + object[] attributes = methodInfo.GetCustomAttributes(false); + + for (var i = 0; i < attributes.Length; i++) + { + object att = attributes[i]; + + if (att is DrawerMethodAttribute attDrawer) + { + if (drawer != null) + continue; + + var prop = InternalCreateInstanceOf(attDrawer); + + if (prop != null) + drawer = new ResultValue(attDrawer, prop); + } + else if (att is AccessModifierMethodAttribute accessModifier) + { + var prop = InternalCreateInstanceOf(accessModifier); + + if (prop != null) + accessModifiers.Add(new ResultValue(accessModifier, prop)); + } + else if (att is DecoratorMethodAttribute attDecorator) + { + if (decorator != null) + continue; + + var prop = InternalCreateInstanceOf(attDecorator); + + if (prop != null) + decorator = new ResultValue(attDecorator, prop); + } + } + + if (drawer == null && decorator == null && accessModifiers.Count == 0) + return null; + + return new Result(drawer, decorator, accessModifiers); + } + + private static T InternalCreateInstanceOf(AbstractMethodAttribute att) where T : AbstractMethodDrawer + { + if (CACHED_ATT_TO_DRAWER.TryGetValue(att.GetType(), out Type drawerType)) + return Activator.CreateInstance(drawerType) as T; + + return null; + } + + /// + /// Class: Result from method query + /// + public sealed class Result + { + public readonly ResultValue draw; + public readonly ResultValue decorator; + public readonly List> accessModifiers; + + public Result(ResultValue draw, + ResultValue decorator, + List> accessModifiers) + { + this.draw = draw; + this.decorator = decorator; + this.accessModifiers = accessModifiers; + } + + public T GetAccessModifier() where T : AccessModifierMethodAttribute + { + for (var i = 0; i < accessModifiers.Count; i++) + { + if (accessModifiers[i].attribute is T att) + return att; + } + + return null; + } + } + + /// + /// Class: Contains attribute and drawer values + /// + /// + /// + public sealed class ResultValue where T0 : AbstractMethodAttribute + where T1 : AbstractMethodDrawer + { + public readonly T0 attribute; + public readonly T1 drawer; + + public ResultValue(T0 attribute, T1 drawer) + { + this.attribute = attribute; + this.drawer = drawer; + } + } + + /// + /// Class: Contains primary method info and drawer for a specific method + /// + public sealed class ResultPrimary + { + public readonly MethodInfo methodInfo; + public readonly AbstractMethodDrawer drawer; + + public ResultPrimary(MethodInfo methodInfo, AbstractMethodDrawer drawer) + { + this.methodInfo = methodInfo; + this.drawer = drawer; + } + + public ResultPrimary(MethodInfo methodInfo, Result result) + { + this.methodInfo = methodInfo; + + if (result.draw != null) + drawer = result.draw.drawer; + else if (result.decorator != null) + drawer = result.decorator.drawer; + else if (result.accessModifiers != null && result.accessModifiers.Count > 0) + drawer = result.accessModifiers[0].drawer; + } + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/EditorMethodUtility.cs.meta b/Editor/Utilities/EditorMethodUtility.cs.meta new file mode 100644 index 0000000..e7b471e --- /dev/null +++ b/Editor/Utilities/EditorMethodUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8084cb44127a2464ab72b4d104b7b622 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/EditorNamingUtility.cs b/Editor/Utilities/EditorNamingUtility.cs new file mode 100644 index 0000000..cfdf66e --- /dev/null +++ b/Editor/Utilities/EditorNamingUtility.cs @@ -0,0 +1,76 @@ +using System.Globalization; +using System.Linq; +using System.Text.RegularExpressions; + +namespace Module.Inspector.Editor.Utilities +{ + public static class EditorNamingUtility + { + public static string ConvertTo(Naming.EPatternType type, string str) + { + switch (type) + { + case Naming.EPatternType.CamelCasing: + return ToCamel(str); + case Naming.EPatternType.PascalCasing: + return ToPascal(str); + case Naming.EPatternType.SnakeCasing: + return ToSnake(str); + case Naming.EPatternType.SnakeCasingAllCaps: + return ToSnake(str).ToUpper(); + case Naming.EPatternType.KebabCasing: + return ToKebab(str); + case Naming.EPatternType.KebabCasingAllCaps: + return ToKebab(str).ToUpper(); + default: + return str; + } + } + + public static string ToPascal(string str) + { + var pattern = new Regex(@"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+"); + MatchCollection matches = pattern.Matches(str); + + if (matches.Count != 0) + str = matches.Cast().Select(c => c.Value).Aggregate(( a, b ) => a + " " + b); + + var culture = new CultureInfo("en-US", false); + str = culture.TextInfo.ToTitleCase(str); + str = str.Replace(@" ", ""); + return str; + } + + public static string ToCamel(string str) + { + str = ToPascal(str); + + if (str.Length > 0) + str = char.ToLower(str[0]) + str.Substring(1); + + return str; + } + + public static string ToSnake(string str) + { + var pattern = new Regex(@"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+"); + MatchCollection matches = pattern.Matches(str); + + if (matches.Count != 0) + str = matches.Cast().Select(c => c.Value).Aggregate(( a, b ) => a + "_" + b); + + return str; + } + + public static string ToKebab(string str) + { + var pattern = new Regex(@"[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+"); + MatchCollection matches = pattern.Matches(str); + + if (matches.Count != 0) + str = matches.Cast().Select(c => c.Value).Aggregate(( a, b ) => a + "-" + b); + + return str; + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/EditorNamingUtility.cs.meta b/Editor/Utilities/EditorNamingUtility.cs.meta new file mode 100644 index 0000000..cec18a9 --- /dev/null +++ b/Editor/Utilities/EditorNamingUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cbf1a9393f7c4425b846686ccc5445e0 +timeCreated: 1625650972 \ No newline at end of file diff --git a/Editor/Utilities/EditorPropertyUtility.cs b/Editor/Utilities/EditorPropertyUtility.cs new file mode 100644 index 0000000..5399aad --- /dev/null +++ b/Editor/Utilities/EditorPropertyUtility.cs @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Editor.Utilities +{ + public static class EditorPropertyUtility + { + private static Dictionary CACHED_RESULTS; + private static Dictionary CACHED_ATT_TO_DRAWER; + + private static void InitializeCache() + { + if (CACHED_ATT_TO_DRAWER != null) + return; + + CACHED_ATT_TO_DRAWER = new Dictionary(); + + Type baseDrawerType = typeof(AbstractPropertyDrawer); + var assembly = Assembly.GetAssembly(baseDrawerType); + Type[] types = assembly.GetTypes(); + + for (var i = 0; i < types.Length; i++) + { + Type type = types[i]; + + if (type.IsAbstract || !baseDrawerType.IsAssignableFrom(type)) + continue; + + IList attributes = type.GetCustomAttributesData(); + + for (var j = 0; j < attributes.Count; j++) + { + CustomAttributeData attData = attributes[j]; + IList arguments = attData.ConstructorArguments; + + for (var k = 0; k < arguments.Count; k++) + { + if (arguments[k].Value is Type argType) + CACHED_ATT_TO_DRAWER.Add(argType, type); + } + } + } + } + + public static Result Query(FieldInfo fieldInfo) + { + InitializeCache(); + + if (CACHED_RESULTS == null) + CACHED_RESULTS = new Dictionary(); + + if (CACHED_RESULTS.TryGetValue(fieldInfo, out Result result)) + return result; + + result = InternalFetchProperties(fieldInfo); + CACHED_RESULTS.Add(fieldInfo, result); + return result; + } + + private static Result InternalFetchProperties(FieldInfo fieldInfo) + { + ResultValue drawer = null; + var typeDrawer = InternalCreateInstanceOf(fieldInfo); + + if (typeDrawer != null) + drawer = new ResultValue(null, typeDrawer); + + var valueModifiers = new List>(2); + var accessModifiers = new List>(2); + object[] attributes = fieldInfo.GetCustomAttributes(false); + string tooltip = null; + var isObsolete = false; + string obsoleteText = null; + + for (var i = 0; i < attributes.Length; i++) + { + object att = attributes[i]; + + if (att is DrawerPropertyAttribute attDrawer) + { + if (drawer != null) + continue; + + var prop = InternalCreateInstanceOf(attDrawer); + + if (prop != null) + drawer = new ResultValue(attDrawer, prop); + } + else if (att is ValueModifierPropertyAttribute valueModifier) + { + var prop = InternalCreateInstanceOf(valueModifier); + + if (prop != null) + valueModifiers.Add(new ResultValue(valueModifier, prop)); + } + else if (att is AccessModifierPropertyAttribute accessModifier) + { + var prop = InternalCreateInstanceOf(accessModifier); + + if (prop != null) + accessModifiers.Add(new ResultValue(accessModifier, prop)); + } + else if (att is TooltipAttribute attTooltip) + { + tooltip = attTooltip.tooltip; + } + else if (att is ObsoleteAttribute attObsolete) + { + isObsolete = true; + obsoleteText = attObsolete.Message; + } + } + + if (!string.IsNullOrEmpty(obsoleteText)) + { + if (tooltip != null) + tooltip += $"\n[Obsolete: {obsoleteText}"; + else + tooltip = $"Obsolete: {obsoleteText}"; + } + + return new Result(drawer, valueModifiers, accessModifiers, tooltip, isObsolete); + } + + private static T InternalCreateInstanceOf(AbstractPropertyAttribute att) where T : AbstractPropertyDrawer + { + if (CACHED_ATT_TO_DRAWER.TryGetValue(att.GetType(), out Type drawerType)) + return Activator.CreateInstance(drawerType) as T; + + return null; + } + + private static T InternalCreateInstanceOf(FieldInfo fieldInfo) where T : AbstractPropertyDrawer + { + if (CACHED_ATT_TO_DRAWER.TryGetValue(fieldInfo.FieldType, out Type drawerType)) + return Activator.CreateInstance(drawerType) as T; + + return null; + } + + /// + /// Class: Result from property query + /// + public sealed class Result + { + public readonly ResultValue draw; + public readonly List> valueModifiers; + public readonly List> accessModifiers; + public readonly string tooltip; + public readonly bool isObsolete; + + public Result(ResultValue draw, + List> valueModifiers, + List> accessModifiers, + string tooltip, + bool isObsolete) + { + this.draw = draw; + this.valueModifiers = valueModifiers; + this.accessModifiers = accessModifiers; + this.tooltip = tooltip; + this.isObsolete = isObsolete; + } + + public T GetValueModifier() where T : ValueModifierPropertyAttribute + { + for (var i = 0; i < valueModifiers.Count; i++) + { + if (valueModifiers[i].attribute is T att) + return att; + } + + return null; + } + + public T GetAccessModifier() where T : AccessModifierPropertyAttribute + { + for (var i = 0; i < accessModifiers.Count; i++) + { + if (accessModifiers[i].attribute is T att) + return att; + } + + return null; + } + } + + /// + /// Class: Contains attribute and drawer values + /// + /// + /// + public sealed class ResultValue where T0 : AbstractPropertyAttribute + where T1 : AbstractPropertyDrawer + { + public readonly T0 attribute; + public readonly T1 drawer; + + public ResultValue(T0 attribute, T1 drawer) + { + this.attribute = attribute; + this.drawer = drawer; + } + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/EditorPropertyUtility.cs.meta b/Editor/Utilities/EditorPropertyUtility.cs.meta new file mode 100644 index 0000000..a9b7ac0 --- /dev/null +++ b/Editor/Utilities/EditorPropertyUtility.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dd20b0ba8f5857e4d89bd475e38b7c13 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Utilities/EditorSerializedPropertyUtility.cs b/Editor/Utilities/EditorSerializedPropertyUtility.cs new file mode 100644 index 0000000..97de347 --- /dev/null +++ b/Editor/Utilities/EditorSerializedPropertyUtility.cs @@ -0,0 +1,56 @@ +using System; +using UnityEditor; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace Module.Inspector.Editor.Utilities +{ + internal static class EditorSerializedPropertyUtility + { + public static bool IsValue(Object obj, string fieldName, object value, bool useFieldValue) + { + if (obj == null || string.IsNullOrEmpty(fieldName)) + return false; + + var so = new SerializedObject(obj); + SerializedProperty sp = so.FindProperty(fieldName); + return IsValue(sp, value, useFieldValue); + } + + public static bool IsValue(SerializedProperty sp, object value, bool useFieldValue) + { + if (sp == null) + return false; + + if (useFieldValue) + { + switch (sp.propertyType) + { + case SerializedPropertyType.Generic: + return value == (object)sp.objectReferenceValue; + case SerializedPropertyType.Integer: + return value is int i && sp.intValue == i; + case SerializedPropertyType.Boolean: + return value is bool b && sp.boolValue == b; + case SerializedPropertyType.Float: + return value is float f && Mathf.Approximately(sp.floatValue, f); + case SerializedPropertyType.String: + return value is string s && sp.stringValue == s; + case SerializedPropertyType.LayerMask: + return value is LayerMask l && sp.intValue == l; + case SerializedPropertyType.Enum: + return value is Enum && sp.intValue == Convert.ToInt32(value); + } + } + else + { + if (sp.propertyType == SerializedPropertyType.Boolean) + return sp.boolValue; + if (sp.propertyType == SerializedPropertyType.ObjectReference) + return sp.objectReferenceValue != null; + } + + return true; + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/EditorSerializedPropertyUtility.cs.meta b/Editor/Utilities/EditorSerializedPropertyUtility.cs.meta new file mode 100644 index 0000000..ffe7e31 --- /dev/null +++ b/Editor/Utilities/EditorSerializedPropertyUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: d9c65105e5014222be899656c09dceef +timeCreated: 1610022228 \ No newline at end of file diff --git a/Editor/Utilities/EditorTypeUtility.cs b/Editor/Utilities/EditorTypeUtility.cs new file mode 100644 index 0000000..0020342 --- /dev/null +++ b/Editor/Utilities/EditorTypeUtility.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEditor; +using UnityEngine; +using Object = UnityEngine.Object; + +namespace Module.Inspector.Editor +{ + internal static class EditorTypeUtility + { + private const BindingFlags FIELD_FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic; + + private static readonly Dictionary DICT_AS_TYPES = new Dictionary(); + private static readonly Dictionary DICT_AS_STRS = new Dictionary(); + private static readonly Dictionary DICT_AS_DESCS = new Dictionary(); + + private static readonly Dictionary DICT_AS_FIELDS = new Dictionary(); + private static readonly Dictionary DICT_FIELDS_AS_STRS = new Dictionary(); + private static readonly Dictionary DICT_FIELDS_AS_DESCS = new Dictionary(); + + public static Type GetType(string fullname) + { + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + for (var i = 0; i < assemblies.Length; i++) + { + Assembly assembly = assemblies[i]; + Type type = assembly.GetType(fullname); + + if (type != null) + return type; + } + + return null; + } + + public static FieldInfo GetField(object target, string fieldName) + { + return GetFieldByName(target.GetType(), fieldName); + } + + public static bool SetFieldValue(object target, string fieldName, object value, bool allowDuplicate) + { + if (InternalTrySetUnityObject(target, fieldName, value, allowDuplicate)) + return true; + + FieldInfo field = GetField(target, fieldName); + + if (field == null) + return false; + + try + { + field.SetValue(target, value); + + if (target is Object o) + EditorUtility.SetDirty(o); + } + catch (Exception e) + { + Debug.LogException(e); + return false; + } + + return true; + } + + private static bool InternalTrySetUnityObject(object target, string fieldName, object value, bool allowDuplicate) + { + if (!(target is Object o)) + return false; + + var so = new SerializedObject(o); + SerializedProperty sp = so.FindProperty(fieldName); + bool success = sp?.TrySetValueTo(value, allowDuplicate) ?? false; + + if (success) + so.ApplyModifiedProperties(); + + return success; + } + + internal static Type[] GetAssignableFrom(Type type) + { + if (!DICT_AS_TYPES.ContainsKey(type)) + InternalFetch(type); + + return DICT_AS_TYPES[type]; + } + + internal static string[] GetAssignableFromAsStrings(Type type) + { + if (!DICT_AS_STRS.ContainsKey(type)) + InternalFetch(type); + + return DICT_AS_STRS[type]; + } + + internal static string[] GetAssignableFromAsDescriptions(Type type) + { + if (!DICT_AS_DESCS.ContainsKey(type)) + InternalFetch(type); + + return DICT_AS_DESCS[type]; + } + + internal static FieldInfo[] GetFields(Type type) + { + if (!DICT_AS_FIELDS.ContainsKey(type)) + InternalFetchFields(type); + + return DICT_AS_FIELDS[type]; + } + + internal static FieldInfo GetFieldByName(Type type, string fieldName) + { + FieldInfo[] fields = GetFields(type); + + for (var i = 0; i < fields.Length; i++) + { + if (fields[i].Name.Equals(fieldName)) + return fields[i]; + } + + return null; + } + + internal static string[] GetFieldsAsStrings(Type type) + { + if (!DICT_FIELDS_AS_STRS.ContainsKey(type)) + InternalFetchFields(type); + + return DICT_FIELDS_AS_STRS[type]; + } + + internal static string[] GetFieldsAsDescriptions(Type type) + { + if (!DICT_FIELDS_AS_DESCS.ContainsKey(type)) + InternalFetchFields(type); + + return DICT_FIELDS_AS_DESCS[type]; + } + + private static void InternalFetch(Type assignableFrom) + { + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + var listTypes = new List(32); + + for (var i = 0; i < assemblies.Length; i++) + { + Assembly assembly = assemblies[i]; + Type[] types = assembly.GetTypes(); + + for (var j = 0; j < types.Length; j++) + { + Type type = types[j]; + + if (!type.IsAbstract && assignableFrom.IsAssignableFrom(type)) + listTypes.Add(type); + } + } + + listTypes.Sort((t0, t1) => string.Compare(t0.Name, t1.Name, StringComparison.Ordinal)); + var fullnames = new string[listTypes.Count]; + var descs = new string[listTypes.Count]; + + for (var i = 0; i < fullnames.Length; i++) + { + fullnames[i] = listTypes[i].FullName; + descs[i] = $"{listTypes[i].Name} ({fullnames[i]})"; + } + + DICT_AS_TYPES.Add(assignableFrom, listTypes.ToArray()); + DICT_AS_STRS.Add(assignableFrom, fullnames); + DICT_AS_DESCS.Add(assignableFrom, descs); + } + + private static void InternalFetchFields(Type type) + { + FieldInfo[] fields = type.GetFields(FIELD_FLAGS); + Array.Sort(fields, (f0, f1) => string.Compare(f0.Name, f1.Name, StringComparison.Ordinal)); + + var names = new string[fields.Length]; + var descs = new string[fields.Length]; + + for (var i = 0; i < names.Length; i++) + { + names[i] = fields[i].Name; + descs[i] = $"{fields[i].Name} ({fields[i].FieldType.Name})"; + } + + DICT_AS_FIELDS.Add(type, fields); + DICT_FIELDS_AS_STRS.Add(type, names); + DICT_FIELDS_AS_DESCS.Add(type, descs); + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/EditorTypeUtility.cs.meta b/Editor/Utilities/EditorTypeUtility.cs.meta new file mode 100644 index 0000000..45bb50f --- /dev/null +++ b/Editor/Utilities/EditorTypeUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 762ec4eaaaf08a745929731d2379bed8 +timeCreated: 1590404966 \ No newline at end of file diff --git a/Editor/ValueModifierPropertyDrawer.cs b/Editor/ValueModifierPropertyDrawer.cs new file mode 100644 index 0000000..67ec121 --- /dev/null +++ b/Editor/ValueModifierPropertyDrawer.cs @@ -0,0 +1,9 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + public abstract class ValueModifierPropertyDrawer : AbstractPropertyDrawer + { + public abstract void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property); + } +} \ No newline at end of file diff --git a/Editor/ValueModifierPropertyDrawer.cs.meta b/Editor/ValueModifierPropertyDrawer.cs.meta new file mode 100644 index 0000000..6599c37 --- /dev/null +++ b/Editor/ValueModifierPropertyDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 824d03533ff074549bac1851ba463173 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ValueModifiers.meta b/Editor/ValueModifiers.meta new file mode 100644 index 0000000..ef94d31 --- /dev/null +++ b/Editor/ValueModifiers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9b0feaeebea549541b58b7e682c5aa1b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ValueModifiers/DrawerArrayIndex.cs b/Editor/ValueModifiers/DrawerArrayIndex.cs new file mode 100644 index 0000000..b1653f4 --- /dev/null +++ b/Editor/ValueModifiers/DrawerArrayIndex.cs @@ -0,0 +1,27 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(ArrayIndex))] + internal sealed class DrawerArrayIndex : ValueModifierPropertyDrawer + { + public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property) + { + var att = (ArrayIndex)attribute; + + int arraySize = GetSiblingArraySize(property, att); + int max = arraySize > 0 ? arraySize - 1 : 0; + int value = Mathf.Clamp(property.intValue, 0, max); + + if (value != property.intValue) + property.intValue = value; + } + + private static int GetSiblingArraySize(SerializedProperty sp, ArrayIndex att) + { + SerializedProperty spSibling = sp.GetSibling(att.fieldName); + return spSibling != null && spSibling.isArray ? spSibling.arraySize : 0; + } + } +} \ No newline at end of file diff --git a/Editor/ValueModifiers/DrawerArrayIndex.cs.meta b/Editor/ValueModifiers/DrawerArrayIndex.cs.meta new file mode 100644 index 0000000..a611f03 --- /dev/null +++ b/Editor/ValueModifiers/DrawerArrayIndex.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 58c23ce231bb093478a6e73290d3f08d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ValueModifiers/DrawerLargerThanField.cs b/Editor/ValueModifiers/DrawerLargerThanField.cs new file mode 100644 index 0000000..9022960 --- /dev/null +++ b/Editor/ValueModifiers/DrawerLargerThanField.cs @@ -0,0 +1,17 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(LargerThanField))] + internal sealed class DrawerLargerThanField : ValueModifierPropertyDrawer + { + public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property) + { + var att = (LargerThanField)attribute; + SerializedPropertyExtension.ECompareType compareType = property.IsGreaterOrEqualToSiblingValue(att.fieldName); + + if (compareType == SerializedPropertyExtension.ECompareType.False) + property.SetValueTo(property.GetSibling(att.fieldName)); + } + } +} \ No newline at end of file diff --git a/Editor/ValueModifiers/DrawerLargerThanField.cs.meta b/Editor/ValueModifiers/DrawerLargerThanField.cs.meta new file mode 100644 index 0000000..0e0657b --- /dev/null +++ b/Editor/ValueModifiers/DrawerLargerThanField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 33edc75018f0b9a4d9f9e5289c531abd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ValueModifiers/DrawerMaxValue.cs b/Editor/ValueModifiers/DrawerMaxValue.cs new file mode 100644 index 0000000..57c5257 --- /dev/null +++ b/Editor/ValueModifiers/DrawerMaxValue.cs @@ -0,0 +1,58 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(MaxValue))] + internal sealed class DrawerMaxValue : ValueModifierPropertyDrawer + { + public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property) + { + var max = (MaxValue)attribute; + + switch (property.propertyType) + { + case SerializedPropertyType.Integer: + property.intValue = Mathf.Min(max.intValue, property.intValue); + break; + case SerializedPropertyType.Float: + property.floatValue = Mathf.Min(max.floatValue, property.floatValue); + break; + case SerializedPropertyType.Vector2: + Vector2 v2 = property.vector2Value; + v2.x = Mathf.Min(max.floatValue, property.vector2Value.x); + v2.y = Mathf.Min(max.floatValue, property.vector2Value.y); + property.vector2Value = v2; + break; + case SerializedPropertyType.Vector3: + Vector3 v3 = property.vector3Value; + v3.x = Mathf.Min(max.floatValue, property.vector3Value.x); + v3.y = Mathf.Min(max.floatValue, property.vector3Value.y); + v3.z = Mathf.Min(max.floatValue, property.vector3Value.z); + property.vector3Value = v3; + break; + case SerializedPropertyType.Vector4: + Vector4 v4 = property.vector4Value; + v4.x = Mathf.Min(max.floatValue, property.vector4Value.x); + v4.y = Mathf.Min(max.floatValue, property.vector4Value.y); + v4.z = Mathf.Min(max.floatValue, property.vector4Value.z); + v4.w = Mathf.Min(max.floatValue, property.vector4Value.w); + property.vector4Value = v4; + break; + case SerializedPropertyType.Vector2Int: + Vector2Int v2Int = property.vector2IntValue; + v2Int.x = Mathf.Min(max.intValue, property.vector2IntValue.x); + v2Int.y = Mathf.Min(max.intValue, property.vector2IntValue.y); + property.vector2IntValue = v2Int; + break; + case SerializedPropertyType.Vector3Int: + Vector3Int v3Int = property.vector3IntValue; + v3Int.x = Mathf.Min(max.intValue, property.vector3IntValue.x); + v3Int.y = Mathf.Min(max.intValue, property.vector3IntValue.y); + v3Int.z = Mathf.Min(max.intValue, property.vector3IntValue.z); + property.vector3IntValue = v3Int; + break; + } + } + } +} \ No newline at end of file diff --git a/Editor/ValueModifiers/DrawerMaxValue.cs.meta b/Editor/ValueModifiers/DrawerMaxValue.cs.meta new file mode 100644 index 0000000..7f0204e --- /dev/null +++ b/Editor/ValueModifiers/DrawerMaxValue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f430530eb43aa974b8a4273c333c2149 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ValueModifiers/DrawerMinValue.cs b/Editor/ValueModifiers/DrawerMinValue.cs new file mode 100644 index 0000000..effda92 --- /dev/null +++ b/Editor/ValueModifiers/DrawerMinValue.cs @@ -0,0 +1,58 @@ +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(MinValue))] + internal sealed class DrawerMinValue : ValueModifierPropertyDrawer + { + public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property) + { + var min = (MinValue)attribute; + + switch (property.propertyType) + { + case SerializedPropertyType.Integer: + property.intValue = Mathf.Max(min.intValue, property.intValue); + break; + case SerializedPropertyType.Float: + property.floatValue = Mathf.Max(min.floatValue, property.floatValue); + break; + case SerializedPropertyType.Vector2: + Vector2 v2 = property.vector2Value; + v2.x = Mathf.Max(min.floatValue, property.vector2Value.x); + v2.y = Mathf.Max(min.floatValue, property.vector2Value.y); + property.vector2Value = v2; + break; + case SerializedPropertyType.Vector3: + Vector3 v3 = property.vector3Value; + v3.x = Mathf.Max(min.floatValue, property.vector3Value.x); + v3.y = Mathf.Max(min.floatValue, property.vector3Value.y); + v3.z = Mathf.Max(min.floatValue, property.vector3Value.z); + property.vector3Value = v3; + break; + case SerializedPropertyType.Vector4: + Vector4 v4 = property.vector4Value; + v4.x = Mathf.Max(min.floatValue, property.vector4Value.x); + v4.y = Mathf.Max(min.floatValue, property.vector4Value.y); + v4.z = Mathf.Max(min.floatValue, property.vector4Value.z); + v4.w = Mathf.Max(min.floatValue, property.vector4Value.w); + property.vector4Value = v4; + break; + case SerializedPropertyType.Vector2Int: + Vector2Int v2Int = property.vector2IntValue; + v2Int.x = Mathf.Max(min.intValue, property.vector2IntValue.x); + v2Int.y = Mathf.Max(min.intValue, property.vector2IntValue.y); + property.vector2IntValue = v2Int; + break; + case SerializedPropertyType.Vector3Int: + Vector3Int v3Int = property.vector3IntValue; + v3Int.x = Mathf.Max(min.intValue, property.vector3IntValue.x); + v3Int.y = Mathf.Max(min.intValue, property.vector3IntValue.y); + v3Int.z = Mathf.Max(min.intValue, property.vector3IntValue.z); + property.vector3IntValue = v3Int; + break; + } + } + } +} \ No newline at end of file diff --git a/Editor/ValueModifiers/DrawerMinValue.cs.meta b/Editor/ValueModifiers/DrawerMinValue.cs.meta new file mode 100644 index 0000000..9fa38e2 --- /dev/null +++ b/Editor/ValueModifiers/DrawerMinValue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dec0cb037cad4194aafd92c44268ede8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ValueModifiers/DrawerSmallerThanField.cs b/Editor/ValueModifiers/DrawerSmallerThanField.cs new file mode 100644 index 0000000..a388f57 --- /dev/null +++ b/Editor/ValueModifiers/DrawerSmallerThanField.cs @@ -0,0 +1,17 @@ +using UnityEditor; + +namespace Module.Inspector.Editor +{ + [CustomPropertyDrawer(typeof(SmallerThanField))] + internal sealed class DrawerSmallerThanField : ValueModifierPropertyDrawer + { + public override void Modify(ValueModifierPropertyAttribute attribute, SerializedProperty property) + { + var att = (SmallerThanField)attribute; + SerializedPropertyExtension.ECompareType compareType = property.IsSmallerOrEqualToSiblingValue(att.fieldName); + + if (compareType == SerializedPropertyExtension.ECompareType.False) + property.SetValueTo(property.GetSibling(att.fieldName)); + } + } +} \ No newline at end of file diff --git a/Editor/ValueModifiers/DrawerSmallerThanField.cs.meta b/Editor/ValueModifiers/DrawerSmallerThanField.cs.meta new file mode 100644 index 0000000..1a15d06 --- /dev/null +++ b/Editor/ValueModifiers/DrawerSmallerThanField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04a363a4b71b7c94bb9ab276d255e69b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Windows.meta b/Editor/Windows.meta new file mode 100644 index 0000000..ae9ac58 --- /dev/null +++ b/Editor/Windows.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: ae12f66bc1c84ed092b6d9259d642416 +timeCreated: 1590404861 \ No newline at end of file diff --git a/Editor/Windows/EditorWindowStringToField.cs b/Editor/Windows/EditorWindowStringToField.cs new file mode 100644 index 0000000..2f57b5b --- /dev/null +++ b/Editor/Windows/EditorWindowStringToField.cs @@ -0,0 +1,105 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + internal sealed class EditorWindowStringToField : EditorWindow + { + private string[] names; + private string[] descriptions; + + private string filter = string.Empty; + private bool needFocus = true; + + private Vector2 scrollPosition; + private GUIStyle style0; + private GUIStyle style1; + + private SerializedProperty property; + + public static void Open(Type type, SerializedProperty property) + { + var window = GetWindow(); + window.titleContent = new GUIContent(type.Name); + window.names = EditorTypeUtility.GetFieldsAsStrings(type); + window.descriptions = EditorTypeUtility.GetFieldsAsDescriptions(type); + window.property = property; + window.ShowAuxWindow(); + } + + private void OnGUI() + { + if (!IsValid()) + return; + + CreateStyles(); + + EditorGUILayout.BeginVertical(); + { + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Search"); + + GUI.SetNextControlName("TextField_Filter"); + filter = EditorGUILayout.TextField(filter, GUILayout.Width(128)); + + GUILayout.FlexibleSpace(); + + if (GUILayout.Button("Close")) + Close(); + } + EditorGUILayout.EndHorizontal(); + + scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); + { + for (int i = 0, j = 0; i < descriptions.Length; i++) + { + if (!descriptions[i].Contains(filter)) + continue; + + j++; + + if (!GUILayout.Button(descriptions[i], j % 2 == 0 ? style0 : style1)) + continue; + + property.stringValue = names[i]; + property.serializedObject.ApplyModifiedProperties(); + Close(); + } + } + EditorGUILayout.EndScrollView(); + } + EditorGUILayout.EndVertical(); + + if (needFocus) + { + needFocus = false; + GUI.FocusControl("TextField_Filter"); + } + } + + private bool IsValid() + { + return names != null; + } + + private void CreateStyles() + { + if (style0 != null) + return; + + style0 = new GUIStyle(GUI.skin.box) + { + stretchWidth = true, + alignment = TextAnchor.MiddleLeft, + richText = true + }; + + style1 = new GUIStyle(style0) + { + normal = { background = null } + }; + } + } +} \ No newline at end of file diff --git a/Editor/Windows/EditorWindowStringToField.cs.meta b/Editor/Windows/EditorWindowStringToField.cs.meta new file mode 100644 index 0000000..937c393 --- /dev/null +++ b/Editor/Windows/EditorWindowStringToField.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 56356be65b80479599bd7e6ae370a1e9 +timeCreated: 1590411067 \ No newline at end of file diff --git a/Editor/Windows/EditorWindowStringToType.cs b/Editor/Windows/EditorWindowStringToType.cs new file mode 100644 index 0000000..4b34469 --- /dev/null +++ b/Editor/Windows/EditorWindowStringToType.cs @@ -0,0 +1,105 @@ +using System; +using UnityEditor; +using UnityEngine; + +namespace Module.Inspector.Editor +{ + internal sealed class EditorWindowStringToType : EditorWindow + { + private string[] names; + private string[] descriptions; + + private string filter = string.Empty; + private bool needFocus = true; + + private Vector2 scrollPosition; + private GUIStyle style0; + private GUIStyle style1; + + private SerializedProperty property; + + public static void Open(Type assignableFrom, SerializedProperty property) + { + var window = GetWindow(); + window.titleContent = new GUIContent(assignableFrom.Name); + window.names = EditorTypeUtility.GetAssignableFromAsStrings(assignableFrom); + window.descriptions = EditorTypeUtility.GetAssignableFromAsDescriptions(assignableFrom); + window.property = property; + window.ShowAuxWindow(); + } + + private void OnGUI() + { + if (!IsValid()) + return; + + CreateStyles(); + + EditorGUILayout.BeginVertical(); + { + EditorGUILayout.BeginHorizontal(); + { + GUILayout.Label("Search"); + + GUI.SetNextControlName("TextField_Filter"); + filter = EditorGUILayout.TextField(filter, GUILayout.Width(128)); + + GUILayout.FlexibleSpace(); + + if (GUILayout.Button("Close")) + Close(); + } + EditorGUILayout.EndHorizontal(); + + scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); + { + for (int i = 0, j = 0; i < descriptions.Length; i++) + { + if (!descriptions[i].Contains(filter)) + continue; + + j++; + + if (!GUILayout.Button(descriptions[i], j % 2 == 0 ? style0 : style1)) + continue; + + property.stringValue = names[i]; + property.serializedObject.ApplyModifiedProperties(); + Close(); + } + } + EditorGUILayout.EndScrollView(); + } + EditorGUILayout.EndVertical(); + + if (needFocus) + { + needFocus = false; + GUI.FocusControl("TextField_Filter"); + } + } + + private bool IsValid() + { + return names != null; + } + + private void CreateStyles() + { + if (style0 != null) + return; + + style0 = new GUIStyle(GUI.skin.box) + { + stretchWidth = true, + alignment = TextAnchor.MiddleLeft, + richText = true + }; + + style1 = new GUIStyle(style0) + { + normal = { background = null } + }; + } + } +} \ No newline at end of file diff --git a/Editor/Windows/EditorWindowStringToType.cs.meta b/Editor/Windows/EditorWindowStringToType.cs.meta new file mode 100644 index 0000000..668092e --- /dev/null +++ b/Editor/Windows/EditorWindowStringToType.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 19592f952a40459f9f1cb769f00b7c6e +timeCreated: 1590404869 \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 39af52c..0000000 --- a/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# README # - -This README would normally document whatever steps are necessary to get your application up and running. - -### What is this repository for? ### - -* Quick summary -* Version -* [Learn Markdown](https://bitbucket.org/tutorials/markdowndemo) - -### How do I get set up? ### - -* Summary of set up -* Configuration -* Dependencies -* Database configuration -* How to run tests -* Deployment instructions - -### Contribution guidelines ### - -* Writing tests -* Code review -* Other guidelines - -### Who do I talk to? ### - -* Repo owner or admin -* Other community or team contact \ No newline at end of file diff --git a/Runtime.meta b/Runtime.meta new file mode 100644 index 0000000..ceed9e3 --- /dev/null +++ b/Runtime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d921bcc192de526448a4f541810e91ce +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AbstractMethodAttribute.cs b/Runtime/AbstractMethodAttribute.cs new file mode 100644 index 0000000..c0f7253 --- /dev/null +++ b/Runtime/AbstractMethodAttribute.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace Module.Inspector +{ + public abstract class AbstractMethodAttribute : PropertyAttribute + { + public abstract EMethodType Type { get; } + } +} \ No newline at end of file diff --git a/Runtime/AbstractMethodAttribute.cs.meta b/Runtime/AbstractMethodAttribute.cs.meta new file mode 100644 index 0000000..2e84a2b --- /dev/null +++ b/Runtime/AbstractMethodAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04377724af9c50941a4132e012a0304b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AbstractPropertyAttribute.cs b/Runtime/AbstractPropertyAttribute.cs new file mode 100644 index 0000000..1e8ac86 --- /dev/null +++ b/Runtime/AbstractPropertyAttribute.cs @@ -0,0 +1,9 @@ +using UnityEngine; + +namespace Module.Inspector +{ + public abstract class AbstractPropertyAttribute : PropertyAttribute + { + public abstract EPropertyType Type { get; } + } +} \ No newline at end of file diff --git a/Runtime/AbstractPropertyAttribute.cs.meta b/Runtime/AbstractPropertyAttribute.cs.meta new file mode 100644 index 0000000..3f1f0ff --- /dev/null +++ b/Runtime/AbstractPropertyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fcc8a63054c4c0d4cbae89798c54514d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifierMethodAttribute.cs b/Runtime/AccessModifierMethodAttribute.cs new file mode 100644 index 0000000..9ee095b --- /dev/null +++ b/Runtime/AccessModifierMethodAttribute.cs @@ -0,0 +1,7 @@ +namespace Module.Inspector +{ + public abstract class AccessModifierMethodAttribute : AbstractMethodAttribute + { + public override EMethodType Type => EMethodType.AccessModifier; + } +} \ No newline at end of file diff --git a/Runtime/AccessModifierMethodAttribute.cs.meta b/Runtime/AccessModifierMethodAttribute.cs.meta new file mode 100644 index 0000000..0a98d60 --- /dev/null +++ b/Runtime/AccessModifierMethodAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 04a29c505958a284b999d162c4a6b245 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifierPropertyAttribute.cs b/Runtime/AccessModifierPropertyAttribute.cs new file mode 100644 index 0000000..9f8374c --- /dev/null +++ b/Runtime/AccessModifierPropertyAttribute.cs @@ -0,0 +1,7 @@ +namespace Module.Inspector +{ + public abstract class AccessModifierPropertyAttribute : AbstractPropertyAttribute + { + public override EPropertyType Type => EPropertyType.AccessModifier; + } +} \ No newline at end of file diff --git a/Runtime/AccessModifierPropertyAttribute.cs.meta b/Runtime/AccessModifierPropertyAttribute.cs.meta new file mode 100644 index 0000000..20bed0f --- /dev/null +++ b/Runtime/AccessModifierPropertyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d160dad70565d5142b47e2eb9d1f9fe1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers.meta b/Runtime/AccessModifiers.meta new file mode 100644 index 0000000..d8b1cc2 --- /dev/null +++ b/Runtime/AccessModifiers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c9b1735cf143c104f80cd60f19678e5b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/Disable.cs b/Runtime/AccessModifiers/Disable.cs new file mode 100644 index 0000000..f95acd7 --- /dev/null +++ b/Runtime/AccessModifiers/Disable.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class Disable : AccessModifierPropertyAttribute + { + [Preserve] + public Disable() + { + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/Disable.cs.meta b/Runtime/AccessModifiers/Disable.cs.meta new file mode 100644 index 0000000..383bdaa --- /dev/null +++ b/Runtime/AccessModifiers/Disable.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 37a1b5b78d13d24498eeb5c4eb638eaa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/DisableField.cs b/Runtime/AccessModifiers/DisableField.cs new file mode 100644 index 0000000..67d6daf --- /dev/null +++ b/Runtime/AccessModifiers/DisableField.cs @@ -0,0 +1,24 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class DisableField : AccessModifierPropertyAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + public DisableField(string fieldName) + { + this.fieldName = fieldName; + } + + public DisableField(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/DisableField.cs.meta b/Runtime/AccessModifiers/DisableField.cs.meta new file mode 100644 index 0000000..0460e4b --- /dev/null +++ b/Runtime/AccessModifiers/DisableField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dc1cbe4502a3d8949b359c756b1b2d76 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/DisableFieldInPlayMode.cs b/Runtime/AccessModifiers/DisableFieldInPlayMode.cs new file mode 100644 index 0000000..ab2d498 --- /dev/null +++ b/Runtime/AccessModifiers/DisableFieldInPlayMode.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class DisableFieldInPlayMode : AccessModifierPropertyAttribute + { + [Preserve] + public DisableFieldInPlayMode() + { + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/DisableFieldInPlayMode.cs.meta b/Runtime/AccessModifiers/DisableFieldInPlayMode.cs.meta new file mode 100644 index 0000000..745cb22 --- /dev/null +++ b/Runtime/AccessModifiers/DisableFieldInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 880b640fbf3cf924eb280d74e2c6c247 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/DisableMethod.cs b/Runtime/AccessModifiers/DisableMethod.cs new file mode 100644 index 0000000..2ab77cd --- /dev/null +++ b/Runtime/AccessModifiers/DisableMethod.cs @@ -0,0 +1,24 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class DisableMethod : AccessModifierMethodAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + public DisableMethod(string fieldName) + { + this.fieldName = fieldName; + } + + public DisableMethod(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/DisableMethod.cs.meta b/Runtime/AccessModifiers/DisableMethod.cs.meta new file mode 100644 index 0000000..56780a7 --- /dev/null +++ b/Runtime/AccessModifiers/DisableMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3bd54811567361b45b1c8943fd0a5b78 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/DisableMethodInPlayMode.cs b/Runtime/AccessModifiers/DisableMethodInPlayMode.cs new file mode 100644 index 0000000..160e240 --- /dev/null +++ b/Runtime/AccessModifiers/DisableMethodInPlayMode.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class DisableMethodInPlayMode : AccessModifierMethodAttribute + { + [Preserve] + public DisableMethodInPlayMode() + { + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/DisableMethodInPlayMode.cs.meta b/Runtime/AccessModifiers/DisableMethodInPlayMode.cs.meta new file mode 100644 index 0000000..5ee7880 --- /dev/null +++ b/Runtime/AccessModifiers/DisableMethodInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 591693d337f993c4db5f8aff7857e485 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/EnableField.cs b/Runtime/AccessModifiers/EnableField.cs new file mode 100644 index 0000000..fce2b62 --- /dev/null +++ b/Runtime/AccessModifiers/EnableField.cs @@ -0,0 +1,24 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class EnableField : AccessModifierPropertyAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + public EnableField(string fieldName) + { + this.fieldName = fieldName; + } + + public EnableField(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/EnableField.cs.meta b/Runtime/AccessModifiers/EnableField.cs.meta new file mode 100644 index 0000000..f253302 --- /dev/null +++ b/Runtime/AccessModifiers/EnableField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8867c9625eae27745be94b8600b7a556 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/EnableFieldInPlayMode.cs b/Runtime/AccessModifiers/EnableFieldInPlayMode.cs new file mode 100644 index 0000000..ca7c0a6 --- /dev/null +++ b/Runtime/AccessModifiers/EnableFieldInPlayMode.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class EnableFieldInPlayMode : AccessModifierPropertyAttribute + { + [Preserve] + public EnableFieldInPlayMode() + { + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/EnableFieldInPlayMode.cs.meta b/Runtime/AccessModifiers/EnableFieldInPlayMode.cs.meta new file mode 100644 index 0000000..a9b151a --- /dev/null +++ b/Runtime/AccessModifiers/EnableFieldInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6c2b1ef19f320274da63ac2b5bd52897 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/EnableMethod.cs b/Runtime/AccessModifiers/EnableMethod.cs new file mode 100644 index 0000000..b034c25 --- /dev/null +++ b/Runtime/AccessModifiers/EnableMethod.cs @@ -0,0 +1,24 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class EnableMethod : AccessModifierMethodAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + public EnableMethod(string fieldName) + { + this.fieldName = fieldName; + } + + public EnableMethod(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/EnableMethod.cs.meta b/Runtime/AccessModifiers/EnableMethod.cs.meta new file mode 100644 index 0000000..1513148 --- /dev/null +++ b/Runtime/AccessModifiers/EnableMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 097d79c03a17a8349a74c645f098b8fa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/EnableMethodInPlayMode.cs b/Runtime/AccessModifiers/EnableMethodInPlayMode.cs new file mode 100644 index 0000000..ed1536a --- /dev/null +++ b/Runtime/AccessModifiers/EnableMethodInPlayMode.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class EnableMethodInPlayMode : AccessModifierMethodAttribute + { + [Preserve] + public EnableMethodInPlayMode() + { + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/EnableMethodInPlayMode.cs.meta b/Runtime/AccessModifiers/EnableMethodInPlayMode.cs.meta new file mode 100644 index 0000000..a4b74e8 --- /dev/null +++ b/Runtime/AccessModifiers/EnableMethodInPlayMode.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5a066db4471bd1249a6f7efa5d6ccde8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/HideField.cs b/Runtime/AccessModifiers/HideField.cs new file mode 100644 index 0000000..9db3294 --- /dev/null +++ b/Runtime/AccessModifiers/HideField.cs @@ -0,0 +1,30 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class HideField : AccessModifierPropertyAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + [Preserve] + public HideField() + { + } + + public HideField(string fieldName) + { + this.fieldName = fieldName; + } + + public HideField(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/HideField.cs.meta b/Runtime/AccessModifiers/HideField.cs.meta new file mode 100644 index 0000000..10ae6c5 --- /dev/null +++ b/Runtime/AccessModifiers/HideField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 840e7f4913f24ef4b849a5dbba6d5e62 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/HideInNormalInspector.cs b/Runtime/AccessModifiers/HideInNormalInspector.cs new file mode 100644 index 0000000..98635fe --- /dev/null +++ b/Runtime/AccessModifiers/HideInNormalInspector.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = true, Inherited = true)] + public sealed class HideInNormalInspector : AccessModifierPropertyAttribute + { + [Preserve] + public HideInNormalInspector() + { + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/HideInNormalInspector.cs.meta b/Runtime/AccessModifiers/HideInNormalInspector.cs.meta new file mode 100644 index 0000000..5720e97 --- /dev/null +++ b/Runtime/AccessModifiers/HideInNormalInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fedaa2e21153a9749b8e3267973ba1ba +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/HideMethod.cs b/Runtime/AccessModifiers/HideMethod.cs new file mode 100644 index 0000000..3af86f1 --- /dev/null +++ b/Runtime/AccessModifiers/HideMethod.cs @@ -0,0 +1,30 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class HideMethod : AccessModifierMethodAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + [Preserve] + public HideMethod() + { + } + + public HideMethod(string fieldName) + { + this.fieldName = fieldName; + } + + public HideMethod(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/HideMethod.cs.meta b/Runtime/AccessModifiers/HideMethod.cs.meta new file mode 100644 index 0000000..52ed8c6 --- /dev/null +++ b/Runtime/AccessModifiers/HideMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b2557b3cc395e5747940128702bfbaac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/ShowField.cs b/Runtime/AccessModifiers/ShowField.cs new file mode 100644 index 0000000..24ce26f --- /dev/null +++ b/Runtime/AccessModifiers/ShowField.cs @@ -0,0 +1,24 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class ShowField : AccessModifierPropertyAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + public ShowField(string fieldName) + { + this.fieldName = fieldName; + } + + public ShowField(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/ShowField.cs.meta b/Runtime/AccessModifiers/ShowField.cs.meta new file mode 100644 index 0000000..0b45414 --- /dev/null +++ b/Runtime/AccessModifiers/ShowField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6db89ad9a06f94d468f564b9b4866208 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/AccessModifiers/ShowMethod.cs b/Runtime/AccessModifiers/ShowMethod.cs new file mode 100644 index 0000000..5e9e433 --- /dev/null +++ b/Runtime/AccessModifiers/ShowMethod.cs @@ -0,0 +1,24 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class ShowMethod : AccessModifierMethodAttribute + { + public readonly string fieldName; + public readonly bool useFieldValue; + public readonly object fieldValue; + + public ShowMethod(string fieldName) + { + this.fieldName = fieldName; + } + + public ShowMethod(string fieldName, object fieldValue) + { + this.fieldName = fieldName; + this.fieldValue = fieldValue; + useFieldValue = true; + } + } +} \ No newline at end of file diff --git a/Runtime/AccessModifiers/ShowMethod.cs.meta b/Runtime/AccessModifiers/ShowMethod.cs.meta new file mode 100644 index 0000000..56f81da --- /dev/null +++ b/Runtime/AccessModifiers/ShowMethod.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8c133d0f0de53b74c9ddac89e5be9a9b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/DecoratorMethodAttribute.cs b/Runtime/DecoratorMethodAttribute.cs new file mode 100644 index 0000000..df8775b --- /dev/null +++ b/Runtime/DecoratorMethodAttribute.cs @@ -0,0 +1,7 @@ +namespace Module.Inspector +{ + public abstract class DecoratorMethodAttribute : AbstractMethodAttribute + { + public override EMethodType Type => EMethodType.Decorator; + } +} \ No newline at end of file diff --git a/Runtime/DecoratorMethodAttribute.cs.meta b/Runtime/DecoratorMethodAttribute.cs.meta new file mode 100644 index 0000000..4aa079a --- /dev/null +++ b/Runtime/DecoratorMethodAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: bcb003fc832a59343bf474a0ec712288 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Decorators.meta b/Runtime/Decorators.meta new file mode 100644 index 0000000..9ed4c7f --- /dev/null +++ b/Runtime/Decorators.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d33dd1df7b837144bb86f9322b67e1b2 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Decorators/HorizontalLine.cs b/Runtime/Decorators/HorizontalLine.cs new file mode 100644 index 0000000..b043f05 --- /dev/null +++ b/Runtime/Decorators/HorizontalLine.cs @@ -0,0 +1,22 @@ +using System; +using UnityEngine; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class HorizontalLine : PropertyAttribute + { + public readonly string title; + + [Preserve] + public HorizontalLine() + { + } + + public HorizontalLine(string title) + { + this.title = title; + } + } +} \ No newline at end of file diff --git a/Runtime/Decorators/HorizontalLine.cs.meta b/Runtime/Decorators/HorizontalLine.cs.meta new file mode 100644 index 0000000..a4184f4 --- /dev/null +++ b/Runtime/Decorators/HorizontalLine.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f60560b1c40c2234199477a1321eb1c9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Decorators/MethodHeader.cs b/Runtime/Decorators/MethodHeader.cs new file mode 100644 index 0000000..8e22c74 --- /dev/null +++ b/Runtime/Decorators/MethodHeader.cs @@ -0,0 +1,21 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class MethodHeader : DecoratorMethodAttribute + { + public readonly string title; + + [Preserve] + public MethodHeader() + { + } + + public MethodHeader(string title) + { + this.title = title; + } + } +} \ No newline at end of file diff --git a/Runtime/Decorators/MethodHeader.cs.meta b/Runtime/Decorators/MethodHeader.cs.meta new file mode 100644 index 0000000..1f83f91 --- /dev/null +++ b/Runtime/Decorators/MethodHeader.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1387053ae5892314bb59f3a0d3769ea6 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/DrawerMethodAttribute.cs b/Runtime/DrawerMethodAttribute.cs new file mode 100644 index 0000000..f6f24bf --- /dev/null +++ b/Runtime/DrawerMethodAttribute.cs @@ -0,0 +1,7 @@ +namespace Module.Inspector +{ + public abstract class DrawerMethodAttribute : AbstractMethodAttribute + { + public override EMethodType Type => EMethodType.Drawer; + } +} \ No newline at end of file diff --git a/Runtime/DrawerMethodAttribute.cs.meta b/Runtime/DrawerMethodAttribute.cs.meta new file mode 100644 index 0000000..2938475 --- /dev/null +++ b/Runtime/DrawerMethodAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ddfbd813bee41bb4aaea197f66ceee5a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/DrawerPropertyAttribute.cs b/Runtime/DrawerPropertyAttribute.cs new file mode 100644 index 0000000..808d1de --- /dev/null +++ b/Runtime/DrawerPropertyAttribute.cs @@ -0,0 +1,7 @@ +namespace Module.Inspector +{ + public abstract class DrawerPropertyAttribute : AbstractPropertyAttribute + { + public override EPropertyType Type => EPropertyType.Drawer; + } +} \ No newline at end of file diff --git a/Runtime/DrawerPropertyAttribute.cs.meta b/Runtime/DrawerPropertyAttribute.cs.meta new file mode 100644 index 0000000..d7cb478 --- /dev/null +++ b/Runtime/DrawerPropertyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a5f34a2a2293d584aa96e682ddb6233b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers.meta b/Runtime/Drawers.meta new file mode 100644 index 0000000..5d45569 --- /dev/null +++ b/Runtime/Drawers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: fbe40bd4dc6215f45af89fd2066fcada +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/EnumFlag.cs b/Runtime/Drawers/EnumFlag.cs new file mode 100644 index 0000000..88f6820 --- /dev/null +++ b/Runtime/Drawers/EnumFlag.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class EnumFlag : DrawerPropertyAttribute + { + [Preserve] + public EnumFlag() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/EnumFlag.cs.meta b/Runtime/Drawers/EnumFlag.cs.meta new file mode 100644 index 0000000..00a47f9 --- /dev/null +++ b/Runtime/Drawers/EnumFlag.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7a13196e6dff9404d81a3911bb06cc55 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/FilePath.cs b/Runtime/Drawers/FilePath.cs new file mode 100644 index 0000000..49625fe --- /dev/null +++ b/Runtime/Drawers/FilePath.cs @@ -0,0 +1,22 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class FilePath : DrawerPropertyAttribute + { + public readonly bool useAbsolute; + public readonly string extension = "*"; + + public FilePath(bool useAbsolute = false) + { + this.useAbsolute = useAbsolute; + } + + public FilePath(string extension, bool useAbsolute = false) + { + this.extension = extension; + this.useAbsolute = useAbsolute; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/FilePath.cs.meta b/Runtime/Drawers/FilePath.cs.meta new file mode 100644 index 0000000..eef8a0a --- /dev/null +++ b/Runtime/Drawers/FilePath.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8d62b72f20cb29b4f9ba3774c21ea275 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/FolderPath.cs b/Runtime/Drawers/FolderPath.cs new file mode 100644 index 0000000..9f5bb41 --- /dev/null +++ b/Runtime/Drawers/FolderPath.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class FolderPath : DrawerPropertyAttribute + { + public readonly bool useAbsolute; + + public FolderPath(bool useAbsolute = false) + { + this.useAbsolute = useAbsolute; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/FolderPath.cs.meta b/Runtime/Drawers/FolderPath.cs.meta new file mode 100644 index 0000000..51156f6 --- /dev/null +++ b/Runtime/Drawers/FolderPath.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 19f4936da040eda458dad2d7ac69efcb +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/IntToEnum.cs b/Runtime/Drawers/IntToEnum.cs new file mode 100644 index 0000000..f34f28b --- /dev/null +++ b/Runtime/Drawers/IntToEnum.cs @@ -0,0 +1,48 @@ +using System; +using Module.Inspector.Utilities; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class IntToEnum : DrawerPropertyAttribute + { + private Type type; + + private readonly string strTypeReplaceWith; + private bool hasTriedFetchReplaceType; + + [Preserve] + public IntToEnum(Type type) + { + this.type = type; + hasTriedFetchReplaceType = true; + } + + [Preserve] + public IntToEnum(Type type, string strTypeReplaceWith) + { + this.type = type; + this.strTypeReplaceWith = strTypeReplaceWith; + } + + public Type GetValidType() + { + if (hasTriedFetchReplaceType) + return type; + + #if UNITY_EDITOR + Type replaceType = ReflectionUtility.GetAnyTypeWithName(strTypeReplaceWith); + #else + Type replaceType = null; + #endif + + hasTriedFetchReplaceType = true; + + if (replaceType != null) + type = replaceType; + + return type; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/IntToEnum.cs.meta b/Runtime/Drawers/IntToEnum.cs.meta new file mode 100644 index 0000000..7c65608 --- /dev/null +++ b/Runtime/Drawers/IntToEnum.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: d54a749b500e802439618671a142c976 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/IntToLayer.cs b/Runtime/Drawers/IntToLayer.cs new file mode 100644 index 0000000..0046f1d --- /dev/null +++ b/Runtime/Drawers/IntToLayer.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class IntToLayer : DrawerPropertyAttribute + { + [Preserve] + public IntToLayer() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/IntToLayer.cs.meta b/Runtime/Drawers/IntToLayer.cs.meta new file mode 100644 index 0000000..1259264 --- /dev/null +++ b/Runtime/Drawers/IntToLayer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 210d910f4eeed444e876bfedd8f6967b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/MethodButton.cs b/Runtime/Drawers/MethodButton.cs new file mode 100644 index 0000000..9bbedd9 --- /dev/null +++ b/Runtime/Drawers/MethodButton.cs @@ -0,0 +1,21 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)] + public sealed class MethodButton: DrawerMethodAttribute + { + public readonly string name; + + [Preserve] + public MethodButton() + { + } + + public MethodButton(string name) + { + this.name = name; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/MethodButton.cs.meta b/Runtime/Drawers/MethodButton.cs.meta new file mode 100644 index 0000000..165f7e0 --- /dev/null +++ b/Runtime/Drawers/MethodButton.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: aa939647376a39e4dae0c9e54bba3133 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/Naming.cs b/Runtime/Drawers/Naming.cs new file mode 100644 index 0000000..1b755b3 --- /dev/null +++ b/Runtime/Drawers/Naming.cs @@ -0,0 +1,43 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class Naming : DrawerPropertyAttribute + { + public enum EPatternType : byte + { + /// + /// Camel casing: thisIsCamelCasing + /// + CamelCasing, + /// + /// Pascal casing: ThisIsPascalCasing + /// + PascalCasing, + /// + /// Snake casing: this_is_snake_casing + /// + SnakeCasing, + /// + /// Snake casing: THIS_IS_SNAKE_CASING_WITH_ALL_CAPS + /// + SnakeCasingAllCaps, + /// + /// Kebab casing: this-is-kebab-casing + /// + KebabCasing, + /// + /// Kebab casing: THIS_IS_KEBAB_CASING_WITH_ALL_CAPS + /// + KebabCasingAllCaps + } + + public readonly EPatternType type; + + public Naming(EPatternType type) + { + this.type = type; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/Naming.cs.meta b/Runtime/Drawers/Naming.cs.meta new file mode 100644 index 0000000..3aa1d0e --- /dev/null +++ b/Runtime/Drawers/Naming.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f99c4aa6447ed24787b1d125c4ae6bf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/Percentage.cs b/Runtime/Drawers/Percentage.cs new file mode 100644 index 0000000..b8fb83c --- /dev/null +++ b/Runtime/Drawers/Percentage.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class Percentage : DrawerPropertyAttribute + { + [Preserve] + public Percentage() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/Percentage.cs.meta b/Runtime/Drawers/Percentage.cs.meta new file mode 100644 index 0000000..162e7a9 --- /dev/null +++ b/Runtime/Drawers/Percentage.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dfe545e7a0cb02148bd45f51f9474a43 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/PopupFromConst.cs b/Runtime/Drawers/PopupFromConst.cs new file mode 100644 index 0000000..603ea8b --- /dev/null +++ b/Runtime/Drawers/PopupFromConst.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class PopupFromConst : DrawerPropertyAttribute + { + public readonly Type type; + + public PopupFromConst(Type type) + { + this.type = type; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/PopupFromConst.cs.meta b/Runtime/Drawers/PopupFromConst.cs.meta new file mode 100644 index 0000000..be25157 --- /dev/null +++ b/Runtime/Drawers/PopupFromConst.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d8559005b0cb44438da12adccfcaa5a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/QuaternionToEuler.cs b/Runtime/Drawers/QuaternionToEuler.cs new file mode 100644 index 0000000..9782457 --- /dev/null +++ b/Runtime/Drawers/QuaternionToEuler.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class QuaternionToEuler : DrawerPropertyAttribute + { + [Preserve] + public QuaternionToEuler() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/QuaternionToEuler.cs.meta b/Runtime/Drawers/QuaternionToEuler.cs.meta new file mode 100644 index 0000000..4ebc19b --- /dev/null +++ b/Runtime/Drawers/QuaternionToEuler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5639ab9888faa7943b8675eb61fa7f1f +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/SceneDropdown.cs b/Runtime/Drawers/SceneDropdown.cs new file mode 100644 index 0000000..f2d15e3 --- /dev/null +++ b/Runtime/Drawers/SceneDropdown.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class SceneDropdown : DrawerPropertyAttribute + { + [Preserve] + public SceneDropdown() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/SceneDropdown.cs.meta b/Runtime/Drawers/SceneDropdown.cs.meta new file mode 100644 index 0000000..f13af05 --- /dev/null +++ b/Runtime/Drawers/SceneDropdown.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: adc159b87625ef3468b0877d5c1e88d9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/Slider.cs b/Runtime/Drawers/Slider.cs new file mode 100644 index 0000000..7eb4d22 --- /dev/null +++ b/Runtime/Drawers/Slider.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class Slider : DrawerPropertyAttribute + { + [Preserve] + public Slider() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/Slider.cs.meta b/Runtime/Drawers/Slider.cs.meta new file mode 100644 index 0000000..a33b0db --- /dev/null +++ b/Runtime/Drawers/Slider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ac2ff972f40468140919d5b8706cabff +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/StringToField.cs b/Runtime/Drawers/StringToField.cs new file mode 100644 index 0000000..d6a395d --- /dev/null +++ b/Runtime/Drawers/StringToField.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class StringToField : DrawerPropertyAttribute + { + public readonly Type type; + + public StringToField(Type type) + { + this.type = type; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/StringToField.cs.meta b/Runtime/Drawers/StringToField.cs.meta new file mode 100644 index 0000000..0eabc6c --- /dev/null +++ b/Runtime/Drawers/StringToField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dbd081def12467742a3bf05946dc5d40 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/StringToType.cs b/Runtime/Drawers/StringToType.cs new file mode 100644 index 0000000..034726f --- /dev/null +++ b/Runtime/Drawers/StringToType.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class StringToType : DrawerPropertyAttribute + { + public readonly Type assignableFrom; + + public StringToType(Type assignableFrom) + { + this.assignableFrom = assignableFrom; + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/StringToType.cs.meta b/Runtime/Drawers/StringToType.cs.meta new file mode 100644 index 0000000..63e7d47 --- /dev/null +++ b/Runtime/Drawers/StringToType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7870b2ad7f2ad67469d6787848cc70de +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Drawers/UrlGoTo.cs b/Runtime/Drawers/UrlGoTo.cs new file mode 100644 index 0000000..6a594a7 --- /dev/null +++ b/Runtime/Drawers/UrlGoTo.cs @@ -0,0 +1,14 @@ +using System; +using UnityEngine.Scripting; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class UrlGoTo : DrawerPropertyAttribute + { + [Preserve] + public UrlGoTo() + { + } + } +} \ No newline at end of file diff --git a/Runtime/Drawers/UrlGoTo.cs.meta b/Runtime/Drawers/UrlGoTo.cs.meta new file mode 100644 index 0000000..5b52463 --- /dev/null +++ b/Runtime/Drawers/UrlGoTo.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ac9efabc5f0547f43921c2804bb85220 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Enums.meta b/Runtime/Enums.meta new file mode 100644 index 0000000..9896f1c --- /dev/null +++ b/Runtime/Enums.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9debf833b42a21c46b4835cd0c6b7fd6 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Enums/EMethodType.cs b/Runtime/Enums/EMethodType.cs new file mode 100644 index 0000000..e703fec --- /dev/null +++ b/Runtime/Enums/EMethodType.cs @@ -0,0 +1,9 @@ +namespace Module.Inspector +{ + public enum EMethodType : byte + { + Drawer, + AccessModifier, + Decorator + } +} \ No newline at end of file diff --git a/Runtime/Enums/EMethodType.cs.meta b/Runtime/Enums/EMethodType.cs.meta new file mode 100644 index 0000000..7dd88fa --- /dev/null +++ b/Runtime/Enums/EMethodType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9e2a688cc0dd10c4baccd1761f96e149 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Enums/EPropertyType.cs b/Runtime/Enums/EPropertyType.cs new file mode 100644 index 0000000..6c88df4 --- /dev/null +++ b/Runtime/Enums/EPropertyType.cs @@ -0,0 +1,9 @@ +namespace Module.Inspector +{ + public enum EPropertyType : byte + { + Drawer, + ValueModifier, + AccessModifier + } +} \ No newline at end of file diff --git a/Runtime/Enums/EPropertyType.cs.meta b/Runtime/Enums/EPropertyType.cs.meta new file mode 100644 index 0000000..8a70cd3 --- /dev/null +++ b/Runtime/Enums/EPropertyType.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0103f9597762e174c9ad5b2917da82c1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Module.Inspector.asmdef b/Runtime/Module.Inspector.asmdef new file mode 100644 index 0000000..bf9507d --- /dev/null +++ b/Runtime/Module.Inspector.asmdef @@ -0,0 +1,14 @@ +{ + "name": "Module.Inspector", + "rootNamespace": "Module.Inspector", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Runtime/Module.Inspector.asmdef.meta b/Runtime/Module.Inspector.asmdef.meta new file mode 100644 index 0000000..0a959de --- /dev/null +++ b/Runtime/Module.Inspector.asmdef.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: a58be6d007e5e434ebc9bf7f902990a7 +AssemblyDefinitionImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utilities.meta b/Runtime/Utilities.meta new file mode 100644 index 0000000..5e75427 --- /dev/null +++ b/Runtime/Utilities.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7b44fa4b849c82448a7c45c2c3cecd76 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Utilities/ReflectionUtility.cs b/Runtime/Utilities/ReflectionUtility.cs new file mode 100644 index 0000000..dcbc138 --- /dev/null +++ b/Runtime/Utilities/ReflectionUtility.cs @@ -0,0 +1,231 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; + +namespace Module.Inspector.Utilities +{ + internal static class ReflectionUtility + { + #if UNITY_EDITOR + public static T GetValue(object obj, string name) + { + return GetValue(obj, name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + } + + public static T GetValue(object obj, string name, BindingFlags flags) + { + FieldInfo field = obj.GetType().GetField(name, flags); + return field != null ? (T)field.GetValue(obj) : default; + } + + public static T GetValue(object obj, FieldInfo field) + { + return field != null ? (T)field.GetValue(obj) : default; + } + + public static T[] GetArrayValue(object obj, string name) + { + return GetArrayValue(obj, name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + } + + public static T[] GetArrayValue(object obj, string name, BindingFlags flags) + { + FieldInfo field = obj.GetType().GetField(name, flags); + return field != null ? (T[])field.GetValue(obj) : default; + } + + public static void SetValue(object obj, string name, T value) + { + SetValue(obj, name, value, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + } + + public static void SetValue(object obj, string name, T value, BindingFlags flags) + { + FieldInfo field = obj.GetType().GetField(name, flags); + + if (field != null) + field.SetValue(obj, value); + } + + public static void SetValue(object obj, T value, FieldInfo field) + { + field.SetValue(obj, value); + } + + public static void SetValue(object obj, string name, T[] value) + { + SetValue(obj, name, value, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + } + + public static void SetValue(object obj, string name, T[] value, BindingFlags flags) + { + FieldInfo field = obj.GetType().GetField(name, flags); + + if (field != null) + field.SetValue(obj, value); + } + + public static FieldInfo[] GetFields(BindingFlags flags) + { + return typeof(T).GetFields(flags); + } + + public static FieldInfo[] GetFields(Type type, BindingFlags flags) + { + return type.GetFields(flags); + } + + public static FieldInfo[] GetFields(Type type, BindingFlags flags, string[] ignoreFields) + { + var fields = new List(GetFields(type, flags)); + + for (int i = fields.Count - 1; i >= 0; i--) + { + FieldInfo fi = fields[i]; + + for (var j = 0; j < ignoreFields.Length; j++) + { + if (!fi.Name.Equals(ignoreFields[j])) + continue; + + fields.RemoveAt(i); + break; + } + } + + return fields.ToArray(); + } + + public static bool HasField(object obj, string name) + { + return HasField(obj, name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + } + + public static bool HasField(object obj, string name, BindingFlags flags) + { + FieldInfo field = obj.GetType().GetField(name, flags); + return field != null && field.FieldType.IsAssignableFrom(typeof(T)); + } + + public static T GetPropertyValue(object obj, string name) + { + return GetPropertyValue(obj, name, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + } + + public static T GetPropertyValue(object obj, string name, BindingFlags flags) + { + PropertyInfo pi = obj.GetType().GetProperty(name, flags); + return pi != null ? (T)pi.GetValue(obj, null) : default(T); + } + + public static void SetPropertyValue(object obj, string name, T value) + { + SetPropertyValue(obj, name, value, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + } + + public static void SetPropertyValue(object obj, string name, T value, BindingFlags flags) + { + PropertyInfo pi = obj.GetType().GetProperty(name, flags); + + if (pi != null) + pi.SetValue(obj, value, null); + } + + public static bool HasAttribute(FieldInfo field, System.Type attributeType) + { + // WSU: Needs the explicit conversion + var objs = (object[])field.GetCustomAttributes(attributeType, true); + return objs.Length != 0; + } + + public static bool HasAttributeTitle(FieldInfo field) + { + return HasAttribute(field, typeof(HeaderAttribute)); + } + + public static T GetAttribute(FieldInfo field) + { + // WSU: Needs the explicit conversion + var objs = (object[])field.GetCustomAttributes(typeof(T), true); + + if (objs.Length != 0) + return (T)objs[0]; + + return default; + } + + public static string GetAttributeTitle(FieldInfo field) + { + // WSU: Needs the explicit conversion + var objs = (object[])field.GetCustomAttributes(typeof(HeaderAttribute), true); + + if (objs.Length == 0) + return "Unknown"; + + Type type = objs[0].GetType(); + return (string)type.GetFields()[0].GetValue(objs[0]); + } + + public static Type[] GetTypesWith(System.Type type) + { + Type[] types = type.Assembly.GetTypes(); + var arr = new List(); + + for (var i = 0; i < types.Length; i++) + { + Type t = types[i]; + + if (t == type || type.IsAssignableFrom(t)) + arr.Add(t); + } + + return arr.ToArray(); + } + + public static Type GetAnyTypeWithName(string typeName) + { + Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + for (var i = 0; i < assemblies.Length; i++) + { + Type type = assemblies[i].GetType(typeName); + + if (type != null) + return type; + } + + return null; + } + + public static object Create(Type type) + { + return Activator.CreateInstance(type); + } + + public static void CopyFields(object source, object destination) + { + // Get fields + FieldInfo[] sourceFields = GetFields(source.GetType(), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + FieldInfo[] destinationFields = GetFields(destination.GetType(), BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); + + // Start setting fields (if of same type) + for (var i = 0; i < sourceFields.Length; i++) + { + FieldInfo fiSource = sourceFields[i]; + + for (var j = 0; j < destinationFields.Length; j++) + { + FieldInfo fiDestination = destinationFields[j]; + + if (fiSource.Name.Equals(fiDestination.Name) && fiSource.FieldType == fiDestination.FieldType) + { + fiDestination.SetValue(destination, fiSource.GetValue(source)); + break; + } + } + } + } + #endif + } +} \ No newline at end of file diff --git a/Runtime/Utilities/ReflectionUtility.cs.meta b/Runtime/Utilities/ReflectionUtility.cs.meta new file mode 100644 index 0000000..051a322 --- /dev/null +++ b/Runtime/Utilities/ReflectionUtility.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 347153fa5a0849c6a320237332288c61 +timeCreated: 1594144995 \ No newline at end of file diff --git a/Runtime/ValueModifierPropertyAttribute.cs b/Runtime/ValueModifierPropertyAttribute.cs new file mode 100644 index 0000000..ffc6f29 --- /dev/null +++ b/Runtime/ValueModifierPropertyAttribute.cs @@ -0,0 +1,7 @@ +namespace Module.Inspector +{ + public abstract class ValueModifierPropertyAttribute : AbstractPropertyAttribute + { + public override EPropertyType Type => EPropertyType.ValueModifier; + } +} \ No newline at end of file diff --git a/Runtime/ValueModifierPropertyAttribute.cs.meta b/Runtime/ValueModifierPropertyAttribute.cs.meta new file mode 100644 index 0000000..0c9f73d --- /dev/null +++ b/Runtime/ValueModifierPropertyAttribute.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9d6d384fd2f87fa41ba6dfd9b200de3a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ValueModifiers.meta b/Runtime/ValueModifiers.meta new file mode 100644 index 0000000..49401e6 --- /dev/null +++ b/Runtime/ValueModifiers.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9151495f1ed9ccb4391516420e50d18c +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ValueModifiers/ArrayIndex.cs b/Runtime/ValueModifiers/ArrayIndex.cs new file mode 100644 index 0000000..78ecb92 --- /dev/null +++ b/Runtime/ValueModifiers/ArrayIndex.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class ArrayIndex : ValueModifierPropertyAttribute + { + public readonly string fieldName; + + public ArrayIndex(string fieldName) + { + this.fieldName = fieldName; + } + } +} \ No newline at end of file diff --git a/Runtime/ValueModifiers/ArrayIndex.cs.meta b/Runtime/ValueModifiers/ArrayIndex.cs.meta new file mode 100644 index 0000000..65c008b --- /dev/null +++ b/Runtime/ValueModifiers/ArrayIndex.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0582e0b83200e0f41a362856b299c773 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ValueModifiers/LargerThanField.cs b/Runtime/ValueModifiers/LargerThanField.cs new file mode 100644 index 0000000..385b95c --- /dev/null +++ b/Runtime/ValueModifiers/LargerThanField.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class LargerThanField : ValueModifierPropertyAttribute + { + public readonly string fieldName; + + public LargerThanField(string fieldName) + { + this.fieldName = fieldName; + } + } +} \ No newline at end of file diff --git a/Runtime/ValueModifiers/LargerThanField.cs.meta b/Runtime/ValueModifiers/LargerThanField.cs.meta new file mode 100644 index 0000000..17abc4a --- /dev/null +++ b/Runtime/ValueModifiers/LargerThanField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5852536dc58cd4d448cb4409df39bcf7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ValueModifiers/MaxValue.cs b/Runtime/ValueModifiers/MaxValue.cs new file mode 100644 index 0000000..8485903 --- /dev/null +++ b/Runtime/ValueModifiers/MaxValue.cs @@ -0,0 +1,24 @@ +using System; +using UnityEngine; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class MaxValue : ValueModifierPropertyAttribute + { + public readonly int intValue; + public readonly float floatValue; + + public MaxValue(int value) + { + intValue = value; + floatValue = value; + } + + public MaxValue(float value) + { + intValue = Mathf.RoundToInt(value); + floatValue = value; + } + } +} \ No newline at end of file diff --git a/Runtime/ValueModifiers/MaxValue.cs.meta b/Runtime/ValueModifiers/MaxValue.cs.meta new file mode 100644 index 0000000..3b8c1a8 --- /dev/null +++ b/Runtime/ValueModifiers/MaxValue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fa22cb1d8cf75d344b2da0b84e5439ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ValueModifiers/MinValue.cs b/Runtime/ValueModifiers/MinValue.cs new file mode 100644 index 0000000..6afef97 --- /dev/null +++ b/Runtime/ValueModifiers/MinValue.cs @@ -0,0 +1,24 @@ +using System; +using UnityEngine; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class MinValue : ValueModifierPropertyAttribute + { + public readonly int intValue; + public readonly float floatValue; + + public MinValue(int value) + { + intValue = value; + floatValue = value; + } + + public MinValue(float value) + { + intValue = Mathf.RoundToInt(value); + floatValue = value; + } + } +} \ No newline at end of file diff --git a/Runtime/ValueModifiers/MinValue.cs.meta b/Runtime/ValueModifiers/MinValue.cs.meta new file mode 100644 index 0000000..092a2bc --- /dev/null +++ b/Runtime/ValueModifiers/MinValue.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c3c28b3d8c494014f9061e5af6800576 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/ValueModifiers/SmallerThanField.cs b/Runtime/ValueModifiers/SmallerThanField.cs new file mode 100644 index 0000000..a4c30df --- /dev/null +++ b/Runtime/ValueModifiers/SmallerThanField.cs @@ -0,0 +1,15 @@ +using System; + +namespace Module.Inspector +{ + [AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = true)] + public sealed class SmallerThanField : ValueModifierPropertyAttribute + { + public readonly string fieldName; + + public SmallerThanField(string fieldName) + { + this.fieldName = fieldName; + } + } +} \ No newline at end of file diff --git a/Runtime/ValueModifiers/SmallerThanField.cs.meta b/Runtime/ValueModifiers/SmallerThanField.cs.meta new file mode 100644 index 0000000..ff65ee0 --- /dev/null +++ b/Runtime/ValueModifiers/SmallerThanField.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6a5c7cdc8fef16c40b2fff63e54cd95e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/package.json b/package.json new file mode 100644 index 0000000..6ff247f --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "com.module.inspector", + "version": "0.2.0", + "displayName": "Module.Inspector", + "description": "Custom inspector with various useful property drawers", + "unity": "2019.2", + "unityRelease": "17f1", + "dependencies": { + }, + "keywords": [ + "Inspector" + ], + "author": { + "name": "Anders Ejlersen", + "email": "anders@ejlersen.info", + "url": "https://www.ejlersen.info" + } +} \ No newline at end of file diff --git a/package.json.meta b/package.json.meta new file mode 100644 index 0000000..a2ada00 --- /dev/null +++ b/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: e6eda6114e728de4fa70c21cdbb3e586 +PackageManifestImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: