Added lots of examples for editor customization
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d54ab03c1c0c44d791dc4924077e6721
|
||||
timeCreated: 1782227128
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Attributes.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(RequiredAttribute))]
|
||||
public class RequiredAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
bool isNull = property.objectReferenceValue == null;
|
||||
|
||||
if (isNull) position.height = EditorGUIUtility.singleLineHeight;
|
||||
|
||||
// draw property itself
|
||||
EditorGUI.PropertyField(position, property, label);
|
||||
|
||||
// draw error if property is null
|
||||
if (!isNull) return;
|
||||
|
||||
position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
|
||||
position.height += 10.0f;
|
||||
EditorGUI.HelpBox(position, "Property has to be set!", MessageType.Error);
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (property.objectReferenceValue == null)
|
||||
{
|
||||
return EditorGUIUtility.singleLineHeight * 2 + EditorGUIUtility.standardVerticalSpacing + 10.0f;
|
||||
}
|
||||
return EditorGUIUtility.singleLineHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6e50e9fdc60c4539822a5697fb9ca70f
|
||||
timeCreated: 1782227142
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Attributes
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class RequiredAttribute : PropertyAttribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24b0639b8cb74a8199a77a007236bce1
|
||||
timeCreated: 1782226882
|
||||
Reference in New Issue
Block a user