Кинуть файл куда угодно, только не в Editor папку.
Использование :
Синтаксис:
Используется csharp
[EnumAlphabeticalSorted]
public KeyCode keyCode;
public KeyCode keyCode;
Синтаксис:
Используется csharp
//Created by Neodrop. mailto:neodrop@unity3d.ru
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public sealed class EnumAlphabeticalSortedAttribute : PropertyAttribute
{
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof (EnumAlphabeticalSortedAttribute))]
public class EnumCustomDrawer : PropertyDrawer
{
private const string StrDelimitter = "/";
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return property.propertyType != SerializedPropertyType.Enum ? 2 + base.GetPropertyHeight(property, label) * 3 : base.GetPropertyHeight(property, label);
}
private void AddDelimitter(GUIContent cnt)
{
if (!string.IsNullOrEmpty(cnt.text))
{
cnt.text = cnt.text[0].ToString().ToUpper() + StrDelimitter + cnt.text;
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if(property.propertyType != SerializedPropertyType.Enum)
{
position.height -= base.GetPropertyHeight(property, label) + 2;
EditorGUI.HelpBox(position, "Use EnumAlphabeticalSortedAttribute for Enum type variables only.", MessageType.Error);
position.height = base.GetPropertyHeight(property, label);
position.y += 2 + base.GetPropertyHeight(property, label)*2;
EditorGUI.PropertyField(position, property, label);
return;
}
List<string> _strs = new List<string>(property.enumNames);
_strs.Sort();
string[] enumNames = _strs.ToArray();
EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
{
GUIContent[] contents = new GUIContent[enumNames.Length];
int contentsCount = contents.Length;
for (int i = 0; i < contentsCount; i++)
{
contents[i] = new GUIContent(enumNames[i]);
AddDelimitter(contents[i]);
}
property.enumValueIndex = EditorGUI.Popup(position, label, property.enumValueIndex, contents);
}
EditorGUI.showMixedValue = false;
}
}
#endif
#endif
using System;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
public sealed class EnumAlphabeticalSortedAttribute : PropertyAttribute
{
}
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof (EnumAlphabeticalSortedAttribute))]
public class EnumCustomDrawer : PropertyDrawer
{
private const string StrDelimitter = "/";
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return property.propertyType != SerializedPropertyType.Enum ? 2 + base.GetPropertyHeight(property, label) * 3 : base.GetPropertyHeight(property, label);
}
private void AddDelimitter(GUIContent cnt)
{
if (!string.IsNullOrEmpty(cnt.text))
{
cnt.text = cnt.text[0].ToString().ToUpper() + StrDelimitter + cnt.text;
}
}
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if(property.propertyType != SerializedPropertyType.Enum)
{
position.height -= base.GetPropertyHeight(property, label) + 2;
EditorGUI.HelpBox(position, "Use EnumAlphabeticalSortedAttribute for Enum type variables only.", MessageType.Error);
position.height = base.GetPropertyHeight(property, label);
position.y += 2 + base.GetPropertyHeight(property, label)*2;
EditorGUI.PropertyField(position, property, label);
return;
}
List<string> _strs = new List<string>(property.enumNames);
_strs.Sort();
string[] enumNames = _strs.ToArray();
EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
{
GUIContent[] contents = new GUIContent[enumNames.Length];
int contentsCount = contents.Length;
for (int i = 0; i < contentsCount; i++)
{
contents[i] = new GUIContent(enumNames[i]);
AddDelimitter(contents[i]);
}
property.enumValueIndex = EditorGUI.Popup(position, label, property.enumValueIndex, contents);
}
EditorGUI.showMixedValue = false;
}
}
#endif
#endif