public override bool InspectSelf(Inspector inspector, string name, ref object data, Type type)
        {
            var e = data as Enum;

            if (e == null)
            {
                return(false);
            }
            if (TypeTools.GetAttribute <FlagsAttribute>(type) != null)
            {
                return(ApplyValueIfNotEqual(ref data, GUITools.EnumMaskField(name, e)));
            }
            else
            {
                return(ApplyValueIfNotEqual(ref data, GUITools.EnumPopup(name, e)));
            }
        }
        public override bool InspectSelf(Inspector inspector, string name, ref object data, Type type)
        {
            if (data == null)
            {
                GUITools.LabelField("null");
                GUILayout.FlexibleSpace();
                return(false);
            }

            if (ShowSize())
            {
                GUITools.LabelField("Count: " + Size(data));
            }

            GUILayout.FlexibleSpace();
            return(false);
        }
        private static bool Traversal(Inspector inspector, string path, DictionaryGUIState state, int start, int end)
        {
            bool changed    = false;
            var  bucketSize = Math.Max(state.display.bucketSize, 2);
            var  valueType  = state.ValueType();

            if (end - start <= bucketSize)
            {
                for (int index = start; index < end; ++index)
                {
                    changed |= InspectElement(inspector, path, state.display.resultKeys[index], state, valueType);
                }
            }
            else
            {
                // Allow multiple level of bucket, calculate the current step
                int step = bucketSize;
                while (step * bucketSize < end - start)
                {
                    step *= bucketSize;
                }

                for (int inner = start; inner < end; inner += step)
                {
                    int innerEnd = Math.Min(end, inner + step);

                    var innerKeyBegin = state.display.resultKeys[inner];
                    var innerKeyEnd   = state.display.resultKeys[innerEnd - 1];
                    var label         = FormatKeyRange(innerKeyBegin, innerKeyEnd);
                    var foldoutPath   = path + "[" + innerKeyBegin + "~" + innerKeyEnd + "]";

                    inspector.isFoldout[foldoutPath] = GUITools.Foldout(inspector.isFoldout.ContainsKey(foldoutPath) && inspector.isFoldout[foldoutPath], label);
                    if (inspector.isFoldout[foldoutPath])
                    {
                        using (GUITools.Indent())
                        {
                            changed |= Traversal(inspector, path, state, inner, innerEnd);
                        }
                    }
                }
            }

            return(changed);
        }
        public override bool InspectChildren(Inspector inspector, string path, ref object data, Type type)
        {
            if (data == null)
            {
                return(false);
            }

            if (Resizable(data))
            {
                var oldSize = Size(data);
                int size    = Math.Max(0, GUITools.IntField("Size", oldSize));
                if (size != oldSize)
                {
                    data = Resize(data, size);
                    return(true);
                }
            }

            return(GUIContainerTools.EditDict(inspector, path, data, this));
        }
        public bool Inspect(string name, string path, object data,
                            Type type  = null,
                            IMark mark = null,
                            Action <object> OnValueChanged = null)
        {
            if (inInspector)
            {
                return(InspectInternal(name, path, data, type, mark, OnValueChanged));
            }

            try
            {
                inInspector = true;
                GUITools.Setup();
                return(InspectInternal(name, path, data, type, mark, OnValueChanged));
            }
            finally
            {
                inInspector = false;
            }
        }
        private static bool InspectProperty(Inspector inspector, string path, ref object data,
                                            PropertyInfo propertyInfo)
        {
            if (propertyInfo.CanRead && CanInspect(propertyInfo))
            {
                object value;
                try
                {
                    value = propertyInfo.GetValue(data, null);
                }
                catch (Exception)
                {
                    return(false);
                }

                return(inspector.Inspect(propertyInfo.Name, path + "." + propertyInfo.Name, value));
            }
            else
            {
                GUITools.LabelField(propertyInfo.Name, "unreadable");
                return(false);
            }
        }
        public override bool InspectChildren(Inspector inspector, string path, ref object data, Type type)
        {
            var time = (DateTime)data;

            GUITools.LabelField("Unix Time Stamp", ToUnixTimestampString(time));

            var ticks = GUITools.LongField("Ticks", time.Ticks);
            var kind  = (DateTimeKind)GUITools.EnumPopup("Kind", time.Kind);

            if (ticks != time.Ticks || kind != time.Kind)
            {
                try
                {
                    data = new DateTime(ticks, kind);
                    return(true);
                }
                catch (Exception)
                {
                }
            }

            return(false);
        }
 public override bool AlwaysShowChildren()
 {
     return(GUITools.IsInEditor() == false);
 }
 public override bool HasChildren()
 {
     return(GUITools.IsInEditor() == false);
 }
        // Boolean, Byte, SByte, Int16, UInt16, Int32, UInt32, Int64, UInt64, IntPtr, UIntPtr, Char, Double, and Single.
        public override bool InspectSelf(Inspector inspector, string name, ref object data, Type type)
        {
            object result;

            if (data == null)
            {
                GUITools.LabelField(name, "null");
                result = null;
            }
            else if (data is bool)
            {
                result = (bool)GUITools.Toggle(name, (bool)data);
            }
            else if (data is byte)
            {
                result = (byte)GUITools.IntField(name, (byte)data);
            }
            else if (data is sbyte)
            {
                result = (sbyte)GUITools.IntField(name, (sbyte)data);
            }
            else if (data is short)
            {
                result = (short)GUITools.IntField(name, (short)data);
            }
            else if (data is ushort)
            {
                result = (ushort)GUITools.IntField(name, (ushort)data);
            }
            else if (data is int)
            {
                result = (int)GUITools.IntField(name, (int)data);
            }
            else if (data is uint)
            {
                result = (uint)GUITools.LongField(name, (uint)data);
            }
            else if (data is long)
            {
                result = (long)ParseLong(GUITools.TextField(name, data.ToString()), (long)data);
            }
            else if (data is ulong)
            {
                result = (ulong)ParseULong(GUITools.TextField(name, data.ToString()), (ulong)data);
            }
            else if (data is IntPtr)
            {
                GUITools.TextField(name, data.ToString());
                result = data;
            }
            else if (data is UIntPtr)
            {
                GUITools.TextField(name, data.ToString());
                result = data;
            }
            else if (data is char)
            {
                result = (char)ParseChar(GUITools.TextField(name, data.ToString()), (char)data);
            }
            else if (data is float)
            {
                result = (float)GUITools.FloatField(name, (float)data);
            }
            else if (data is double)
            {
                result = (double)GUITools.DoubleField(name, (double)data);
            }
            else
            {
                throw new NotImplementedException(type.Name);
            }

            return(ApplyValueIfNotEqual(ref data, result));
        }
        public override bool InspectChildren(Inspector inspector, string path, ref object data, Type type)
        {
            var timestamp = (int)data;

            return(ApplyValueIfNotEqual(ref data, GUITools.IntField("Unix Time Stamp", timestamp)));
        }
Пример #12
0
        public bool InspectInternal(string name, string path, object data,
                                    Type type  = null,
                                    IMark mark = null,
                                    Action <object> OnValueChanged = null)
        {
            if (data != null)
            {
                type = data.GetType();
            }

            GUITools.SetLabelWidth(options.labelWidth);
            VisualizerBase visualizer  = GetVisualizer(type, mark);
            bool           changed     = false;
            object         changedData = data;

            if (visualizer != null)
            {
                string fieldinfo = name;
                var    postfix   = visualizer.GetLabelPostfix(this, data, type);
                if (postfix != null)
                {
                    fieldinfo += postfix;
                }

                if (visualizer.HasChildren())
                {
                    // Note: to avoid infinite expand that may cause by alwaysShowChildren,
                    // If parentAlwaysShowChild, then current node ignores alwaysShowChildren.
                    var  parentAlwaysShowChild = parentIsAlwaysShow.Count > 0 && parentIsAlwaysShow.Peek();
                    bool alwaysShowChildren    = !parentAlwaysShowChild && visualizer.AlwaysShowChildren();
                    if (!alwaysShowChildren)
                    {
                        using (GUITools.HorizontalScope())
                        {
                            var width = options.labelWidth - options.indentOffset * GUITools.GetIndentLevel();
                            using (GUITools.HorizontalScope(width))
                            {
                                isFoldout[path] = GUITools.Foldout(isFoldout.ContainsKey(path) && isFoldout[path], fieldinfo);
                            }
                            changed |= InspectRoot(name, type, ref changedData, visualizer, mark);
                        }
                    }
                    else
                    {
                        changed |= InspectRoot(name, type, ref changedData, visualizer, mark);
                    }

                    if (changedData != null && (alwaysShowChildren || isFoldout[path]))
                    {
                        try
                        {
                            parentIsAlwaysShow.Push(alwaysShowChildren);
                            using (GUITools.Indent())
                                changed |= visualizer.InspectChildren(this, path, ref changedData, type);
                        }
                        finally
                        {
                            parentIsAlwaysShow.Pop();
                        }
                    }
                }
                else
                {
                    changed |= InspectRoot(fieldinfo, type, ref changedData, visualizer, mark);
                }
            }

            if (changed && OnValueChanged != null)
            {
                OnValueChanged(changedData);
            }
            return(changed);
        }