mirror of
https://github.com/AnnulusGames/Alchemy.git
synced 2025-01-22 08:18:51 -05:00
Add: AlchemyEditorUtility
This commit is contained in:
parent
1a645e2a81
commit
7e848c8b3c
25
Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs
Normal file
25
Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs
Normal file
@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using Alchemy.Inspector;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
public static class AlchemyEditorUtility
|
||||
{
|
||||
public static Type FindGroupDrawerType(PropertyGroupAttribute attribute)
|
||||
{
|
||||
return TypeCache.GetTypesWithAttribute<CustomGroupDrawerAttribute>()
|
||||
.FirstOrDefault(x => x.GetCustomAttribute<CustomGroupDrawerAttribute>().targetAttributeType == attribute.GetType());
|
||||
}
|
||||
|
||||
internal static AlchemyGroupDrawer CreateGroupDrawer(PropertyGroupAttribute attribute, Type targetType)
|
||||
{
|
||||
var drawerType = FindGroupDrawerType(attribute);
|
||||
var drawer = (AlchemyGroupDrawer)Activator.CreateInstance(drawerType);
|
||||
drawer.SetUniqueId("AlchemyGroupId_" + targetType.FullName + "_" + attribute.GroupPath);
|
||||
return drawer;
|
||||
}
|
||||
}
|
||||
}
|
11
Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs.meta
Normal file
11
Alchemy/Assets/Alchemy/Editor/AlchemyEditorUtility.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 890788e0ea34e47319ee5f653021c4dd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -9,6 +9,11 @@ namespace Alchemy.Editor
|
||||
public virtual VisualElement GetGroupElement(Attribute attribute) => null;
|
||||
|
||||
public string UniqueId => _uniqueId;
|
||||
internal string _uniqueId;
|
||||
string _uniqueId;
|
||||
|
||||
internal void SetUniqueId(string id)
|
||||
{
|
||||
this._uniqueId = id;
|
||||
}
|
||||
}
|
||||
}
|
@ -46,10 +46,7 @@ namespace Alchemy.Editor.Elements
|
||||
}
|
||||
else if (targetType.TryGetCustomAttribute<PropertyGroupAttribute>(out var groupAttribute)) // custom group
|
||||
{
|
||||
var drawerType = TypeCache.GetTypesWithAttribute<CustomGroupDrawerAttribute>()
|
||||
.FirstOrDefault(x => x.GetCustomAttribute<CustomGroupDrawerAttribute>().targetAttributeType == groupAttribute.GetType());
|
||||
var drawer = (AlchemyGroupDrawer)Activator.CreateInstance(drawerType);
|
||||
drawer._uniqueId = "AlchemyGroupId_" + targetType.FullName + "_" + property.propertyPath;
|
||||
var drawer = AlchemyEditorUtility.CreateGroupDrawer(groupAttribute, targetType);
|
||||
|
||||
var root = drawer.CreateRootElement(labelText);
|
||||
InspectorHelper.BuildElements(property.serializedObject, root, property.GetValue<object>(), name => property.FindPropertyRelative(name), depth + 1);
|
||||
|
@ -182,13 +182,7 @@ namespace Alchemy.Editor
|
||||
var next = parentNode.Find(x => x.Name == groupName);
|
||||
if (next == null)
|
||||
{
|
||||
// Find drawer type
|
||||
var drawerType = TypeCache.GetTypesWithAttribute<CustomGroupDrawerAttribute>()
|
||||
.FirstOrDefault(x => x.GetCustomAttribute<CustomGroupDrawerAttribute>().targetAttributeType == groupAttribute.GetType());
|
||||
|
||||
var drawer = (AlchemyGroupDrawer)Activator.CreateInstance(drawerType);
|
||||
drawer._uniqueId = "AlchemyGroupId_" + targetType.FullName + "_" + groupAttribute.GroupPath;
|
||||
|
||||
var drawer = AlchemyEditorUtility.CreateGroupDrawer(groupAttribute, targetType);
|
||||
next = new GroupNode(groupName, drawer);
|
||||
parentNode.Add(next);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user