GithubHelp home page GithubHelp logo

sibz / com.sibz.editorlist Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 77 KB

This packages enables lists that can be nicely displayed in the editor. It's fully extensible.

C# 100.00%
unity unity-editor unity-editor-gui

com.sibz.editorlist's Introduction

Com.Sibz.EditorList

This packages enables lists that can be nicely displayed in the editor. It's fully extensible.

Contains two implementations:

  • UnorderedGameObjectList
  • OrderedGameObjectList

Both are very similar, they display a list of game objects, however the ordered one has ordering buttons.

Usage

using UnityEditor;
using UnityEngine;

public class MyTestMono : MonoBehaviour
{
   public UnorderedGameObjectList GameObjectsList1;
   public OrderedGameObjectList GameObjectsList2;
}

// This is required to enable the use of GUILayout. Can also be put in own file.
#if UNITY_EDITOR
[CustomEditor(typeof(MyTestMono)), CanEditMultipleObjects]
public class MyTestMonoCI : Editor{}
#endif

This should give you something similar to:

sample

List of Custom (Unity)Objects

Implement as above but define your own EditList and ObjectListDrawer. T Must derive from UnityEngine.Object.

OrderedColliderList.cs

using System;
using UnityEngine;
using Sibz.EditorList;

[Serializable]
public class OrderedColliderList : EditorList<Collider> { }

OrderedColliderListDrawer.cs

using Sibz.EditorList.Editor;
using UnityEditor;

[CustomPropertyDrawer(typeof(OrderedColliderList))]
public class OrderedColliderListDrawer : ObjectListDrawer<Collider> { }

List of anything

Anything can be listed, you either have to write a custom property drawer for the object you are listing, or override the default ListView.

  1. If you made your CustomPropertyDrawer for the property on the list:
[Serializable]
public class CustomObject {
   public string Name;
};
[Serializable]
public class OrderedCustomObjectList : EditorList<CustomObject> { }

Note overriding ListDrawer here (not ObjectListDrawer):

[CustomPropertyDrawer(typeof(OrderedCustomObjectList))]
public class CustomObjectListDrawer : ListDrawer<CustomObject> { }
  1. If you want to do your own thing for the item, then you have to override ListDrawer.ListItemDrawer:
[CustomPropertyDrawer(typeof(OrderedCustomObjectList))]
public class CustomObjectListDrawer : ListDrawer<CustomObject>
{
  protected override void ListItemDrawer(SerializedProperty listProperty, SerializedProperty listItemProperty, int index)
  {
      EditorGUILayout.LabelField(listItemProperty.FindPropertyRelative("Name").stringValue);
  }
}

Custom List Result:

sample2

com.sibz.editorlist's People

Contributors

sibz avatar

Watchers

 avatar  avatar

com.sibz.editorlist's Issues

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.