Hi,
I have a simple object that has a Array that I want to contain one of each item in an enum by default.
How can I get the Array to show these default values in the Editor? for the most part they will not change but in a few cases (specifically while I’m testing the game) I want to change the values in the array in a few instances of the object.
Thanks for your help,
Matt
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using UnityEngine;
public enum MyEnum { FirstThing, SecondThing, ThirdThing }
public class NewBehaviourScript : MonoBehaviour {
static NewBehaviourScript()
{
List<MyEnum> defaults = new List<MyEnum>();
foreach (var v in Enum.GetValues(typeof(MyEnum)))
defaults.Add((MyEnum)v);
s_DefaultEnumValues = new ReadOnlyCollection<MyEnum>(defaults.ToArray());
}
static readonly ReadOnlyCollection<MyEnum> s_DefaultEnumValues;
[SerializeField]
List<MyEnum> m_EnumValues = s_DefaultEnumValues.ToList();
}