1.5.0: Added IntToLayerMask, marked QuaternionToEuler as obsolete as of 2021 and fixed a couple of bugs
- Drawer: Added IntToLayerMaskAttribute, if a raw int is wanted instead of LayerMask - Drawer: Added option to either use full or short type name, when using SerializeReferenceTo - Extension: Fixed issue, where GetValueType and GetValue for SerializedProperty would throw exceptions, if field is private
This commit is contained in:
parent
ee7326c33a
commit
7d99d62e11
14 changed files with 114 additions and 17 deletions
57
Editor/Drawers/IntToLayerMaskAttributeDrawer.cs
Normal file
57
Editor/Drawers/IntToLayerMaskAttributeDrawer.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(IntToLayerMaskAttribute))]
|
||||
internal sealed class IntToLayerMaskAttributeDrawer : DrawerPropertyDrawer
|
||||
{
|
||||
private static string[] NAMES;
|
||||
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Integer)
|
||||
return false;
|
||||
|
||||
FetchLayerNames();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
property.intValue = EditorGUI.MaskField(position, label, property.intValue, NAMES);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports integers";
|
||||
}
|
||||
|
||||
|
||||
private static void FetchLayerNames()
|
||||
{
|
||||
if (NAMES != null)
|
||||
return;
|
||||
|
||||
NAMES = new string[32];
|
||||
|
||||
for (var i = 0; i < 32; i++)
|
||||
{
|
||||
string str = LayerMask.LayerToName(i);
|
||||
|
||||
if (string.IsNullOrEmpty(str))
|
||||
str = $"Unused Layer #{i:00}";
|
||||
|
||||
NAMES[i] = str;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue