added more utilty packges

This commit is contained in:
Sebastian Bularca
2026-03-29 18:59:24 +02:00
parent ee97b2fec3
commit 71b432e253
131 changed files with 7674 additions and 54 deletions

View File

@@ -0,0 +1,38 @@
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace InspectorToolkit {
public class OnValueChangedAttribute : PropertyAttribute {
public readonly string methodName;
public OnValueChangedAttribute(string methodName) {
this.methodName = methodName;
}
}
}
#if UNITY_EDITOR
namespace InspectorToolkit.Internal {
[CustomPropertyDrawer(typeof(OnValueChangedAttribute))]
public class OnValueChangedAttributeDrawer : PropertyDrawer {
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
EditorGUI.BeginChangeCheck();
EditorGUI.PropertyField(position, property, label);
if(EditorGUI.EndChangeCheck()) {
property.serializedObject.ApplyModifiedProperties();
Object target = property.serializedObject.targetObject;
string methodName = ((OnValueChangedAttribute)attribute).methodName;
MethodInfo methodInfo = target.GetType().GetMethod(methodName);
if (methodInfo != null) {
methodInfo.Invoke(target, null);
}
else {
Debug.LogError($"No method named '{methodName}' found on {target}", target);
}
}
}
}
}
#endif