mirror of
https://github.com/AnnulusGames/Alchemy.git
synced 2025-01-22 08:18:51 -05:00
commit
2cc974d676
@ -6,6 +6,9 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for extending drawing processing for fields with Alchemy attributes.
|
||||
/// </summary>
|
||||
public abstract class AlchemyAttributeDrawer
|
||||
{
|
||||
SerializedObject serializedObject;
|
||||
@ -15,13 +18,39 @@ namespace Alchemy.Editor
|
||||
Attribute attribute;
|
||||
VisualElement targetElement;
|
||||
|
||||
/// <summary>
|
||||
/// Target serialized object.
|
||||
/// </summary>
|
||||
public SerializedObject SerializedObject => serializedObject;
|
||||
|
||||
/// <summary>
|
||||
/// Target serialized property.
|
||||
/// </summary>
|
||||
public SerializedProperty SerializedProperty => serializedProperty;
|
||||
|
||||
/// <summary>
|
||||
/// Target object.
|
||||
/// </summary>
|
||||
public object Target => target;
|
||||
|
||||
/// <summary>
|
||||
/// MemberInfo of the target member.
|
||||
/// </summary>
|
||||
public MemberInfo MemberInfo => memberInfo;
|
||||
|
||||
/// <summary>
|
||||
/// Target attribute.
|
||||
/// </summary>
|
||||
public Attribute Attribute => attribute;
|
||||
|
||||
/// <summary>
|
||||
/// Target visual element.
|
||||
/// </summary>
|
||||
public VisualElement TargetElement => targetElement;
|
||||
|
||||
/// <summary>
|
||||
/// Called when the target visual element is created.
|
||||
/// </summary>
|
||||
public abstract void OnCreateElement();
|
||||
|
||||
internal static void ExecutePropertyDrawers(SerializedObject serializedObject, SerializedProperty property, object target, MemberInfo memberInfo, VisualElement memberElement)
|
||||
|
@ -6,14 +6,20 @@ using Alchemy.Inspector;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Alchemy Editor utility functions.
|
||||
/// </summary>
|
||||
public static class AlchemyEditorUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// Finds the type of drawer that corresponds to PropertyGroupAttribute.
|
||||
/// </summary>
|
||||
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);
|
||||
|
@ -6,6 +6,9 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for constructing EditorWindow using Alchemy attributes.
|
||||
/// </summary>
|
||||
public abstract class AlchemyEditorWindow : EditorWindow
|
||||
{
|
||||
protected virtual void CreateGUI()
|
||||
@ -30,16 +33,27 @@ namespace Alchemy.Editor
|
||||
rootVisualElement.Add(windowElement);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path where the window data is saved. The default path is $"ProjectSettings/{GetType().FullName}.json".
|
||||
/// </summary>
|
||||
protected virtual string GetWindowDataPath()
|
||||
{
|
||||
return $"ProjectSettings/{GetType().FullName}.json";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the current window data.
|
||||
/// </summary>
|
||||
/// <param name="dataPath">Window data path</param>
|
||||
protected virtual void SaveWindowData(string dataPath)
|
||||
{
|
||||
File.WriteAllText(dataPath, JsonUtility.ToJson(this, true));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads saved window data.
|
||||
/// </summary>
|
||||
/// <param name="dataPath">Window data path</param>
|
||||
protected virtual void LoadWindowData(string dataPath)
|
||||
{
|
||||
if (File.Exists(dataPath))
|
||||
|
@ -3,12 +3,28 @@ using UnityEngine.UIElements;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for implementing Alchemy group attribute drawing process.
|
||||
/// </summary>
|
||||
public abstract class AlchemyGroupDrawer
|
||||
{
|
||||
/// <summary>
|
||||
/// Create a visual element that will be the root of the group.
|
||||
/// </summary>
|
||||
/// <param name="label">Label text</param>
|
||||
public abstract VisualElement CreateRootElement(string label);
|
||||
|
||||
/// <summary>
|
||||
/// Returns the corresponding visual element when the root visual element differs depending on the attribute value.
|
||||
/// </summary>
|
||||
/// <param name="attribute">Target attribute</param>
|
||||
public virtual VisualElement GetGroupElement(Attribute attribute) => null;
|
||||
|
||||
/// <summary>
|
||||
/// ID used to identify the group.
|
||||
/// </summary>
|
||||
public string UniqueId => uniqueId;
|
||||
|
||||
string uniqueId;
|
||||
|
||||
internal void SetUniqueId(string id)
|
||||
|
@ -6,11 +6,18 @@ using Alchemy.Hierarchy;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Alchemy project-level settings
|
||||
/// </summary>
|
||||
public sealed class AlchemySettings : ScriptableObject
|
||||
{
|
||||
static readonly string SettingsPath = "ProjectSettings/AlchemySettings.json";
|
||||
|
||||
static AlchemySettings instance;
|
||||
|
||||
/// <summary>
|
||||
/// Get a cached instance. If the cache does not exist, returns a newly created one.
|
||||
/// </summary>
|
||||
public static AlchemySettings GetOrCreateSettings()
|
||||
{
|
||||
if (instance != null) return instance;
|
||||
@ -28,6 +35,9 @@ namespace Alchemy.Editor
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save the settings to a file.
|
||||
/// </summary>
|
||||
public static void SaveSettings()
|
||||
{
|
||||
File.WriteAllText(SettingsPath, JsonUtility.ToJson(instance, true));
|
||||
|
@ -2,6 +2,9 @@ using System;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute for specifying the target attribute of AlchemyAttributeDrawer.
|
||||
/// </summary>
|
||||
public sealed class CustomAttributeDrawerAttribute : Attribute
|
||||
{
|
||||
public CustomAttributeDrawerAttribute(Type targetAttributeType, int order = 0)
|
||||
|
@ -2,12 +2,16 @@ using System;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Attribute for specifying the target attribute of AlchemyGroupDrawer.
|
||||
/// </summary>
|
||||
public sealed class CustomGroupDrawerAttribute : Attribute
|
||||
{
|
||||
public CustomGroupDrawerAttribute(Type targetAttributeType)
|
||||
{
|
||||
this.targetAttributeType = targetAttributeType;
|
||||
}
|
||||
|
||||
public readonly Type targetAttributeType;
|
||||
}
|
||||
}
|
@ -3,6 +3,9 @@ using UnityEngine;
|
||||
|
||||
namespace Alchemy.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// Base class for adding custom drawing processing to hierarchy items.
|
||||
/// </summary>
|
||||
public abstract class HierarchyDrawer
|
||||
{
|
||||
public abstract void OnGUI(int instanceID, Rect selectionRect);
|
||||
|
@ -2,6 +2,9 @@ using UnityEngine;
|
||||
|
||||
namespace Alchemy.Hierarchy
|
||||
{
|
||||
/// <summary>
|
||||
/// A component that displays headers in a hierarchy.
|
||||
/// </summary>
|
||||
[AddComponentMenu("Alchemy/Hierarchy Header")]
|
||||
public sealed class HierarchyHeader : HierarchyObject { }
|
||||
}
|
@ -2,6 +2,9 @@ using UnityEngine;
|
||||
|
||||
namespace Alchemy.Hierarchy
|
||||
{
|
||||
/// <summary>
|
||||
/// A component used to decorate the appearance of a hierarchy.
|
||||
/// </summary>
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Alchemy/Hierarchy Object")]
|
||||
public class HierarchyObject : MonoBehaviour
|
||||
|
@ -1,9 +1,21 @@
|
||||
namespace Alchemy.Hierarchy
|
||||
{
|
||||
/// <summary>
|
||||
/// Specify how to handle HierarchyObject at runtime.
|
||||
/// </summary>
|
||||
public enum HierarchyObjectMode
|
||||
{
|
||||
/// <summary>
|
||||
/// Treated as a regular GameObject.
|
||||
/// </summary>
|
||||
None = 0,
|
||||
/// <summary>
|
||||
/// Removed in play mode.
|
||||
/// </summary>
|
||||
RemoveInPlayMode = 1,
|
||||
/// <summary>
|
||||
/// Removed in build.
|
||||
/// </summary>
|
||||
RemoveInBuild = 2
|
||||
}
|
||||
}
|
@ -2,6 +2,9 @@ using UnityEngine;
|
||||
|
||||
namespace Alchemy.Hierarchy
|
||||
{
|
||||
/// <summary>
|
||||
/// A component that displays separators in a hierarchy.
|
||||
/// </summary>
|
||||
[AddComponentMenu("Alchemy/Hierarchy Separator")]
|
||||
public sealed class HierarchySeparator : HierarchyObject { }
|
||||
}
|
Loading…
Reference in New Issue
Block a user