Skip to content

A Unity package for associating a value with each case of an enum. Allows setting values in the inspector and serialization.

License

Unlicense, Unknown licenses found

Licenses found

Unlicense
LICENSE
Unknown
LICENSE.meta
Notifications You must be signed in to change notification settings

ComradeVanti/UnityEnumDict

Repository files navigation

EnumDict

openupm

A Unity package for associating a value with each case of an enum. Allows setting values in the inspector and serialization.

Installation

The quickest way is to install via OpenUPM using openupm add dev.comradevanti.enum-dict.

Or install manually as git dependency from https://github.com/ComradeVanti/UnityEnumDict.git or download as zip and import locally.

Works for Unity 2020.x and upwards.

Usage

Say, you want to associate a movement-force for a rigidbody with each possible movement state. You could do this by first defining an enum for it like this.

public enum MovementState
{

    Walking,
    Crouching,
    Running

}

Next create a variable for the EnumDict in your script. All serializable types are valid, such as strings, serializable classes and structs or in this case, floats.

public class MyScript : MonoBehaviour
{

    public EnumDict<MovementState, float> movementForces;

}

You can then edit it from the inspector.

EnumDict inspector

To access the value for a specific enum-case, use the indexer syntax.

// 0.5
var force = movementForces[MovementState.Crouching];

About

A Unity package for associating a value with each case of an enum. Allows setting values in the inspector and serialization.

Topics

Resources

License

Unlicense, Unknown licenses found

Licenses found

Unlicense
LICENSE
Unknown
LICENSE.meta

Stars

Watchers

Forks

Languages