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:
Anders Ejlersen 2022-06-26 15:06:52 +02:00
parent ee7326c33a
commit 7d99d62e11
14 changed files with 114 additions and 17 deletions

View 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;
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71ec06fd224544c0b6df1cb7657b7869
timeCreated: 1656194575

View file

@ -1,4 +1,5 @@
using Module.Inspector.Editor.Utilities;
#if !UNITY_2021_1_OR_NEWER
using Module.Inspector.Editor.Utilities;
using UnityEditor;
using UnityEngine;
@ -33,4 +34,5 @@ namespace Module.Inspector.Editor
return "Only supports quaternions";
}
}
}
}
#endif

View file

@ -9,8 +9,8 @@ using Object = UnityEngine.Object;
namespace Module.Inspector.Editor
{
[CustomPropertyDrawer(typeof(SerializableReferenceToAttribute))]
internal sealed class SerializableReferenceToAttributeDrawer : DrawerPropertyDrawer
[CustomPropertyDrawer(typeof(SerializeReferenceToAttribute))]
internal sealed class SerializeReferenceToAttributeDrawer : DrawerPropertyDrawer
{
private enum ESupportType
{
@ -27,10 +27,10 @@ namespace Module.Inspector.Editor
if (IsSupported(property) != ESupportType.Supported)
return false;
var att = (SerializableReferenceToAttribute)attribute;
var att = (SerializeReferenceToAttribute)attribute;
Type type = att.useType ? att.type : property.GetValueType();
string[] arrStrings = EditorTypeUtility.GetAssignableFromAsStrings(type);
GUIContent[] arrGui = EditorTypeUtility.GetAssignableFromAsGUI(type);
GUIContent[] arrGui = EditorTypeUtility.GetAssignableFromAsGUI(type, att.useFullname);
EditorGUI.BeginChangeCheck();
EditorGUI.BeginProperty(position, label, property);
@ -46,7 +46,6 @@ namespace Module.Inspector.Editor
if (newIndex != -1 && index != newIndex)
{
Type newType = EditorTypeUtility.GetType(arrStrings[newIndex]);
if (newType != null && IsSupported(newType))
property.managedReferenceValue = FormatterServices.GetUninitializedObject(newType);