rotorz / unity3d-reorderable-list

List control for Unity allowing editor developers to add reorderable list controls to their GUIs.
MIT License
169 stars 31 forks source link
unity3d unity3d-npm-package

unity3d-reorderable-list

List control for Unity allowing editor developers to add reorderable list controls to their GUIs. Supports generic lists and serialized property arrays, though additional collection types can be supported by implementing Rotorz.Games.Collections.IReorderableListAdaptor.

$ yarn add rotorz/unity3d-reorderable-list

This package is compatible with the unity3d-package-syncer tool. Refer to the tools' README for information on syncing packages into a Unity project.

screenshot

Features

Preview (showing drop insertion feature)

preview

Installation

The unity3d-reorderable-list library is designed to be installed into Unity projects using the npm package manager and then synchronized into the "Assets" directory using the unity3d-package-syncer utility. For more information regarding this workflow refer to the unity3d-package-syncer repository.

Alternatively you can download the contents of this repository and add directly into your project, but you would also need to download the sources of other packages that this package is dependant upon. Refer to the packages.json file to see these.

A couple of examples!

Serialized array of strings

private SerializedProperty wishlistProperty;
private SerializedProperty pointsProperty;

private void OnEnable()
{
    this.wishlistProperty = this.serializedObject.FindProperty("wishlist");
    this.pointsProperty = this.serializedObject.FindProperty("points");
}

public override void OnInspectorGUI()
{
    this.serializedObject.Update();

    ReorderableListGUI.Title("Wishlist");
    ReorderableListGUI.ListField(this.wishlistProperty);

    ReorderableListGUI.Title("Points");
    ReorderableListGUI.ListField(this.pointsProperty, ReorderableListFlags.ShowIndices);

    this.serializedObject.ApplyModifiedProperties();
}

List of strings

private List<string> yourList = new List<string>();

private void OnGUI()
{
    ReorderableListGUI.ListField(this.yourList, this.CustomListItem, this.DrawEmpty);
}

private string CustomListItem(Rect position, string itemValue)
{
    // Text fields do not like null values!
    if (itemValue == null) {
        itemValue = "";
    }
    return EditorGUI.TextField(position, itemValue);
}

private void DrawEmpty()
{
    GUILayout.Label("No items in list.", EditorStyles.miniLabel);
}

More examples

Refer to the docs/examples directory of this repository for further examples!

Contribution Agreement

This project is licensed under the MIT license (see LICENSE). To be in the best position to enforce these licenses the copyright status of this project needs to be as simple as possible. To achieve this the following terms and conditions must be met: