• Stars
    star
    131
  • Rank 274,636 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

ArrayDrawer is a base class like PropertyDrawer, but for arrays and lists.

UnityExtensions.ArrayDrawer

Before & After

Installation

Option 1: Via Unity Package Manager

Add an entry to your project's Packages/manifest.json dependencies list using the package name "com.garettbass.unityextensions.arraydrawer"; e.g.:

{
  "dependencies": {
    "com.garettbass.unityextensions.arraydrawer": "https://github.com/garettbass/UnityExtensions.ArrayDrawer.git"
  }
}

Alternatively, clone the project somewhere on your machine and add it as a local package.

Option 2: Manually

Just clone this repo somewhere inside your Unity project's Assets or Packages folders.

ArrayDrawer

To customize the editing experience for a member variable, you can implement a property drawer class that derives from the UnityEditor.PropertyDrawer base class. However, when a property drawer is specified for an array or list, Unity associates that property drawer with the elements of the array or list, not the array or list itself.

I created the UnityExtensions.ArrayDrawer base class to enable the creation of property drawers that customize the editing experience for arrays and lists. The provided ReorderableListDrawer derives from ArrayDrawer to do its business, but you can just as easily implement other sorts of array and list UI customizations. For example, in one project where I use this library, I have implemented EnumeratedArrayDrawer which provides a named array element for each value of the provided enum type.

ReorderableListDrawer

As an example ArrayDrawer-derived property drawer, this library provides ReorderableListDrawer, which presents an array or list using Unity's ReorderableList UI element, providing a much better default editing experience for arrays and lists. Additionally, the ReorderableListDrawer supports the use case where the elements of an array should be subassets of the same Unity asset. You can enable this feature by attaching the ReorderableListAttribute to the array or list in your ScriptableObject. The class shown in the screenshot above uses this feature for the SampleAsset.subassetArray member variable:

    public class SampleAsset : ScriptableObject
    {

        /* other fields ... */

        // show `subassetArray` elements directly in the inspector,
        // and save them to the same *.asset file
        [ReorderableList(elementsAreSubassets: true)]
        public SampleSubasset[] subassetArray;

    }

ReorderableListDrawerAttribute

The ReorderableListDrawerAttribute can be attached to an array or list member variable to configure the behavior of the ReorderableListDrawer. It provides the following configuration options:

  • bool disableAdding - Disables the + button in the ReorderableList UI

  • bool disableRemoving - Disables the - button in the ReorderableList UI

  • bool disableAddingAndRemoving - A shortcut to diable both adding and removing

  • bool disableDragging - Prevents the user from reordering array elements by drag & drop

  • bool elementsAreSubassets - Directs the ReorderableListDrawer to embed array elements that derive from ScriptableObject into the same Unity .asset file that contains the array or list, and to also show their member variables in the array, instead of the default object picker UI normally shown for a ScriptableObject. This is especially useful for arrays of polymorphic types, since Unity only supports polymorphism for classes that derive from ScriptableObject.

ReorderableListDrawerInjector

This class attempts to attach the ReorderableListDrawer as the default property drawer for all arrays and lists for which no other property drawer is provided. As a result, all of your arrays and lists that would normally receive the default UI treatment (seen on the left in the screenshot above) will instead receive the ReorderableListDrawer UI.

More Repositories

1

gpuc

A header-only C-like shading language compiler that writes Metal, HLSL, GLSL
C
60
star
2

oc

Macro magic for declaring/calling Objective-C APIs from C11 or C++. Preloads selectors, chooses the correct objc_msgSend to call per method/platform.
C
57
star
3

reflect

easy reflection and serialization for C++17, MIT licensed
C++
51
star
4

UnityExtensions.InspectInline

Enables you to inspect and edit object references, and easily embed such objects as subassets.
C#
44
star
5

UnityExtensions.MeshIntersection

Perform a raycast against one or more meshes.
C#
29
star
6

UnityExtensions.SelectionHistory

Adds navigation menu items in Unity Editor: "Edit/Selection/Back", "Edit/Selection/Forward"
C#
27
star
7

UnityExtensions.EditorCoroutine

UnityExtensions.EditorCoroutine makes it easy to run coroutines from Unity editor code.
C#
19
star
8

app-cpp

A header-only multiplatform entry point for Apps written in C++
C++
17
star
9

c-array

A simple std::vector-style array for C
C
12
star
10

json

A simple, easy to use, C++11 JSON library.
C++
6
star
11

cxe

Compose, compile, and run C/C++ programs
C++
5
star
12

vulkan_express_samples

Vulkan API samples using Vulkan Express
C
4
star
13

UnityAnimationHDRPExamples

C#
3
star
14

objc

An Objective-C API for C++
C++
2
star
15

jobs

simple job queue implementation for zig
Zig
2
star
16

UnityExtensions.AssetBackup

Backs up assets whenever they are saved, and allows you to quickly restore an asset from backup.
C#
2
star
17

UnityExtensions.VSCodeIntegrationPatch

Enables `C# for Visual Studio Code` plugin to work with Unity `C#` scripts
C#
2
star
18

gtoolbox

Various C++11 utilities I developed in my free time which were later integrated into Zengine, Z2's in-house engine.
C++
2
star
19

net

some simple, composable networking primitives using Berkeley sockets and C++11
C++
2
star
20

UnityExtensions.GameEvents

GameEvents let your scenes and prefabs talk to each other!
C#
1
star
21

Notifications

WIP: may become UnityExtensions.Notifications
C#
1
star
22

app-dev

Development environment for http://github.com/garettbass/app
C++
1
star
23

function_traits

C++ function signature deduction
C++
1
star
24

vulkan_express

Simplify common sequences of Vulkan API calls for simple use cases.
C
1
star
25

app

A platform agnostic application entry point in C.
C++
1
star
26

UnityExtensions.IconBrowser

A searchable editor window to browse Unity's builtin GUI icons.
C#
1
star
27

UnityExtensions.VectorDrawer

Apply the [Vector] attribute to a field to get inspector GUI similar to Vector3 and friends.
C#
1
star