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,13 @@
using UnityEngine;
namespace Data
{
[CreateAssetMenu(fileName = "CharacterAttributes", menuName = "Data/Character Attributes", order = 0)]
public class CharacterAttributes : ScriptableObject
{
public string Name;
public int Health;
public int Strength;
public float StrengthMultiplier;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b61abb9f0ac44c59b3b2fd2042e9ace6
timeCreated: 1749826252
@@ -0,0 +1,28 @@
using Core;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace Data
{
[CustomPropertyDrawer(typeof(CharacterAttributes))]
public class CharacterAttributesDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
position = EditorGUI.PrefixLabel(position, label);
position.width *= 0.75f;
EditorGUI.PropertyField(position, property, GUIContent.none);
position.x += position.width;
position.width *= 0.3333333f;
if (GUI.Button(position, "Open"))
{
CharacterAttributesWindow window = EditorWindow.GetWindow<CharacterAttributesWindow>();
window.CharacterAttributesToEdit = property.objectReferenceValue as CharacterAttributes;
window.Show();
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 484559cbb76043e19a4cacc8b753bebf
timeCreated: 1749829051
@@ -0,0 +1,23 @@
using Core;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
namespace Data
{
[CustomEditor(typeof(CharacterAttributes))]
public class CharacterAttributesEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Open Character Attributes Editor"))
{
CharacterAttributesWindow window = EditorWindow.GetWindow<CharacterAttributesWindow>();
window.CharacterAttributesToEdit = target as CharacterAttributes;
window.Show();
}
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 272269d36d454d6cbd79b57adc9f2692
timeCreated: 1749828536
@@ -0,0 +1,10 @@
using UnityEngine;
namespace Data
{
[CreateAssetMenu(fileName = "FloatValue", menuName = "Data/Values/Float", order = 0)]
public class FloatValue : ScriptableObject
{
public float Value;
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: fd75fdc6380d499a861c0efdba916acc
timeCreated: 1749823882