Пример #1
0
        private static void ConvertToSelectList()
        {
            Console.Clear();
            Console.WriteLine("\t\t--------------- ToSelectList ---------------");

            const EnumDayOfWeek EnumInstance = EnumDayOfWeek.Fri;
            var DayOfWeekOptions             = EnumInstance.ToSelectList();

            foreach (var item in DayOfWeekOptions)
            {
                Console.WriteLine($"\t\t Value:{item.Value} - Text:{item.Text}");
            }
            Console.ReadKey();
            RecarregarMenu();
        }
Пример #2
0
        private object  SetValue(string path, object instance, string name, object value)
        {
            IFieldModifier field = InnerUtility.GetFieldInfo(instance.GetType(), name);

            InternalNGDebug.Assert(field != null, "Field \"" + name + "\" was not found in type \"" + instance.GetType() + "\".");
            object fieldValue = field.GetValue(instance);

            UnityObject uo = value as UnityObject;

            if (uo != null)
            {
                field.SetValue(instance, this.TryFetchFromProject(path, uo));
                return(instance);
            }

            ClientClass gc = value as ClientClass;

            if (gc != null)
            {
                if (fieldValue == null)
                {
                    fieldValue = Activator.CreateInstance(field.Type);
                }

                IncompleteGameObjectException incompleteEx = null;

                for (int j = 0; j < gc.fields.Length; j++)
                {
                    FieldInfo subField = field.Type.GetField(gc.fields[j].name);
                    InternalNGDebug.Assert(subField != null, "Field \"" + gc.fields[j].name + "\" was not found in type \"" + field.Type + "\".");

                    if (subField.IsLiteral == true)
                    {
                        continue;
                    }

                    try
                    {
                        fieldValue = this.SetValue(path + '.' + gc.fields[j].name, fieldValue, gc.fields[j].name, gc.fields[j].value);
                    }
                    catch (IncompleteGameObjectException ex)
                    {
                        if (incompleteEx == null)
                        {
                            incompleteEx = ex;
                        }
                        else
                        {
                            incompleteEx.Aggregate(ex);
                        }
                    }
                }

                if (incompleteEx != null)
                {
                    throw incompleteEx;
                }

                field.SetValue(instance, fieldValue);

                return(instance);
            }

            ArrayData a = value as ArrayData;

            if (a != null)
            {
                if (a.array != null)
                {
                    Type subType = Utility.GetArraySubType(field.Type);
                    if (fieldValue == null)
                    {
                        fieldValue = Array.CreateInstance(subType, a.array.Length);
                    }

                    if (field.Type.IsArray == true)
                    {
                        IncompleteGameObjectException incompleteEx = null;
                        Array fieldArray = fieldValue as Array;

                        if (fieldArray.Length != a.array.Length)
                        {
                            fieldValue = Array.CreateInstance(subType, a.array.Length);
                            fieldArray = fieldValue as Array;
                        }

                        for (int j = 0; j < a.array.Length; j++)
                        {
                            try
                            {
                                fieldArray.SetValue(this.ConvertValue(path + "#" + j, subType, a.array.GetValue(j)), j);
                            }
                            catch (IncompleteGameObjectException ex)
                            {
                                if (incompleteEx == null)
                                {
                                    incompleteEx = ex;
                                }
                                else
                                {
                                    incompleteEx.Aggregate(ex);
                                }
                            }
                        }

                        if (incompleteEx != null)
                        {
                            throw incompleteEx;
                        }
                    }
                    else if (typeof(IList).IsAssignableFrom(field.Type) == true)
                    {
                        IncompleteGameObjectException incompleteEx = null;
                        IList fieldArray = fieldValue as IList;

                        for (int j = 0; j < a.array.Length; j++)
                        {
                            try
                            {
                                fieldArray[j] = this.ConvertValue(path + "#" + j, subType, a.array.GetValue(j));
                            }
                            catch (IncompleteGameObjectException ex)
                            {
                                if (incompleteEx == null)
                                {
                                    incompleteEx = ex;
                                }
                                else
                                {
                                    incompleteEx.Aggregate(ex);
                                }
                            }
                        }

                        if (incompleteEx != null)
                        {
                            throw incompleteEx;
                        }
                    }
                    else
                    {
                        throw new InvalidCastException("Type \"" + field.Type + "\" is not supported as an array.");
                    }

                    field.SetValue(instance, fieldValue);
                }

                return(instance);
            }

            EnumInstance e = value as EnumInstance;

            if (e != null)
            {
                field.SetValue(instance, e.value);
            }
            else
            {
                field.SetValue(instance, value);
            }

            return(instance);
        }
Пример #3
0
        public override void    Draw(Rect r, DataDrawer data)
        {
            if (this.anim == null)
            {
                this.anim = new BgColorContentAnimator(data.Inspector.Repaint, 1F, 0F);
            }

            string path = data.GetPath();

            if (data.Inspector.Hierarchy.GetUpdateNotification(path) != NotificationPath.None)
            {
                this.anim.Start();
            }

            EnumInstance enumInstance = data.Value as EnumInstance;

            using (this.anim.Restorer(0F, .8F + this.anim.Value, 0F, 1F))
            {
                EnumData enumData = data.Inspector.Hierarchy.GetEnumData(enumInstance.type);

                if (enumData != null)
                {
                    if (enumInstance.GetFlag() == EnumInstance.IsFlag.Unset)
                    {
                        if (enumData.hasFlagAttribute == true)
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Flag);
                        }
                        else
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Value);
                        }
                    }

                    float width = r.width;

                    r.width = 16F;
                    r.x    += (EditorGUI.indentLevel - 1) * 15F;
                    if (GUI.Button(r, "F", enumInstance.GetFlag() == EnumInstance.IsFlag.Flag ? GUI.skin.button : GUI.skin.textField) == true)
                    {
                        if (enumInstance.GetFlag() == EnumInstance.IsFlag.Value)
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Flag);
                        }
                        else
                        {
                            enumInstance.SetFlag(EnumInstance.IsFlag.Value);
                        }
                    }
                    r.x -= (EditorGUI.indentLevel - 1) * 15F;

                    r.width = width;

                    EditorGUI.BeginChangeCheck();

                    int newValue;

                    if (enumInstance.GetFlag() == EnumInstance.IsFlag.Value)
                    {
                        newValue = EditorGUI.IntPopup(r, data.Name, enumInstance.value, enumData.names, enumData.values);
                    }
                    else
                    {
                        newValue = EditorGUI.MaskField(r, data.Name, enumInstance.value, enumData.names);
                    }

                    if (EditorGUI.EndChangeCheck() == true &&
                        this.AsyncUpdateCommand(data.unityData, path, newValue, typeof(Enum)) == true)
                    {
                        data.unityData.RecordChange(path, typeof(Enum), data.Value, newValue);
                    }
                }
                else
                {
                    EditorGUI.LabelField(r, data.Name, LC.G("NGInspector_NotAvailableYet"));

                    if (data.Inspector.Hierarchy.IsChannelBlocked(enumInstance.type.GetHashCode()) == true)
                    {
                        GUI.Label(r, GeneralStyles.StatusWheel);
                    }
                }
            }
        }