Files
LowPolyRPG/Assets/Plugins/Nullframes/Intrigues/Scripts/Attributes/FamilyAttribute.cs
Caleb Sandford deQuincey 715fb68744 Initial commitment
2025-06-25 11:10:11 +01:00

46 lines
1.6 KiB
C#

using System.Collections.Generic;
using System.Linq;
using Nullframes.Intrigues.Graph;
using UnityEditor;
using UnityEngine;
namespace Nullframes.Intrigues.Attributes
{
public class FamilyAttribute : PropertyAttribute { }
#if UNITY_EDITOR
[CustomPropertyDrawer(typeof(FamilyAttribute))]
public class FamilyDrawer : PropertyDrawer
{
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (IM.Exists && IM.DatabaseExists)
{
var list = IM.IEDatabase.groupDataList.Where(g => g is FamilyGroupData).OfType<FamilyGroupData>().OrderBy(c => c.Title)
.Select(g => new { g.ID, g.Title }).ToDictionary(c => c.ID, c => c.Title);
if (list.Count == 0) return;
var dict = new Dictionary<string, string> { { string.Empty, "NULL" } };
foreach (var c in list)
{
dict.Add(c.Key, c.Value);
}
var index = dict.Keys.ToList().IndexOf(property.stringValue);
index = index == -1 ? 0 : index;
EditorGUI.BeginChangeCheck();
var selectedIndex = EditorGUI.Popup(position, property.displayName, index, dict.Values.ToArray());
if (EditorGUI.EndChangeCheck())
{
property.stringValue = dict.ElementAt(selectedIndex).Key;
}
}
else
{
EditorGUI.LabelField(position, $"[{property.displayName}]: IM not found. Please add an IM to the scene.");
}
}
}
#endif
}