Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.47 KB

README.md

File metadata and controls

58 lines (39 loc) · 1.47 KB

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];