Skip to content
 
 

Repository files navigation

Alchemy

license

日本語版READMEはこちら

Overview

Alchemy is a library that provides inspector extensions using attributes.

In addition to adding easy and powerful editor extensions based on attributes, it allows serialization of any type (Dictionary, Hashset, Nullable, Tuple, etc...) through its own serialization process, making it possible to edit them in the inspector. By using Source Generator to dynamically generate the necessary code, it works simply by adding attributes to the target type marked as partial. There is no need to inherit from dedicated classes as with Odin.

Additionally, with the new features of v2.0, EditorWindow extensions and Hierarchy extensions have been added. These make it easy to create tools that streamline the development workflow in the editor.

Features

  • Adds over 30 attributes to extend the Inspector
  • Supports SerializeReference, allowing selection of types from a dropdown
  • Serialize any type (Dictionary, Hashset, Nullable, Tuple, etc...) / Editable in Inspector
  • Creation of EditorWindow using attributes
  • Provides features to improve usability of the Hierarchy
  • Creation of custom attributes that work with Alchemy

Setup

Requirements

  • Unity 2021.2 or higher (Recommended: 2022.1 or higher for serialization extensions)
  • Serialization 2.0 or higher (for serialization extensions)

Installation

  1. Open Package Manager from Window > Package Manager
  2. Click on the "+" button > Add package from git URL
  3. Enter the following URL:
https://github.com/annulusgames/Alchemy.git?path=/Alchemy/Assets/Alchemy

Or open Packages/manifest.json and add the following to the dependencies block:

{
    "dependencies": {
        "com.annulusgames.alchemy": "https://github.com/annulusgames/Alchemy.git?path=/Alchemy/Assets/Alchemy"
    }
}

Documentation

The full version of the documentation can be found here.

Basic Usage

To customize the display in the Inspector, add attributes to the fields of the class.

using UnityEngine;
using UnityEngine.UIElements;
using Alchemy.Inspector;

public class AttributesExample : MonoBehaviour
{
    [LabelText("Custom Label")]
    public float foo;

    [HideLabel]
    public Vector3 bar;
    
    [AssetsOnly]
    public GameObject baz;

    [Title("Title")]
    [HelpBox("HelpBox", HelpBoxMessageType.Info)]
    [ReadOnly]
    public string message = "Read Only";
}

Various attributes for grouping each field are also provided. Each group can be nested by separating with a slash /.

using UnityEngine;
using Alchemy.Inspector;

public class GroupAttributesExample : MonoBehaviour
{
    [FoldoutGroup("Foldout")]
    public int a;

    [FoldoutGroup("Foldout")]
    public int b;

    [FoldoutGroup("Foldout")]
    public int c;

    [TabGroup("Tab", "Tab1")]
    public int x;

    [TabGroup("Tab", "Tab2")]
    public string y;

    [TabGroup("Tab", "Tab3")]
    public Vector3 z;
}

By adding the [Button] attribute to a method, the method can be executed from the Inspector.

using System.Text;
using UnityEngine;
using Alchemy.Inspector;

[Serializable]
public sealed class Example : IExample
{
    public float foo;
    public Vector3 bar;
    public GameObject baz;
}

public class ButtonExample : MonoBehaviour
{
    [Button]
    public void Foo()
    {
        Debug.Log("Foo");
    }

    [Button]
    public void Foo(int parameter)
    {
        Debug.Log("Foo: " + parameter);
    }

    [Button]
    public void Foo(Example parameter)
    {
        var builder = new StringBuilder();
        builder.AppendLine();
        builder.Append("foo = ").AppendLine(parameter.foo.ToString());
        builder.Append("bar = ").AppendLine(parameter.bar.ToString());
        builder.Append("baz = ").Append(parameter.baz == null ? "Null" : parameter.baz.ToString());
        Debug.Log("Foo: " + builder.ToString());
    }
}

Alchemy provides many other attributes. The list of available attributes can be found in the documentation.

Editing Interfaces/Abstract Classes