Пример #1
0
            public object PropertyEditorEnumerable(controlProperty property, IEnumerable value)
            {
                Editor.BeginVertical();
                property.expanded = Editor.Foldout(property.info.Name, property.expanded);
                if (property.expanded)
                {
                    var arrayIndex = 0;

                    foreach (var item in value)
                    {
                        var control = item as Control;
                        if (control != null)
                        {
                            if (Editor.Button("    " + arrayIndex, control.ToString()))
                            {
                                return(control);
                            }
                        }
                        else
                        {
                            if (arrayIndex >= property.arrayEditors.Count)
                            {
                                var itemText = "null";
                                if (item != null)
                                {
                                    itemText = item.ToString();
                                }

                                var aEditor = new objectEditor(item, arrayIndex + " (" + itemText + ")");
                                aEditor.backgroundRGB = MathHelper.Clamp(backgroundRGB - 25, 128, 255);

                                property.arrayEditors.Add(aEditor);
                            }

                            property.arrayEditors[arrayIndex].Draw();
                        }

                        arrayIndex++;
                    }
                }

                Editor.EndVertical();
                return(null);
            }
Пример #2
0
            public object Draw()
            {
                if (properties.Count == 0 && methods.Count == 0)
                {
                    Editor.Label(name);
                    return(null);
                }

                toggleEditor = Editor.Foldout(name, toggleEditor);

                Editor.BeginVertical(toggleEditor ? "Box" : null);

                if (toggleEditor)
                {
                    // Fields.
                    if (fields.Count > 0)
                    {
                        Editor.SetBackColor(Color.AliceBlue);
                        Editor.BeginVertical("Box");
                        Editor.Label("    Fields");

                        for (int i = 0; i < fields.Count; i++)
                        {
                            var tc = Draw(fields[i]);
                            if (tc != null)
                            {
                                return(tc);
                            }
                        }

                        Editor.EndVertical();
                        Editor.NewLine(1);
                    }

                    // Properties.
                    Editor.SetBackColor(Color.White);
                    if (toggleEditor)
                    {
                        Editor.SetBackColor(Color.FromArgb(backgroundRGB, backgroundRGB, backgroundRGB));
                    }

                    for (int i = 0; i < properties.Count; i++)
                    {
                        var tc = Draw(properties[i]);
                        if (tc != null)
                        {
                            return(tc);
                        }
                    }

                    // Methods.
                    if (methods.Count > 0)
                    {
                        if (properties.Count > 0)
                        {
                            Editor.NewLine(1);
                        }
                        Editor.SetBackColor(Color.Lavender);
                        Editor.BeginVertical("Box");
                        Editor.Label("    Methods");

                        for (int i = 0; i < methods.Count; i++)
                        {
                            var tc = Draw(methods[i]);
                            if (tc != null)
                            {
                                return(tc);
                            }
                        }

                        Editor.EndVertical();
                    }
                }

                Editor.EndVertical();

                if (toggleEditor)
                {
                    Editor.NewLine(1);
                }

                return(null);
            }
Пример #3
0
            public object Draw()
            {
                object control = null;

                if (props.Count == 0 && methods.Count == 0)
                {
                    Editor.Label(name);
                    return(null);
                }

                toggleEditor = Editor.Foldout(name, toggleEditor);
                var style = toggleEditor ? "Box" : null;

                Editor.BeginVertical(style);
                if (toggleEditor)
                {
                    // Fields.
                    if (fields.Count > 0)
                    {
                        Editor.SetBackColor(Color.AliceBlue);
                        Editor.BeginVertical("Box");
                        for (int i = 0; i < fields.Count; i++)
                        {
                            var tc = Draw(fields[i]);
                            if (tc != null)
                            {
                                control = tc;
                            }
                        }
                        Editor.EndVertical();

                        Editor.NewLine(1);
                    }

                    // Properties.
                    Editor.SetBackColor(Color.White);
                    if (toggleEditor)
                    {
                        Editor.SetBackColor(Color.FromArgb(rgb, rgb, rgb));
                    }
                    for (int i = 0; i < props.Count; i++)
                    {
                        var tc = Draw(props[i]);
                        if (tc != null)
                        {
                            control = tc;
                        }
                    }

                    // Methods.
                    Editor.SetBackColor(Color.White);
                    if (methods.Count > 0)
                    {
                        Editor.NewLine(1);

                        for (int i = 0; i < methods.Count; i++)
                        {
                            var tc = Draw(methods[i]);
                            if (tc != null)
                            {
                                control = tc;
                            }
                        }
                    }
                }
                Editor.EndVertical();

                if (toggleEditor)
                {
                    Editor.NewLine(1);
                }

                return(control);
            }
Пример #4
0
            public object Draw(controlProperty p)
            {
                object controlToSet = null;

                if (p.info.CanRead == false)
                {
                    return(null);
                }

                var  val  = p.info.GetValue(obj, null);
                Type type = null;

                if (val != null)
                {
                    type = val.GetType();
                }
                else
                {
                    Editor.Label(p.info.Name, "null");
                    return(null);
                }

                // Array & List.
                if (val is string == false)
                {
                    if (type.IsArray || val is IEnumerable)
                    {
                        Editor.BeginVertical();
                        p.expanded = Editor.Foldout(p.info.Name, p.expanded);
                        if (p.expanded)
                        {
                            var vEnum      = val as IEnumerable;
                            var arrayIndex = 0;
                            foreach (var e in vEnum)
                            {
                                var ec = e as Control;
                                if (ec != null)
                                {
                                    if (Editor.Button(ec.ToString()))
                                    {
                                        controlToSet = ec;
                                    }
                                }
                                else
                                {
                                    if (arrayIndex >= p.arrayEditors.Count)
                                    {
                                        var aEditor = new objectEditor(e, arrayIndex.ToString());
                                        aEditor.rgb = rgb - 25;
                                        if (aEditor.rgb < 128)
                                        {
                                            aEditor.rgb = 128;
                                        }
                                        p.arrayEditors.Add(aEditor);
                                    }

                                    p.arrayEditors[arrayIndex].Draw();
                                }
                                arrayIndex++;
                            }
                        }
                        Editor.EndVertical();
                        return(controlToSet);
                    }
                }

                // If there is no Set() method then skip.
                var canSet     = true;
                var pSetMethod = p.info.GetSetMethod(true);

                if (pSetMethod == null || pSetMethod.IsPrivate)
                {
                    canSet = false;
                }

                // Other editors.
                if (val is bool)
                {
                    if (canSet == false)
                    {
                        Editor.Label(p.info.Name, val);
                        return(null);
                    }

                    var bVal  = (bool)val;
                    var ebVal = Editor.BooleanField(p.info.Name, bVal);
                    if (ebVal.Changed)
                    {
                        p.info.SetValue(obj, ebVal.Value, null);
                    }
                }
                else if (val is Control)
                {
                    var cVal = val as Control;
                    if (Editor.Button(p.info.Name, cVal.GetType().Name))
                    {
                        controlToSet = cVal;
                    }
                }
                else if (val is Color)
                {
                    if (canSet == false)
                    {
                        Editor.Label(p.info.Name, val);
                        return(null);
                    }

                    var colorVal = (Color)val;
                    Editor.ColorField(p.info.Name, colorVal, c => p.info.SetValue(obj, c, null));
                }
                else if (val is string)
                {
                    if (canSet == false)
                    {
                        Editor.Label(p.info.Name, val);
                        return(null);
                    }

                    var stringtVal = (string)val;
                    var esVal      = Editor.TextField(p.info.Name, stringtVal);
                    if (esVal.Changed)
                    {
                        p.info.SetValue(obj, esVal.Value, null);
                    }
                }
                else if (val is int)
                {
                    if (canSet == false)
                    {
                        Editor.Label(p.info.Name, val);
                        return(null);
                    }

                    var eiVal = Editor.IntField(p.info.Name, (int)val);
                    if (eiVal.Changed)
                    {
                        p.info.SetValue(obj, eiVal.Value[0], null);
                    }
                }
                else if (val is byte || val is sbyte || val is short || val is ushort || val is uint || val is long || val is ulong || val is float || val is double)
                {
                    if (canSet == false)
                    {
                        Editor.Label(p.info.Name, val);
                        return(null);
                    }

                    // TODO: editors for common types (like for int ^up there).
                    Editor.Label(p.info.Name, val);
                }
                else if (val is Enum)
                {
                    if (canSet == false)
                    {
                        Editor.Label(p.info.Name, val);
                        return(null);
                    }

                    var enumHasFlagAttribute = val.GetType().GetCustomAttributes(typeof(FlagsAttribute), false).Length > 0;
                    var enumOptions          = Enum.GetNames(val.GetType());

                    if (enumHasFlagAttribute)
                    {
                        // TODO: not gonna work with 'None' flag.
                        // https://forum.unity3d.com/threads/editorguilayout-enummaskfield-doesnt-use-enums-values.233332/
                        var eeVal = Editor.MaskField(p.info.Name, Convert.ToInt32(val), enumOptions);
                        if (eeVal.Changed)
                        {
                            p.info.SetValue(obj, eeVal.Value, null);
                        }
                    }
                    else
                    {
                        var eeVal = Editor.EnumField(p.info.Name, (Enum)val);
                        if (eeVal.Changed)
                        {
                            p.info.SetValue(obj, eeVal.Value, null);
                        }
                    }
                }
                else if (val != null)
                {
                    if (p.editor == null)
                    {
                        p.editor     = new objectEditor(val, p.info.Name);
                        p.editor.rgb = rgb - 25;
                        if (p.editor.rgb < 128)
                        {
                            p.editor.rgb = 128;
                        }
                    }

                    p.editor.Draw();
                }

                return(controlToSet);
            }
Пример #5
0
            public object Draw()
            {
                if (properties.Count == 0 && methods.Count == 0)
                {
                    Editor.Label(name);
                    return(null);
                }

                toggleEditor = Editor.Foldout(name, toggleEditor);

                Editor.BeginVertical(toggleEditor ? "Box" : null);

                if (toggleEditor)
                {
                    // Fields.
                    if (fields.Count > 0)
                    {
                        Editor.SetBackColor(Color.AliceBlue);
                        Editor.BeginVertical("Box");
                        Editor.Label("    Fields");

                        for (int i = 0; i < fields.Count; i++)
                        {
                            var tc = Draw(fields[i]);
                            if (tc != null)
                            {
                                return(tc);
                            }
                        }

                        Editor.EndVertical();
                        Editor.NewLine(1);
                    }

                    // Properties.
                    Editor.SetBackColor(Color.White);
                    if (toggleEditor)
                    {
                        Editor.SetBackColor(Color.FromArgb(backgroundRGB, backgroundRGB, backgroundRGB));
                    }

                    for (int i = 0; i < properties.Count; i++)
                    {
                        var tc = Draw(properties[i]);
                        if (tc != null)
                        {
                            return(tc);
                        }
                    }

                    // Methods.
                    if (methods.Count > 0)
                    {
                        if (properties.Count > 0)
                        {
                            Editor.NewLine(1);
                        }
                        Editor.SetBackColor(Color.Lavender);
                        Editor.BeginVertical("Box");
                        Editor.Label("    Methods");

                        for (int i = 0; i < methods.Count; i++)
                        {
                            var tc = Draw(methods[i]);
                            if (tc != null)
                            {
                                return(tc);
                            }
                        }

                        Editor.EndVertical();
                    }

                    // Array & List.
                    if (!(target is string) && (target.GetType().IsArray || target is IEnumerable))
                    {
                        Editor.BeginVertical();

                        {
                            var arrayIndex = 0;
                            var e          = target as IEnumerable;

                            foreach (var item in e)
                            {
                                var control = item as Control;
                                if (control != null)
                                {
                                    if (Editor.Button("    " + arrayIndex, control.ToString()))
                                    {
                                        return(control);
                                    }
                                }
                                else
                                {
                                    if (arrayIndex >= arrayEditors.Count)
                                    {
                                        var itemText = "null";
                                        if (item != null)
                                        {
                                            itemText = item.ToString();
                                        }

                                        var aEditor = new ObjectEditor(item, arrayIndex + " (" + itemText + ")");
                                        aEditor.backgroundRGB = MathHelper.Clamp(backgroundRGB - 25, 128, 255);

                                        arrayEditors.Add(aEditor);
                                    }

                                    arrayEditors[arrayIndex].Draw();
                                }

                                arrayIndex++;
                            }
                        }

                        Editor.EndVertical();
                    }
                }

                Editor.EndVertical();

                if (toggleEditor)
                {
                    Editor.NewLine(1);
                }

                return(null);
            }