31 lines
948 B
C#
31 lines
948 B
C#
|
|
#if UNITY_EDITOR
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
using System.Linq;
|
|
|
|
public class AngleSelectorAttribute : PropertyAttribute { }
|
|
|
|
|
|
[CustomPropertyDrawer(typeof(AngleSelectorAttribute))]
|
|
public class CubeInspectorAngle : PropertyDrawer
|
|
{
|
|
private readonly int[] angles = { 0, 90, 180, 270 };
|
|
|
|
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
|
{
|
|
if (property.propertyType == SerializedPropertyType.Integer)
|
|
{
|
|
int currentAngle = property.intValue;
|
|
int selectedIndex = Mathf.Max(0, System.Array.IndexOf(angles, currentAngle));
|
|
selectedIndex = EditorGUI.Popup(position, label.text, selectedIndex, angles.Select(a => a.ToString()).ToArray());
|
|
property.intValue = angles[selectedIndex];
|
|
}
|
|
else
|
|
{
|
|
EditorGUI.LabelField(position, label.text, "Use [AngleSelector] with int.");
|
|
}
|
|
}
|
|
}
|
|
#endif
|