add scriptable object examples

add editor window example
add attribute + drawer example
This commit is contained in:
2025-06-13 18:07:18 +02:00
parent 0ae837c57b
commit a6dbfb224f
52 changed files with 1460 additions and 533 deletions
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a2a86f13a318489c95e31e662cf4ccf8
timeCreated: 1749829930
@@ -0,0 +1,35 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace Attributes.Editor
{
[CustomPropertyDrawer(typeof(RequireAttribute))]
public class RequireAttributeDrawer : PropertyDrawer
{
private readonly string HELPBOX_CONTENT = "Property has to be set!";
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
bool isNull = !property.objectReferenceValue;
if (isNull) position.height = EditorGUIUtility.singleLineHeight;
EditorGUI.PropertyField(position, property, label);
if (isNull)
{
position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
position.height = EditorStyles.helpBox.CalcHeight(new GUIContent(HELPBOX_CONTENT),
EditorGUIUtility.currentViewWidth) + 10.0f;
EditorGUI.HelpBox(position, HELPBOX_CONTENT, MessageType.Error);
}
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property.objectReferenceValue) return EditorGUIUtility.singleLineHeight;
return EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing + EditorStyles.helpBox.CalcHeight(new GUIContent(HELPBOX_CONTENT), EditorGUIUtility.currentViewWidth) + 10.0f;
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e966da3a6c3e4487ba279991b988a582
timeCreated: 1749829943
@@ -0,0 +1,9 @@
using UnityEngine;
namespace Attributes
{
public class RequireAttribute : PropertyAttribute
{
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a4b36ca3d21740d4ab5a0e19d2622dfb
timeCreated: 1749829828