0.2.0: Moved into inspector drawer from module.toolbox to module.inspector

This commit is contained in:
Anders Ejlersen 2021-09-18 15:48:14 +02:00
parent 5671c2c754
commit ffec2abdf4
227 changed files with 5306 additions and 29 deletions

View file

@ -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;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 58c23ce231bb093478a6e73290d3f08d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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));
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 33edc75018f0b9a4d9f9e5289c531abd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f430530eb43aa974b8a4273c333c2149
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: dec0cb037cad4194aafd92c44268ede8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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));
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 04a363a4b71b7c94bb9ab276d255e69b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: