How to display an enum in UI with spaces

I have tried accessing the System.ComponentModel.DataAnnotations namespace, but it seems that it does not exist.

I have tried the following without the specified namespace and I get and error:

public enum QuestState
{
    Available,
    NotAvailable, [Description("Not Available")]
    InProgress,
    Finished,
    Completed,
    NA
}

Error:

Any help is appreciated! :slight_smile:

I assume when I perform enum.ToString(); after specifying the description of the enum, it will be displayed with a space as specified in Description?

Is there any reason that the System.ComponentModel.DataAnnotations namespace does not exist?

Still cant find a fix :frowning:

If this is editor-only code, you might try UnityEditor.ObjectNames.NicifyVariableName().

I just did this and it worked just fine:

using UnityEngine;
using System.ComponentModel;

public class TestScript01 : MonoBehaviour {

    // Use this for initialization
    void Start ()
    {
        Debug.Log(GetPrettyName(QuestState.NotAvailable));
        Debug.Log(GetPrettyName(QuestState.Completed));
    }


    public static string GetPrettyName(System.Enum e)
    {
        var nm = e.ToString();
        var tp = e.GetType();
        var field = tp.GetField(nm);
        var attrib = System.Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;

        if (attrib != null)
            return attrib.Description;
        else
            return nm;
    }

    [Description("Quest State")]
    public enum QuestState
    {
        [Description("Available")]
        Available,
        [Description("Not Available")]
        NotAvailable,
        [Description("In Progress")]
        InProgress,
        Finished,
        Completed,
        NA
    }

}