Ejemplo n.º 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));
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 3
0
        static public NamedItemList <T> MakeListUnsorted <T>(IEnumerable <T> inItems, NamedListMapperDelegate <T> inMapper = null, NamedItemList <T> inTarget = null)
        {
            inMapper = inMapper ?? DefaultNamedListMapper <T>(false);

            NamedItemList <T> itemList;

            if (inTarget != null)
            {
                itemList = inTarget;
                itemList.Clear();
            }
            else
            {
                itemList = new NamedItemList <T>();
            }

            int idx = 0;

            foreach (var item in inItems)
            {
                string name;
                int    order;
                inMapper(idx++, item, out name, out order);
                itemList.Add(item, name, order);
            }

            return(itemList);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Generates the labeled list for the enum type.
        /// </summary>
        static private NamedItemList <Enum> CreateLabeledList(Type inType, bool inbSorted = false)
        {
            NamedItemList <Enum> itemList = new NamedItemList <Enum>();

            foreach (var field in inType.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly))
            {
                if (field.IsDefined(typeof(HiddenAttribute)) || field.IsDefined(typeof(ObsoleteAttribute)))
                {
                    continue;
                }

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

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

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

                if (orderAttr != null)
                {
                    order = orderAttr.Order;
                }
                else if (inbSorted)
                {
                    order = 100;
                }
                else
                {
                    order = Convert.ToInt32(val);
                }

                itemList.Add(val, name, order);
            }
            return(itemList);
        }
Ejemplo n.º 5
0
            public void GenerateForType(Type inType)
            {
                m_Flags = GetEnumTypeFlags(inType);

                bool bIsLabeled = (m_Flags & TypeFlags.Labeled) == TypeFlags.Labeled;

                if (bIsLabeled)
                {
                    bool bIsSorted = (m_Flags & TypeFlags.Sorted) == TypeFlags.Sorted;
                    m_labeledList = CreateLabeledList(inType, bIsSorted);
                }

                bool bIsFlags = (m_Flags & TypeFlags.Flags) == TypeFlags.Flags;

                if (bIsFlags)
                {
                    CreateFlagMapping(inType, m_labeledList, out m_FlagNames, out m_FlagMapping);
                }
            }
Ejemplo n.º 6
0
        static private void InitializeKeycodeList()
        {
            if (s_KeyCodes != null)
            {
                return;
            }

            s_KeyCodes = new NamedItemList <KeyCode>(510);

            foreach (KeyCode code in Enum.GetValues(typeof(KeyCode)))
            {
                if (code == KeyCode.None)
                {
                    s_KeyCodes.Add(code, "None", -1);
                }
                else
                {
                    s_KeyCodes.Add(code, GetName(code));
                }
            }
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
0
 public NamedItemList(NamedItemList <T> inSource)
 {
     m_Entries  = new List <Entry>(inSource.m_Entries);
     m_Comparer = EqualityComparer <T> .Default;
 }