3
\$\begingroup\$

I have a list of enums. I want to add a new item to it without scripting to make them more easily modifiable for game designers. I made an inventory system and I want to define the type of an item. For an example apple is a type of food and stone is a type of object.

Is there a way to group these items in the inspector?

using UnityEngine;
using System.Collections;

public class NewBehaviourScript : MonoBehaviour {
    public const string[] typesStrings = {"Player", "Prop", "Enemy"};
    [System.Serializable]
    public class TypeList
    {
        public enum types
        {
            PLAYER = 0,
            PROP = 1,
            ENEMY = 2
        }

    };

    // MonoBehaviour class
    public TypeList.types selectedType;

    public void Start()
    {
        string selected = TypeList.typesStrings[(int)selectedType];
    }
}

This, however, gives me the following error:

Assets/grouping.cs(5,31): error CS0134: A constant grouping.typesStrings' of reference typestring[]' can only be initialized with null

\$\endgroup\$
  • 1
    \$\begingroup\$ Please only ask one question at a time. I removed the second question from your post. But feel free to post it again as a new question. You can retrieve the text and image from the edit history. \$\endgroup\$ – Philipp Jul 13 '16 at 15:22
7
\$\begingroup\$

you can use System.Serializable

using UnityEngine;
using System.Collections;
public class grouping: MonoBehaviour {
    [System.Serializable]
    public class class1{
    public enum myEnum {one,two,three};
    public myEnum[] row;
    public string name;
    public int price;
    }
    public class1[] array;
}

useful link 1 for more information:

make your lists functional with ReorderableList

enter image description here

useful link 2 Custom Editors in Unity3D – Part 8: CustomEditor

enter image description here

Unity Editor: Enum Flags as Toggle Buttons useful link 3 enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.