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,70 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace InspectorToolkit {
public class CompactVector4Attribute : PropertyAttribute {
public CompactVector4Attribute() {
}
}
}
#if UNITY_EDITOR
namespace InspectorToolkit.Internal {
[CustomPropertyDrawer(typeof(CompactVector4Attribute))]
public class CompactVector4AttributeDrawer : PropertyDrawer {
private const int CHILD_COUNT = 4;
private const float LABEL_WIDTH = 13f;
private const float INDENT_WIDTH = 15f;
private const float CHILD_HORIZONTAL_SPACING = 4f;
private static readonly string[] childPropertyNames = new string[] { "x", "y", "z", "w" };
private bool IsCompactLayout => Screen.width <= 333f;
private bool IsNoLabelLayout => Screen.width <= 240f;
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) {
if(IsCompactLayout) { // Unity Vector2 + Vector3 go multi-line at this point
return EditorGUIUtility.singleLineHeight * 2f + EditorGUIUtility.standardVerticalSpacing;
}
return EditorGUIUtility.singleLineHeight;
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
if(property.propertyType != SerializedPropertyType.Vector4) {
GUI.Label(position, "Error, SerializedProperty must be 'Vector4' type");
return;
}
EditorGUI.BeginProperty(position, label, property);
if(IsCompactLayout) {
EditorGUIUtility.labelWidth = position.width;
}
Rect labelRect = new Rect(position) { height = EditorGUIUtility.singleLineHeight };
Rect fieldRect = EditorGUI.PrefixLabel(labelRect, label);
fieldRect.height = EditorGUIUtility.singleLineHeight;
if(IsCompactLayout) {
fieldRect.y = labelRect.yMax + EditorGUIUtility.standardVerticalSpacing;
fieldRect.x = labelRect.x + (IsNoLabelLayout ? 0f : INDENT_WIDTH); // 15 = single indent
fieldRect.width = position.xMax - fieldRect.xMin;
}
EditorGUIUtility.labelWidth = IsNoLabelLayout ? 0.01f : LABEL_WIDTH;
float childSpacing = IsNoLabelLayout ? CHILD_HORIZONTAL_SPACING / 2f : CHILD_HORIZONTAL_SPACING;
float childWidth = ((fieldRect.width + childSpacing) / CHILD_COUNT) - childSpacing;
for(int i = 0; i < CHILD_COUNT; i++) {
SerializedProperty childProperty = property.FindPropertyRelative(childPropertyNames[i]);
Rect childRect = new Rect(fieldRect);
childRect.width = childWidth; // add spacing
childRect.x += i * (childWidth + childSpacing);
EditorGUI.PropertyField(childRect, childProperty);
}
EditorGUI.EndProperty();
}
}
}
#endif