Beispiel #1
0
        static public T Popup <T>(GUIContent inLabel, T inCurrent, NamedItemList <T> inElementList, GUIStyle inStyle, params GUILayoutOption[] inOptions)
        {
            int currentIdx = inElementList.IndexOf(inCurrent);
            int nextIdx    = EditorGUILayout.Popup(inLabel, currentIdx, inElementList.SortedContent(), inStyle, inOptions);

            return(inElementList.Get(nextIdx, inCurrent));
        }
Beispiel #2
0
        static public T Popup <T>(Rect inPosition, GUIContent inLabel, T inCurrent, NamedItemList <T> inElementList, GUIStyle inStyle)
        {
            int currentIdx = inElementList.IndexOf(inCurrent);
            int nextIdx    = EditorGUI.Popup(inPosition, inLabel, currentIdx, inElementList.SortedContent(), inStyle);

            return(inElementList.Get(nextIdx, inCurrent));
        }
Beispiel #3
0
        /// <summary>
        /// Generates the flag mapping for the given enum type.
        /// </summary>
        static private void CreateFlagMapping(Type inType, NamedItemList <Enum> inLabeledList, out string[] outFlagNames, out FlagMapping[] outMapping)
        {
            List <FlagMapping> mappings;
            List <string>      names;

            if (inLabeledList != null)
            {
                int labeledCount = inLabeledList.Count;
                names    = new List <string>(labeledCount);
                mappings = new List <FlagMapping>(labeledCount);

                for (int i = 0; i < inLabeledList.Count; ++i)
                {
                    Enum val    = inLabeledList.Get(i);
                    int  input  = Convert.ToInt32(val);
                    int  output = 1 << mappings.Count;

                    if (Mathf.IsPowerOfTwo(input))
                    {
                        names.Add(inLabeledList.SortedStrings() [i]);
                        mappings.Add(new FlagMapping(input, output));
                    }
                }
            }
            else
            {
                FieldInfo[] fields     = inType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly);
                int         fieldCount = fields.Length;

                names    = new List <string>(fieldCount);
                mappings = new List <FlagMapping>(fieldCount);

                for (int i = 0; i < fieldCount; ++i)
                {
                    FieldInfo field = fields[i];

                    if (field.IsDefined(typeof(HiddenAttribute)) || field.IsDefined(typeof(ObsoleteAttribute)))
                    {
                        continue;
                    }

                    LabelAttribute labeledAttr = (LabelAttribute)field.GetCustomAttribute(typeof(LabelAttribute));

                    string name;
                    Enum   val = (Enum)field.GetValue(null);

                    if (labeledAttr != null)
                    {
                        name = labeledAttr.Name;
                    }
                    else
                    {
                        name = ObjectNames.NicifyVariableName(val.ToString());
                    }

                    int input  = Convert.ToInt32(val);
                    int output = 1 << mappings.Count;

                    if (Mathf.IsPowerOfTwo(input))
                    {
                        names.Add(name);
                        mappings.Add(new FlagMapping(input, output));
                    }
                }
            }

            outFlagNames = names.ToArray();
            outMapping   = mappings.ToArray();
        }