GithubHelp home page GithubHelp logo

bradparks / unity3d-reorderable-list Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rotorz/unity3d-reorderable-list

0.0 2.0 0.0 2.92 MB

List control for Unity allowing editor developers to add reorderable list controls to their GUIs.

License: MIT License

C# 99.89% JavaScript 0.11%

unity3d-reorderable-list's Introduction

unity3d-reorderable-list

npm version Dependency Status devDependency Status

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.

$ npm install --save @rotorz/unity3d-reorderable-list

This package is compatible with unity3d-package-syncer.

screenshot

Features

  • Drag and drop reordering!
  • Automatically scrolls if inside a scroll view whilst reordering.
  • Easily customized using flags.
  • Adaptors for IList<T> and SerializedProperty.
  • Subscribe to add/remove item events.
  • Supports mixed item heights.
  • Disable drag and/or removal on per-item basis.
  • Drop insertion (for use with UnityEditor.DragAndDrop).
  • Styles can be overridden on per-list basis if desired.
  • Subclass list control to override context menu.
  • Add drop-down to add menu (or instead of add menu).
  • Helper functionality to build element adder menus.

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:

  • All contributed content (including but not limited to source code, text, image, videos, bug reports, suggestions, ideas, etc.) must be the contributors own work.

  • The contributor disclaims all copyright and accepts that their contributed content will be released to the public domain.

  • The act of submitting a contribution indicates that the contributor agrees with this agreement. This includes (but is not limited to) pull requests, issues, tickets, e-mails, newsgroups, blogs, forums, etc.

unity3d-reorderable-list's People

Contributors

jacobdufault avatar kruncher avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.