add scriptable object examples
add editor window example add attribute + drawer example
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
using Data;
|
||||
using UnityEditor;
|
||||
using UnityEditor.VersionControl;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Core
|
||||
{
|
||||
public class CharacterAttributesWindow : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/Character Attributes #%^c")]
|
||||
private static void ShowWindow()
|
||||
{
|
||||
var window = GetWindow<CharacterAttributesWindow>();
|
||||
window.titleContent = new GUIContent("Character Attributes");
|
||||
window.Show();
|
||||
}
|
||||
|
||||
public CharacterAttributes CharacterAttributesToEdit;
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
// EditorGUILayout.BeginHorizontal();
|
||||
// EditorGUILayout.LabelField("Label", GUILayout.Width(100));
|
||||
// EditorGUILayout.LabelField("Next Label", GUILayout.ExpandWidth(true));
|
||||
//
|
||||
// EditorGUILayout.BeginVertical();
|
||||
//
|
||||
// EditorGUILayout.LabelField("Another Label");
|
||||
// EditorGUILayout.LabelField("Another Label");
|
||||
// EditorGUILayout.LabelField("Another Label");
|
||||
// EditorGUILayout.LabelField("Another Label");
|
||||
//
|
||||
// EditorGUILayout.EndVertical();
|
||||
//
|
||||
// EditorGUILayout.EndHorizontal();
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
// show all project-wide character attribute assets
|
||||
string[] characterAttributesGUIDs = AssetDatabase.FindAssets("t:CharacterAttributes");
|
||||
foreach (string characterAttributeGUID in characterAttributesGUIDs)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(characterAttributeGUID);
|
||||
CharacterAttributes characterAttributes = AssetDatabase.LoadAssetAtPath<CharacterAttributes>(path);
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
EditorGUILayout.LabelField(characterAttributes.name);
|
||||
// EditorGUILayout.LabelField($"Health: {characterAttributes.Health}");
|
||||
// EditorGUILayout.LabelField($"Strength: {characterAttributes.Strength}");
|
||||
// EditorGUILayout.LabelField($"Strength Multiplier: {characterAttributes.StrengthMultiplier}");
|
||||
|
||||
if (GUILayout.Button("Edit"))
|
||||
{
|
||||
CharacterAttributesToEdit = characterAttributes;
|
||||
}
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
if (CharacterAttributesToEdit)
|
||||
{
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
SerializedObject serializedObject = new SerializedObject(CharacterAttributesToEdit);
|
||||
serializedObject.Update();
|
||||
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("Health"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("Strength"));
|
||||
EditorGUILayout.PropertyField(serializedObject.FindProperty("StrengthMultiplier"));
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
|
||||
EditorGUILayout.Separator();
|
||||
|
||||
if (GUILayout.Button("Create"))
|
||||
{
|
||||
CharacterAttributes newCharacterAttributes = CreateInstance<CharacterAttributes>();
|
||||
string path = EditorUtility.SaveFilePanelInProject("Save Character Attributes", "Character Attributes", "asset", "");
|
||||
AssetDatabase.CreateAsset(newCharacterAttributes, path);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user