Beispiel #1
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));
                }
            }
        }
Beispiel #2
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);
        }