namespace UnityEngine.Rendering { using System; using UnityEngine; /// /// Class to serizalize Enum as string and recover it's state /// [Serializable] public class SerializableEnum { [SerializeField] private string m_EnumValueAsString; [SerializeField] private string m_EnumTypeAsString; /// Value as enum public Enum value { get => !string.IsNullOrEmpty(m_EnumTypeAsString) && Enum.TryParse(Type.GetType(m_EnumTypeAsString), m_EnumValueAsString, out object result) ? (Enum)result : default; set => m_EnumValueAsString = value.ToString(); } /// /// Construct an enum to be serialized with a type /// /// The underliying type of the enum public SerializableEnum(Type enumType) { m_EnumTypeAsString = enumType.AssemblyQualifiedName; m_EnumValueAsString = Enum.GetNames(enumType)[0]; } } }