Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Alchemy/Assets/Alchemy/Editor/AlchemyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ void OnDestroy()
}

public override VisualElement CreateInspectorGUI()
{
var root = new VisualElement();
{
var settings = AlchemySettings.GetOrCreateSettings();
var root = new VisualElement();
var targetType = target.GetType();

if (targetType.HasCustomAttribute<DisableAlchemyEditorAttribute>())
Expand All @@ -80,7 +81,7 @@ public override VisualElement CreateInspectorGUI()
#endif

// Add script field
if (targetType.GetCustomAttribute<HideScriptFieldAttribute>() == null)
if (!settings.AlwaysHideScriptField && targetType.GetCustomAttribute<HideScriptFieldAttribute>() == null)
{
var scriptField = new PropertyField(serializedObject.FindProperty(ScriptFieldName));
scriptField.SetEnabled(false);
Expand Down
9 changes: 6 additions & 3 deletions Alchemy/Assets/Alchemy/Editor/AlchemySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ internal static SettingsProvider CreateSettingsProvider()

using (var changeCheck = new EditorGUI.ChangeCheckScope())
{
EditorGUILayout.PropertyField(serializedObject.FindProperty("hierarchyObjectMode"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("showHierarchyToggles"), new GUIContent("Show Toggles"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("showComponentIcons"));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(hierarchyObjectMode)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(showHierarchyToggles)), new GUIContent("Show Toggles"));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(showComponentIcons)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(alwaysHideScriptField)));
var showTreeMap = serializedObject.FindProperty("showTreeMap");
EditorGUILayout.PropertyField(showTreeMap);
if (showTreeMap.boolValue)
Expand Down Expand Up @@ -110,6 +111,7 @@ internal static SettingsProvider CreateSettingsProvider()
[SerializeField] HierarchyObjectMode hierarchyObjectMode = HierarchyObjectMode.RemoveInBuild;
[SerializeField] bool showHierarchyToggles;
[SerializeField] bool showComponentIcons;
[SerializeField] bool alwaysHideScriptField;
[SerializeField] bool showTreeMap;
[SerializeField] Color treeMapColor = new(0.53f, 0.53f, 0.53f, 0.45f);
[SerializeField] bool showSeparator;
Expand All @@ -121,6 +123,7 @@ internal static SettingsProvider CreateSettingsProvider()
public HierarchyObjectMode HierarchyObjectMode => hierarchyObjectMode;
public bool ShowHierarchyToggles => showHierarchyToggles;
public bool ShowComponentIcons => showComponentIcons;
public bool AlwaysHideScriptField => alwaysHideScriptField;
public bool ShowTreeMap => showTreeMap;
public Color TreeMapColor => treeMapColor;
public bool ShowSeparator => showSeparator;
Expand Down
25 changes: 17 additions & 8 deletions Alchemy/Assets/Alchemy/Editor/Elements/MethodButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,32 @@ public sealed class MethodButton : VisualElement
{
const string ButtonLabelText = "Invoke";

public MethodButton(object target, MethodInfo methodInfo)
public MethodButton(object target, MethodInfo methodInfo, bool useParameters)
{
var parameters = methodInfo.GetParameters();
var parameterObjects = new object[parameters.Length];
for(int i = 0; i < parameters.Length; i++)
{
if(parameters[i].HasDefaultValue)
parameterObjects[i] = parameters[i].DefaultValue;
else
parameterObjects[i] = TypeHelper.CreateDefaultInstance(parameters[i].ParameterType);
}

// Create parameterless button
if (parameters.Length == 0)
if (!useParameters || parameters.Length == 0)
{
button = new Button(() => methodInfo.Invoke(target, null))
{
text = methodInfo.Name
};
if(parameters.Length > 0)
button = new Button(() => methodInfo.Invoke(target, parameterObjects));
else
button = new Button(() => methodInfo.Invoke(target, null));

button.text = ObjectNames.NicifyVariableName(methodInfo.Name);
button.tooltip = methodInfo.ToString();
Add(button);
return;
}

var parameterObjects = new object[parameters.Length];

var box = new HelpBox();
Add(box);
Expand Down Expand Up @@ -59,7 +69,6 @@ public MethodButton(object target, MethodInfo methodInfo)
{
var index = i;
var parameter = parameters[index];
parameterObjects[index] = TypeHelper.CreateDefaultInstance(parameter.ParameterType);
var element = new GenericField(parameterObjects[index], parameter.ParameterType, ObjectNames.NicifyVariableName(parameter.Name));
element.OnValueChanged += x => parameterObjects[index] = x;
element.style.paddingRight = 4f;
Expand Down
4 changes: 2 additions & 2 deletions Alchemy/Assets/Alchemy/Editor/Elements/ReflectionField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public void Rebuild(object target, MemberInfo memberInfo)

if (memberInfo is MethodInfo methodInfo)
{
if (methodInfo.HasCustomAttribute<ButtonAttribute>())
if (methodInfo.TryGetCustomAttribute<ButtonAttribute>(out var buttonAttribute))
{
var button = new MethodButton(target, methodInfo);
var button = new MethodButton(target, methodInfo, buttonAttribute.useParameters);
Add(button);
}
return;
Expand Down
4 changes: 2 additions & 2 deletions Alchemy/Assets/Alchemy/Editor/Internal/InspectorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ public static VisualElement CreateMemberElement(SerializedObject serializedObjec
switch (memberInfo)
{
case MethodInfo methodInfo:
if (methodInfo.HasCustomAttribute<ButtonAttribute>())
if (methodInfo.TryGetCustomAttribute<ButtonAttribute>(out var buttonAttribute))
{
return new MethodButton(target, methodInfo);
return new MethodButton(target, methodInfo, buttonAttribute.useParameters);
}
break;
case FieldInfo:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public sealed class OrderAttribute : Attribute
}

[AttributeUsage(AttributeTargets.Method)]
public sealed class ButtonAttribute : Attribute { }
public sealed class ButtonAttribute : Attribute
{
public ButtonAttribute(bool useParameters = true) => this.useParameters = useParameters;
public readonly bool useParameters;
}

[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public sealed class ShowInInspectorAttribute : Attribute { }
Expand Down
1 change: 1 addition & 0 deletions Alchemy/ProjectSettings/AlchemySettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"hierarchyObjectMode": 2,
"showHierarchyToggles": true,
"showComponentIcons": true,
"alwaysHideScriptField": false
"showTreeMap": false,
"treeMapColor": {
"r": 0.5299999713897705,
Expand Down