// // Copyright (c) 2017 Anthony Marmont. All rights reserved. // Licensed for use under the Unity Asset Store EULA. See https://unity3d.com/legal/as_terms for full license information. // #if UNITY_EDITOR #pragma warning disable using System; using UnityEngine; namespace AssetIcons.Editors.Internal { /// /// A Unity that exposes a selection of values. /// [AttributeUsage(AttributeTargets.Field, AllowMultiple = false)] internal sealed class FromValuesAttribute : PropertyAttribute { /// /// The names of all of the values that this property allows. /// public GUIContent[] Names { get; set; } /// /// The values that this property allows. /// public object[] Values { get; set; } /// /// Allows for defining a strict range of values that are allowed on this property. /// /// The values that this property allows. public FromValuesAttribute(params object[] values) { if (values.Length == 0) { return; } Values = values; Type consistantType = null; Names = new GUIContent[Values.Length]; for (int i = 0; i < Values.Length; i++) { object obj = values[i]; if (consistantType == null) { consistantType = obj.GetType(); } else { if (obj.GetType() != consistantType) { return; } } Names[i] = new GUIContent(obj.ToString()); } } } } #pragma warning restore #endif