浏览代码

inspector

/main
fzhangtj 6 年前
当前提交
f05de4ec
共有 33 个文件被更改,包括 2880 次插入89 次删除
  1. 1
      Assets/UIWidgets/Tests/EditableTextWiget.cs
  2. 1
      Assets/UIWidgets/Tests/Paragraph.cs
  3. 4
      Assets/UIWidgets/Tests/Widgets.cs
  4. 67
      Assets/UIWidgets/editor/editor_window.cs
  5. 14
      Assets/UIWidgets/foundation/diagnostics.cs
  6. 2
      Assets/UIWidgets/painting/box_decoration.cs
  7. 27
      Assets/UIWidgets/painting/text_span.cs
  8. 7
      Assets/UIWidgets/rendering/box.cs
  9. 172
      Assets/UIWidgets/rendering/editable.cs
  10. 2
      Assets/UIWidgets/rendering/object.cs
  11. 30
      Assets/UIWidgets/rendering/paragraph.cs
  12. 4
      Assets/UIWidgets/rendering/proxy_box.cs
  13. 4
      Assets/UIWidgets/rendering/sliver.cs
  14. 5
      Assets/UIWidgets/rendering/stack.cs
  15. 9
      Assets/UIWidgets/rendering/view.cs
  16. 3
      Assets/UIWidgets/ui/painting/picture.cs
  17. 127
      Assets/UIWidgets/widgets/basic.cs
  18. 3
      Assets/UIWidgets/widgets/binding.cs
  19. 97
      Assets/UIWidgets/widgets/app.cs
  20. 3
      Assets/UIWidgets/widgets/app.cs.meta
  21. 1001
      Assets/UIWidgets/widgets/widget_inspector.cs
  22. 3
      Assets/UIWidgets/widgets/widget_inspector.cs.meta
  23. 410
      Assets/UIWidgets/debugger/diagnostics.cs
  24. 309
      Assets/UIWidgets/debugger/inpsector_panel.cs
  25. 3
      Assets/UIWidgets/debugger/inpsector_panel.cs.meta
  26. 66
      Assets/UIWidgets/debugger/inspector_objectgroup.cs
  27. 3
      Assets/UIWidgets/debugger/inspector_objectgroup.cs.meta
  28. 146
      Assets/UIWidgets/debugger/inspector_service.cs
  29. 258
      Assets/UIWidgets/debugger/inspector_treeview.cs
  30. 3
      Assets/UIWidgets/debugger/inspector_treeview.cs.meta
  31. 182
      Assets/UIWidgets/debugger/inspector_window.cs
  32. 3
      Assets/UIWidgets/debugger/inspector_window.cs.meta

1
Assets/UIWidgets/Tests/EditableTextWiget.cs


}
void OnDestroy() {
this.windowAdapter.Destory();
this.windowAdapter = null;
}
}

1
Assets/UIWidgets/Tests/Paragraph.cs


}
void OnDestroy() {
this.windowAdapter.Destory();
this.windowAdapter = null;
}

4
Assets/UIWidgets/Tests/Widgets.cs


}
void OnDestroy() {
this.windowAdapter.Destory();
this.windowAdapter = null;
}

}
Widget asPage() {
return new AsScreen();
//return new AsScreen();
return new WidgetInspector(null, new AsScreen(), null);
}
}

67
Assets/UIWidgets/editor/editor_window.cs


using UnityEngine;
using Rect = UnityEngine.Rect;
namespace UIWidgets.editor {
namespace UIWidgets.editor {
public WindowAdapter(EditorWindow editorWindow) {
private static List<WindowAdapter> _windowAdapters = new List<WindowAdapter>();
private bool _alive;
public static IEnumerable<WindowAdapter> windowAdapters
{
get { return _windowAdapters; }
}
public WindowAdapter(EditorWindow editorWindow)
{
this._alive = true;
this.editorWindow = editorWindow;
this.editorWindow.wantsMouseMove = false;
this.editorWindow.wantsMouseEnterLeaveWindow = false;

finally {
instance = null;
}
_windowAdapters.Add(this);
public bool alive
{
get { return _alive; }
}
public void Destory()
{
var index = _windowAdapters.FindIndex(w => w == this);
if (index >= 0)
{
_windowAdapters.RemoveAt(index);
}
this._alive = false;
}
public WidgetInspectorService widgetInspectorService
{
get { return _binding.widgetInspectorService; }
}
readonly WidgetsBinding _binding;
readonly RasterCache _rasterCache;

try {
this.doOnGUI();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
public void WithBinding(Action fn)
{
instance = this;
WidgetsBinding.instance = this._binding;
try
{
fn();
}
finally {
instance = null;
WidgetsBinding.instance = null;
}
}
public T WithBindingFunc<T>(Func<T> fn)
{
instance = this;
WidgetsBinding.instance = this._binding;
try
{
return fn();
}
finally {
instance = null;

14
Assets/UIWidgets/foundation/diagnostics.cs


{"name", this.name},
{"showSeparator", this.showSeparator},
{"description", this.toDescription()},
{"level", this.level.ToString()},
{"level", Convert.ToString(this.level)},
{"style", this.style.ToString()},
{"valueToString", this.valueObject.ToString()},
{"style", Convert.ToString(this.style)},
{"valueToString", Convert.ToString(valueObject)},
{"type", this.GetType().ToString()},
{"hasChildren", this.getChildren().isNotEmpty()}
};

return "\"" + text + "\"";
}
return text;
return text ?? "null";
}
}

}
public delegate T ComputePropertyValueCallback<T>();
public class DiagnosticsProperty<T> : DiagnosticsNode {
public DiagnosticsProperty(
string name,

public override Dictionary<string, object> toJsonMap() {
var json = base.toJsonMap();
if (this.defaultValue != Diagnostics.kNoDefaultValue) {
json["defaultValue"] = this.defaultValue == null ? "null" : this.defaultValue.ToString();
json["defaultValue"] = Convert.ToString(this.defaultValue);
}
if (this.ifEmpty != null) {

json["propertyType"] = this.propertyType.ToString();
json["valueToString"] = this.valueToString();
json["defaultLevel"] = this._defaultLevel.ToString();
json["defaultLevel"] = Convert.ToString(this._defaultLevel);
if (typeof(Diagnosticable).IsAssignableFrom(typeof(T))) {
json["isDiagnosticableValue"] = true;
}

2
Assets/UIWidgets/painting/box_decoration.cs


public override BoxPainter createBoxPainter(VoidCallback onChanged = null) {
return new _BoxDecorationPainter(this, onChanged);
}
public bool Equals(BoxDecoration other) {
if (object.ReferenceEquals(null, other)) return false;
if (object.ReferenceEquals(this, other)) return true;

27
Assets/UIWidgets/painting/text_span.cs


using System.Linq;
using System.Text;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UIWidgets.ui;
using UnityEditor;
using UnityEngine.Assertions;

public readonly TextStyle style;
public readonly string text;
public readonly List<TextSpan> children;
public readonly GestureMock recognizer;
public readonly GestureRecognizer recognizer;
public TextSpan(string text = "", TextStyle style = null, List<TextSpan> children = null)
{

return left.SequenceEqual(right);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.defaultDiagnosticsTreeStyle = DiagnosticsTreeStyle.whitespace;
// Properties on style are added as if they were properties directly on
// this TextSpan.
if (style != null)
{
style.debugFillProperties(properties);
}
properties.add(new DiagnosticsProperty<GestureRecognizer>(
"recognizer", recognizer,
description: recognizer == null ? "" : recognizer.GetType().FullName,
defaultValue: Diagnostics.kNullDefaultValue
));
properties.add(new StringProperty("text", text, showName: false, defaultValue: Diagnostics.kNullDefaultValue));
if (style == null && text == null && children == null)
{
properties.add(DiagnosticsNode.message("(empty)"));
}
}
public override List<DiagnosticsNode> debugDescribeChildren() {
if (children == null)
{

7
Assets/UIWidgets/rendering/box.cs


});
return result;
}
public override Rect semanticBounds
{
get { return Offset.zero & size; }
}
protected override void debugResetSize() {
size = size;
}

172
Assets/UIWidgets/rendering/editable.cs


{
_showCursor.removeListener(markNeedsPaint);
}
_showCursor = value;
if (attached)
{

{
var caretOffset = _textPainter.getOffsetForCaret(selection.extendPos, _caretPrototype);
var start = new Offset(0.0, preferredLineHeight) + caretOffset + paintOffset;
return new List<TextSelectionPoint>{new TextSelectionPoint(start, null)};
return new List<TextSelectionPoint> {new TextSelectionPoint(start, null)};
}
else
{

var end = new Offset(boxes[last].end, boxes[last].bottom) + paintOffset;
return new List<TextSelectionPoint>
{
new TextSelectionPoint(start, boxes[0].direction),
new TextSelectionPoint(end, boxes[last].direction),
};
{
new TextSelectionPoint(start, boxes[0].direction),
new TextSelectionPoint(end, boxes[last].direction),
};
}
}

{
return _textPainter.getPositionVerticalMove(position, 1);
}
return new TextPosition(offset:line.start, affinity:affinity??position.affinity);
return new TextPosition(offset: line.start, affinity: affinity ?? position.affinity);
}
public bool isLineEndOrStart(int offset)

return false;
}
return new TextPosition(offset:line.endIncludingNewLine, affinity:affinity??position.affinity);
return new TextPosition(offset: line.endIncludingNewLine, affinity: affinity ?? position.affinity);
}
}
}
}
public TextPosition getParagraphStart(TextPosition position, TextAffinity? affinity = null)
{

}
var line = _textPainter.getLineRange(lineIndex);
return new TextPosition(offset:line.start, affinity:affinity??position.affinity);
}
return new TextPosition(offset: line.start, affinity: affinity ?? position.affinity);
}
public TextPosition getParagraphEnd(TextPosition position, TextAffinity? affinity = null)
{
D.assert(!_needsLayout);

{
break;
}
return new TextPosition(offset:_textPainter.getLineRange(lineIndex).endIncludingNewLine,
affinity:affinity??position.affinity);
return new TextPosition(offset: _textPainter.getLineRange(lineIndex).endIncludingNewLine,
affinity: affinity ?? position.affinity);
}
public TextPosition getParagraphForward(TextPosition position, TextAffinity? affinity = null)

{
continue;
}
}
}
return new TextPosition(position.offset, affinity??position.affinity);
return new TextPosition(position.offset, affinity ?? position.affinity);
return new TextPosition(line.end, affinity??position.affinity);
return new TextPosition(line.end, affinity ?? position.affinity);
public TextPosition getParagraphBackward(TextPosition position, TextAffinity? affinity = null)
{
var lineCount = _textPainter.getLineCount();

{
continue;
}
}
}
return new TextPosition(position.offset, affinity??position.affinity);
return new TextPosition(position.offset, affinity ?? position.affinity);
return new TextPosition(line.start, affinity??position.affinity);
return new TextPosition(line.start, affinity ?? position.affinity);
protected override double computeMinIntrinsicWidth(double height) {
protected override double computeMinIntrinsicWidth(double height)
{
protected override double computeMaxIntrinsicWidth(double height) {
protected override double computeMaxIntrinsicWidth(double height)
{
protected override double computeMinIntrinsicHeight(double width) {
protected override double computeMinIntrinsicHeight(double width)
{
protected override double computeMaxIntrinsicHeight(double width) {
protected override double computeMaxIntrinsicHeight(double width)
{
protected override double? computeDistanceToActualBaseline(TextBaseline baseline) {
protected override double? computeDistanceToActualBaseline(TextBaseline baseline)
{
public override void handleEvent(PointerEvent evt, HitTestEntry entry) {
public override void handleEvent(PointerEvent evt, HitTestEntry entry)
{
if (evt is PointerDownEvent && onSelectionChanged != null) {
_tap.addPointer((PointerDownEvent)evt);
_doubleTap.addPointer((PointerDownEvent)evt);
if (evt is PointerDownEvent && onSelectionChanged != null)
{
_tap.addPointer((PointerDownEvent) evt);
_doubleTap.addPointer((PointerDownEvent) evt);
// todo long press
}
}

onSelectionChanged(TextSelection.fromPosition(position), this, SelectionChangedCause.tap);
}
}
public void handleDoubleTap()
{
_layoutText(constraints.maxWidth);

onSelectionChanged(_selectWordAtOffset(position), this, SelectionChangedCause.doubleTap);
}
}
protected override void performLayout() {
protected override void performLayout()
{
_layoutText(constraints.maxWidth);
_caretPrototype = Rect.fromLTWH(0.0, _kCaretHeightOffset, _kCaretWidth,
preferredLineHeight - 2.0 * _kCaretHeightOffset);

_paintContents(context, offset);
}
}
protected override bool hitTestSelf(Offset position)
{
return true;

}
// describeSemanticsConfiguration todo
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Color>("cursorColor", cursorColor));
properties.add(new DiagnosticsProperty<ValueNotifier<bool>>("showCursor", showCursor));
properties.add(new DiagnosticsProperty<int>("maxLines", maxLines));
properties.add(new DiagnosticsProperty<Color>("selectionColor", selectionColor));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor));
properties.add(new DiagnosticsProperty<TextSelection>("selection", selection));
properties.add(new DiagnosticsProperty<ViewportOffset>("offset", offset));
}
private void _paintCaret(Canvas canvas, Offset effectiveOffset)
{

D.assert(_textLayoutLastWidth == constraints.maxWidth);
D.assert(_selectionRects != null);
var paint = new Paint() {color = _selectionColor};
foreach (var box in _selectionRects)
{
canvas.drawRect(box.toRect().shift(effectiveOffset), BorderWidth.zero, BorderRadius.zero, paint);

{
D.assert(_textLayoutLastWidth == constraints.maxWidth);
var effectiveOffset = offset + _paintOffset;
if (_selection != null) {
if (_selection.isCollapsed && _showCursor.value && cursorColor != null) {
if (_selection != null)
{
if (_selection.isCollapsed && _showCursor.value && cursorColor != null)
{
} else if (!_selection.isCollapsed && _selectionColor != null) {
_selectionRects = _selectionRects??_textPainter.getBoxesForSelection(_selection);
}
else if (!_selection.isCollapsed && _selectionColor != null)
{
_selectionRects = _selectionRects ?? _textPainter.getBoxesForSelection(_selection);
if (_hasFocus) {
var caretOffset = _textPainter.getOffsetForCaret(_selection.extendPos, Rect.fromLTWH(0, 0, 1, preferredLineHeight));
if (_hasFocus)
{
var caretOffset =
_textPainter.getOffsetForCaret(_selection.extendPos, Rect.fromLTWH(0, 0, 1, preferredLineHeight));
Input.compositionCursorPos = new Vector2((float)caretRec.left, (float)caretRec.bottom);
Input.compositionCursorPos = new Vector2((float) caretRec.left, (float) caretRec.bottom);
private void _handleSetSelection(TextSelection selection)
{
onSelectionChanged(selection, this, SelectionChangedCause.keyboard);

return preferredLineHeight * lines;
}
_layoutText(width);
return Math.Max(preferredLineHeight, _textPainter.height);
}

{
return TextSelection.fromPosition(position);
}
private bool _isMultiline
{
get { return _maxLines != 1; }

}
return 0.0;
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties)
{
base.debugFillProperties(properties);
properties.add(new DiagnosticsProperty<Color>("cursorColor", cursorColor));
properties.add(new DiagnosticsProperty<ValueNotifier<bool>>("showCursor", showCursor));
properties.add(new DiagnosticsProperty<int>("maxLines", maxLines));
properties.add(new DiagnosticsProperty<Color>("selectionColor", selectionColor));
properties.add(new DiagnosticsProperty<double>("textScaleFactor", textScaleFactor));
properties.add(new DiagnosticsProperty<TextSelection>("selection", selection));
properties.add(new DiagnosticsProperty<ViewportOffset>("offset", offset));
}
public override List<DiagnosticsNode> debugDescribeChildren()
{
return new List<DiagnosticsNode>
{
text.toDiagnosticsNode(
name: "text",
style: DiagnosticsTreeStyle.transition
),
};
}
}
}

2
Assets/UIWidgets/rendering/object.cs


return null;
}
public abstract Rect semanticBounds { get; }
public virtual void handleEvent(PointerEvent evt, HitTestEntry entry) {
}

30
Assets/UIWidgets/rendering/paragraph.cs


using System;
using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.painting;
using UIWidgets.ui;
using UnityEngine;

_layoutTextWithConstraints(constraints);
return _textPainter.computeDistanceToActualBaseline(baseline);
}
protected override bool hitTestSelf(Offset position)
{
return true;
}
protected override void performLayout() {
_layoutTextWithConstraints(constraints);
var textSize = _textPainter.size;

private void _layoutTextWithConstraints(BoxConstraints constraints) {
_layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
}
public override List<DiagnosticsNode> debugDescribeChildren()
{
return new List<DiagnosticsNode>
{
text.toDiagnosticsNode(name: "text", style: DiagnosticsTreeStyle.transition)
};
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<TextAlign>("textAlign", textAlign));
properties.add(new EnumProperty<TextDirection?>("textDirection", textDirection));
properties.add(new FlagProperty("softWrap", value: softWrap, ifTrue: "wrapping at box width",
ifFalse: "no wrapping except at line break characters", showName: true));
properties.add(new EnumProperty<TextOverflow>("overflow", overflow));
properties.add(new DoubleProperty("textScaleFactor", textScaleFactor, defaultValue: 1.0));
properties.add(new IntProperty("maxLines", maxLines, ifNull: "unlimited"));
}
}
}

4
Assets/UIWidgets/rendering/proxy_box.cs


this.markNeedsPaint();
}
protected override bool hitTestSelf(Offset position) {
return _decoration.hitTest(size, position);
}
public override void paint(PaintingContext context, Offset offset) {
this._painter = this._painter ?? this._decoration.createBoxPainter(this.markNeedsPaint);
var filledConfiguration = this.configuration.copyWith(size: this.size);

4
Assets/UIWidgets/rendering/sliver.cs


return null;
}
}
public override Rect semanticBounds {
get { return paintBounds; }
}
protected override void debugResetSize() {
}

5
Assets/UIWidgets/rendering/stack.cs


using UIWidgets.painting;
using UIWidgets.ui;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UnityEngine;
using Rect = UIWidgets.ui.Rect;

}
}
protected override bool hitTestChildren(HitTestResult result, Offset position = null) {
return defaultHitTestChildren(result, position: position);
}
public void paintStack(PaintingContext context, Offset offset) {
defaultPaint(context, offset);
}

9
Assets/UIWidgets/rendering/view.cs


using System;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UIWidgets.painting;
using UIWidgets.ui;
using UnityEngine;
using Rect = UIWidgets.ui.Rect;

get { return Offset.zero & (this.size * this.configuration.devicePixelRatio); }
}
public override Rect semanticBounds {
get
{
D.assert(_rootTransform != null);
return MatrixUtils.transformRect(_rootTransform, Offset.zero & size);
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
D.assert(() => {
properties.add(DiagnosticsNode.message("debug mode enabled"));

3
Assets/UIWidgets/ui/painting/picture.cs


this.addPaintBounds(drawPicture.picture.paintBounds);
} else if (drawCmd is DrawConcat) {
this._transform = ((DrawConcat) drawCmd).transform * this._transform;
} else if (drawCmd is DrawSetMatrix)
{
this._transform = ((DrawSetMatrix) drawCmd).matrix;
} else if (drawCmd is DrawSave) {
this.stack.Push(new CanvasRec(
this._transform,

127
Assets/UIWidgets/widgets/basic.cs


this.overflow = overflow;
}
public AlignmentDirectional alignment;
public TextDirection? textDirection;
public StackFit fit;
public rendering.Overflow overflow;
public readonly AlignmentDirectional alignment;
public readonly TextDirection? textDirection;
public readonly StackFit fit;
public readonly rendering.Overflow overflow;
public override RenderObject createRenderObject(BuildContext context) {

properties.add(new DiagnosticsProperty<AlignmentDirectional>("alignment", alignment));
properties.add(new EnumProperty<StackFit>("fit", fit));
properties.add(new EnumProperty<Overflow>("overflow", overflow));
}
}
public class Positioned : ParentDataWidget<Stack>
{
public Positioned(Widget child, Key key = null, double? left = null, double? top = null,
double? right = null, double? bottom = null, double? width = null, double? height = null) : base(key, child)
{
D.assert(left == null || right == null || width == null);
D.assert(top == null || bottom == null || height == null);
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
this.width = width;
this.height = height;
}
public static Positioned fromRect(Rect rect, Widget child, Key key = null)
{
return new Positioned(child, key: key, left: rect.left,
top: rect.top, width: rect.width, height: rect.height);
}
public static Positioned fromRelativeRect(Rect rect, Widget child, Key key = null)
{
return new Positioned(child, key: key, left: rect.left,
top: rect.top, right: rect.right, bottom: rect.bottom);
}
public static Positioned fill(Widget child, Key key = null)
{
return new Positioned(child, key: key, left: 0.0,
top: 0.0, right: 0.0, bottom: 0.0);
}
public static Positioned directional(Widget child, TextDirection textDirection, Key key = null,
double? start = null, double? top = null,
double? end = null, double? bottom = null, double? width = null, double? height = null)
{
D.assert(textDirection != null);
double? left = null;
double? right = null;
switch (textDirection)
{
case TextDirection.rtl:
left = end;
right = start;
break;
case TextDirection.ltr:
left = start;
right = end;
break;
}
return new Positioned(child, key:key, left: left, top: top, right: right, bottom: bottom, width: width, height: height);
}
public readonly double? left;
public readonly double? top;
public readonly double? right;
public readonly double? bottom;
public readonly double? width;
public readonly double? height;
public override void applyParentData(RenderObject renderObject) {
D.assert(renderObject.parentData is StackParentData);
StackParentData parentData = (StackParentData) renderObject.parentData;
bool needsLayout = false;
if (parentData.left != left) {
parentData.left = left;
needsLayout = true;
}
if (parentData.top != top) {
parentData.top = top;
needsLayout = true;
}
if (parentData.right != right) {
parentData.right = right;
needsLayout = true;
}
if (parentData.bottom != bottom) {
parentData.bottom = bottom;
needsLayout = true;
}
if (parentData.width != width) {
parentData.width = width;
needsLayout = true;
}
if (parentData.height != height) {
parentData.height = height;
needsLayout = true;
}
if (needsLayout) {
var targetParent = renderObject.parent;
if (targetParent is RenderObject)
((RenderObject)targetParent).markNeedsLayout();
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new DoubleProperty("left", left, defaultValue: null));
properties.add(new DoubleProperty("top", top, defaultValue: null));
properties.add(new DoubleProperty("right", right, defaultValue: null));
properties.add(new DoubleProperty("bottom", bottom, defaultValue: null));
properties.add(new DoubleProperty("width", width, defaultValue: null));
properties.add(new DoubleProperty("height", height, defaultValue: null));
}
}

3
Assets/UIWidgets/widgets/binding.cs


public WidgetsBinding() {
this.buildOwner.onBuildScheduled = this._handleBuildScheduled;
Window.instance.onLocaleChanged += this.handleLocaleChanged;
widgetInspectorService = new WidgetInspectorService(this);
this.addPersistentFrameCallback((duration) =>
{
MeshGenrator.tickNextFrame();

return this._observers.Remove(observer);
}
public readonly WidgetInspectorService widgetInspectorService;
protected override void handleMetricsChanged() {
base.handleMetricsChanged();
foreach (WidgetsBindingObserver observer in this._observers) {

97
Assets/UIWidgets/widgets/app.cs


using System;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UIWidgets.painting;
using UIWidgets.ui;
using UnityEngine;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.widgets
{
public class WidgetsApp : StatefulWidget
{
public readonly Widget child;
public WidgetsApp(Key key, Widget child) : base(key)
{
this.child = child;
}
public override State createState()
{
return new _WidgetsAppState();
}
}
class _WidgetsAppState : State<WidgetsApp>
{
public override void initState() {
base.initState();
D.assert(() =>
{
WidgetInspectorService.instance.inspectorShowCallback += inspectorShowChanged;
return true;
});
}
public override void dispose() {
D.assert(() =>
{
WidgetInspectorService.instance.inspectorShowCallback -= inspectorShowChanged;
return true;
});
base.dispose();
}
private void inspectorShowChanged()
{
setState(() => {});
}
public override Widget build(BuildContext context)
{
Widget result = widget.child;
D.assert(() =>
{
if (WidgetInspectorService.instance.debugShowInspector)
{
result = new WidgetInspector(null, result, _InspectorSelectButtonBuilder);
}
return true;
});
return result;
}
private Widget _InspectorSelectButtonBuilder(BuildContext context, VoidCallback onPressed)
{
return new _InspectorSelectButton(onPressed: onPressed);
}
}
class _InspectorSelectButton : StatelessWidget {
public _InspectorSelectButton(
VoidCallback onPressed,
Key key = null
) : base(key: key)
{
this.onPressed = () => onPressed();
}
public readonly GestureTapCallback onPressed;
public override Widget build(BuildContext context) {
return new GestureDetector(
onTap: this.onPressed,
child: new Container(
color: Color.fromARGB(255, 0, 0, 255),
padding: EdgeInsets.all(10),
child: new Text("Select", style: new painting.TextStyle(color: Color.fromARGB(255, 255, 255, 255)))
)
);
}
}
}

3
Assets/UIWidgets/widgets/app.cs.meta


fileFormatVersion: 2
guid: a65e962810af4caba850ebe722776ee9
timeCreated: 1540267826

1001
Assets/UIWidgets/widgets/widget_inspector.cs
文件差异内容过多而无法显示
查看文件

3
Assets/UIWidgets/widgets/widget_inspector.cs.meta


fileFormatVersion: 2
guid: bbffff803c4d4fd5b368c62f161e9e59
timeCreated: 1539239769

410
Assets/UIWidgets/debugger/diagnostics.cs


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UIWidgets.foundation;
using UIWidgets.ui;
namespace UIWidgets.debugger
{
public class DiagnosticsNode : IEquatable<DiagnosticsNode>
{
private readonly Dictionary<string, object> _json; // todo use json class such as simple json
public readonly bool isProperty;
private DiagnosticsNode _parent;
public DiagnosticsNode(Dictionary<string, object> json, bool isProperty)
{
this._json = json;
this.isProperty = isProperty;
}
public bool Equals(DiagnosticsNode other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return Equals(diagnosticRef, other.diagnosticRef);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((DiagnosticsNode) obj);
}
public static bool operator ==(DiagnosticsNode left, DiagnosticsNode right)
{
return Equals(left, right);
}
public static bool operator !=(DiagnosticsNode left, DiagnosticsNode right)
{
return !Equals(left, right);
}
public DiagnosticsNode parent
{
get { return _parent; }
set { _parent = value; }
}
public string getStringMember(string memberName)
{
object ret;
_json.TryGetValue(memberName, out ret);
return ret == null ? null : ret.ToString();
}
public string separator
{
get { return showSeparator ? ":" : ""; }
}
public string name
{
get { return getStringMember("name"); }
}
public bool showSeparator
{
get { return getBoolMember("showSeparator", true); }
}
public string description
{
get { return getStringMember("description"); }
}
public DiagnosticLevel level
{
get { return getLevelMember("level", DiagnosticLevel.info); }
}
public bool showName
{
get { return getBoolMember("showName", true); }
}
public string emptyBodyDescription
{
get { return getStringMember("emptyBodyDescription"); }
}
public DiagnosticsTreeStyle style
{
get { return getStyleMember("style", DiagnosticsTreeStyle.sparse); }
}
public string type
{
get { return getStringMember("type"); }
}
public bool isQuoted
{
get { return getBoolMember("quoted", false); }
}
public bool hasIsQuoted
{
get { return _json.ContainsKey("quoted"); }
}
public string unit
{
get { return getStringMember("unit"); }
}
public bool hasUnit
{
get { return _json.ContainsKey("unit"); }
}
public string numberToString
{
get { return getStringMember("numberToString"); }
}
public bool hasNumberToString
{
get { return _json.ContainsKey("numberToString"); }
}
public string ifTrue
{
get { return getStringMember("ifTrue"); }
}
public bool hasIfTrue
{
get { return _json.ContainsKey("ifTrue"); }
}
public string ifFalse
{
get { return getStringMember("ifFalse"); }
}
public bool hasIfFalse
{
get { return _json.ContainsKey("ifFalse"); }
}
public List<string> values
{
get
{
object value;
_json.TryGetValue("values", out value);
if (value == null)
{
return null;
}
return ((IEnumerable) value).Cast<object>().Select(o => o.ToString()).ToList();
}
}
public bool hasValues
{
get { return _json.ContainsKey("values"); }
}
public string ifPresent
{
get { return getStringMember("ifPresent"); }
}
public bool hasIfPresent
{
get { return _json.ContainsKey("ifPresent"); }
}
public string defaultValue
{
get { return getStringMember("defaultValue"); }
}
public bool hasDefaultValue
{
get { return _json.ContainsKey("defaultValue"); }
}
public string ifEmpty
{
get { return getStringMember("ifEmpty"); }
}
public string ifNull
{
get { return getStringMember("ifNull"); }
}
public string tooltip
{
get { return getStringMember("tooltip"); }
}
public bool hasTooltip
{
get { return _json.ContainsKey("tooltip"); }
}
public bool missingIfNull
{
get { return getBoolMember("missingIfNull", false); }
}
public string exception
{
get { return getStringMember("exception"); }
}
public bool hasException
{
get { return _json.ContainsKey("exception"); }
}
public string propertyType
{
get { return getStringMember("propertyType"); }
}
public DiagnosticLevel defaultLevel
{
get { return getLevelMember("defaultLevel", DiagnosticLevel.info); }
}
public bool isDiagnosticableValue
{
get { return getBoolMember("isDiagnosticableValue", false); }
}
public InspectorInstanceRef valueRef
{
get
{
var id = getStringMember("valueId");
return new InspectorInstanceRef(id);
}
}
public List<DiagnosticsNode> children
{
get
{
object value;
_json.TryGetValue("children", out value);
if (value == null)
{
return new List<DiagnosticsNode>();
}
return ((IEnumerable) value).Cast<Dictionary<string, object>>()
.Select(n => new DiagnosticsNode(n, false))
.ToList();
}
}
public Dictionary<string, object> valuePropertiesJson
{
get
{
object value;
_json.TryGetValue("valueProperties", out value);
return (Dictionary<string, object>) value;
}
}
public bool isColorProperty
{
get { return isProperty && (propertyType == typeof(Color).ToString()); }
}
//
// public bool isEnumProperty
// {
// get
// {
// var type = this.type;
//
// }
// }
//
private bool getBoolMember(string memberName, bool defaultValue = false)
{
object value;
if (!_json.TryGetValue(memberName, out value))
{
return defaultValue;
}
if (value == null)
{
return defaultValue;
}
return Convert.ToBoolean(value);
}
private DiagnosticLevel getLevelMember(string memberName, DiagnosticLevel defaultValue)
{
return getEnumMember(memberName, defaultValue);
}
private DiagnosticsTreeStyle getStyleMember(string memberName, DiagnosticsTreeStyle defaultValue)
{
return getEnumMember(memberName, defaultValue);
}
private T getEnumMember<T>(string memberName, T defaultValue)
{
object value;
if (!_json.TryGetValue(memberName, out value))
{
return defaultValue;
}
if (value == null)
{
return defaultValue;
}
return (T) Enum.Parse(typeof(T), value.ToString());
}
public InspectorInstanceRef diagnosticRef
{
get { return new InspectorInstanceRef(_json["objectId"].ToString()); }
}
public List<DiagnosticsNode> inlineProperties
{
get
{
var properties = new List<DiagnosticsNode>();
object value;
_json.TryGetValue("properties", out value);
if (value != null)
{
foreach (var v in (IEnumerable<Dictionary<string, object>>) value)
{
properties.Add(new DiagnosticsNode(v, true));
}
}
return properties;
}
}
}
public class InspectorInstanceRef : IEquatable<InspectorInstanceRef>
{
public readonly string id;
public InspectorInstanceRef(string id)
{
this.id = id;
}
public bool Equals(InspectorInstanceRef other)
{
if (ReferenceEquals(null, other)) return false;
if (ReferenceEquals(this, other)) return true;
return string.Equals(id, other.id);
}
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj)) return false;
if (ReferenceEquals(this, obj)) return true;
if (obj.GetType() != this.GetType()) return false;
return Equals((InspectorInstanceRef) obj);
}
public override int GetHashCode()
{
return (id != null ? id.GetHashCode() : 0);
}
public static bool operator ==(InspectorInstanceRef left, InspectorInstanceRef right)
{
return Equals(left, right);
}
public static bool operator !=(InspectorInstanceRef left, InspectorInstanceRef right)
{
return !Equals(left, right);
}
public override string ToString()
{
return string.Format("Id: {0}", id);
}
}
}

309
Assets/UIWidgets/debugger/inpsector_panel.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UIWidgets.foundation;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace UIWidgets.debugger
{
public class InspectorPanel
{
public readonly WidgetTreeType treeType;
private const float splitterHeight = 8;
private readonly InspectorTreeView m_TreeView;
private readonly InspectorTreeView m_DetailTreeView;
private readonly InspectorService m_InspectorService;
private readonly EditorWindow m_Window;
private readonly string m_GroupName;
private Vector2 m_PropertyScrollPos = new Vector2(0, 0);
private bool m_NeedSelectionUpdate = true;
private bool m_NeedDetailUpdate = true;
private List<DiagnosticsNode> m_Properties;
private InspectorInstanceRef m_SelectedNodeRef;
private bool m_VisibleToUser;
private DateTime m_LastPropertyRefresh = DateTime.MinValue;
private float m_SplitOffset = -1;
public InspectorPanel(EditorWindow window, WidgetTreeType treeType, InspectorService inspectorService,
float? splitOffset = null)
{
this.m_Window = window;
this.treeType = treeType;
this.m_InspectorService = inspectorService;
this.m_InspectorService.selectionChanged += handleSelectionChanged;
m_TreeView = new InspectorTreeView(new TreeViewState());
m_TreeView.onNodeSelectionChanged += OnNodeSelectionChanged;
m_TreeView.Reload();
if (treeType == WidgetTreeType.Widget)
{
m_DetailTreeView = new InspectorTreeView(new TreeViewState());
m_DetailTreeView.Reload();
}
m_GroupName = InspectorObjectGroupManager.Instance.nextGroupName("inspector");
m_SplitOffset = splitOffset ?? window.position.height / 2;
}
public string title
{
get { return treeType == WidgetTreeType.Widget ? "Widgets" : "Render Tree"; }
}
public bool visibleToUser
{
get { return m_VisibleToUser; }
set
{
if (m_VisibleToUser == value)
{
return;
}
m_VisibleToUser = value;
if (value)
{
m_NeedSelectionUpdate = true;
m_NeedDetailUpdate = true;
}
}
}
public PanelState PanelState
{
get { return new PanelState(){splitOffset = m_SplitOffset, treeType = treeType}; }
}
public void Close()
{
this.m_InspectorService.selectionChanged -= handleSelectionChanged;
if (m_InspectorService != null)
{
m_InspectorService.disposeGroup(m_GroupName);
}
// todo
}
public void OnGUI()
{
if (Event.current.type != EventType.Layout)
{
var lastRect = GUILayoutUtility.GetLastRect();
var x = lastRect.height;
}
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
// splitter
m_SplitOffset = Math.Max(0, m_SplitOffset);
var rect = EditorGUILayout.GetControlRect(GUILayout.ExpandWidth(true), GUILayout.Height(m_SplitOffset));
m_TreeView.OnGUI(rect);
GUILayout.Box("",
GUILayout.ExpandWidth(true),
GUILayout.Height(splitterHeight));
var splitterRect = GUILayoutUtility.GetLastRect();
this.splitGUI(splitterRect);
if (m_DetailTreeView != null)
{
var rect2 = EditorGUILayout.GetControlRect(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
m_DetailTreeView.OnGUI(rect2);
}
if (m_Properties != null)
{
EditorGUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
m_PropertyScrollPos = EditorGUILayout.BeginScrollView(m_PropertyScrollPos);
foreach (var property in m_Properties)
{
if (property.isColorProperty)
{
var properties = property.valuePropertiesJson;
int alpha = Util.GetIntProperty(properties, "alpha");
int red = Util.GetIntProperty(properties, "red");
int green = Util.GetIntProperty(properties, "green");
int blue = Util.GetIntProperty(properties, "blue");
var color = new UnityEngine.Color(red / 255.0f, green / 255.0f, blue / 255.0f, alpha / 255.0f);
EditorGUILayout.ColorField(property.name, color, GUILayout.ExpandWidth(true));
}
else
{
EditorGUILayout.TextField(property.name, property.description);
}
}
EditorGUILayout.EndScrollView();
EditorGUILayout.EndVertical();
}
EditorGUILayout.EndVertical();
if (Event.current.type == EventType.Repaint)
{
if (splitterRect.yMax > m_Window.position.height)
{
m_SplitOffset -= splitterRect.yMax - m_Window.position.height;
m_Window.Repaint();
}
}
}
public void LoadTree()
{
var node = treeType == WidgetTreeType.Widget
? m_InspectorService.getRootWidgetSummaryTree(m_GroupName)
: m_InspectorService.getRootRenderObject(m_GroupName);
m_TreeView.node = node;
}
public void Update()
{
if (!m_VisibleToUser)
{
return;
}
if (m_TreeView.node == null)
{
LoadTree();
}
updateSelection();
updateDetailTree();
if (treeType == WidgetTreeType.Render &&
DateTime.Now - m_LastPropertyRefresh > TimeSpan.FromMilliseconds(200))
{
m_LastPropertyRefresh = DateTime.Now;
m_Properties = m_SelectedNodeRef == null
? new List<DiagnosticsNode>()
: m_InspectorService.getProperties(m_SelectedNodeRef, m_GroupName);
m_Properties = m_Properties.Where((p) => p.level != DiagnosticLevel.hidden).ToList();
m_Window.Repaint();
}
}
private void OnNodeSelectionChanged(DiagnosticsNode node)
{
m_SelectedNodeRef = node == null ? null : node.diagnosticRef;
m_InspectorService.setSelection(node == null ? null : node.valueRef, m_GroupName);
m_NeedDetailUpdate = m_DetailTreeView != null;
}
private void handleSelectionChanged()
{
m_NeedSelectionUpdate = true;
m_NeedDetailUpdate = true;
}
private void updateSelection()
{
if (!m_NeedSelectionUpdate)
{
return;
}
m_NeedSelectionUpdate = false;
var diagnosticsNode = m_InspectorService.getSelection(m_TreeView.selectedNode, treeType, true, m_GroupName);
m_SelectedNodeRef = diagnosticsNode == null ? null : diagnosticsNode.diagnosticRef;
if (diagnosticsNode != null)
{
var item = m_TreeView.getTreeItemByValueRef(diagnosticsNode.valueRef);
if (item == null)
{
LoadTree();
item = m_TreeView.getTreeItemByValueRef(diagnosticsNode.valueRef);
}
m_TreeView.CollapseAll();
if (item != null)
{
m_TreeView.SetSelection(new List<int> {item.id}, TreeViewSelectionOptions.RevealAndFrame);
}
else
{
m_TreeView.SetSelection(new List<int>());
}
m_TreeView.Repaint();
}
}
private void updateDetailTree()
{
D.assert(!m_NeedSelectionUpdate);
if (!m_NeedDetailUpdate)
{
return;
}
if (m_DetailTreeView == null)
{
return;
}
m_NeedDetailUpdate = false;
if (m_SelectedNodeRef == null)
{
m_DetailTreeView.node = null;
}
else
{
m_DetailTreeView.node = m_InspectorService.getDetailsSubtree(m_SelectedNodeRef, m_GroupName);
}
m_DetailTreeView.ExpandAll();
}
private void splitGUI(Rect splitterRect)
{
var id = GUIUtility.GetControlID("inpectorPannelSplitter".GetHashCode(), FocusType.Passive);
switch (Event.current.GetTypeForControl(id))
{
case EventType.MouseDown:
if (splitterRect.Contains(Event.current.mousePosition))
{
GUIUtility.hotControl = id;
Event.current.Use();
}
break;
case EventType.MouseDrag:
if (GUIUtility.hotControl == id)
{
m_SplitOffset += Event.current.delta.y;
m_Window.Repaint();
Event.current.Use();
}
break;
case EventType.MouseUp:
if (GUIUtility.hotControl == id)
{
GUIUtility.hotControl = 0;
Event.current.Use();
}
break;
case EventType.Repaint:
EditorGUIUtility.AddCursorRect(splitterRect, MouseCursor.ResizeVertical, id);
break;
}
}
}
[Serializable]
public class PanelState
{
public WidgetTreeType treeType;
public float splitOffset;
}
}

3
Assets/UIWidgets/debugger/inpsector_panel.cs.meta


fileFormatVersion: 2
guid: 077d49fa7e054bfbafc94954e83c1b2e
timeCreated: 1540292151

66
Assets/UIWidgets/debugger/inspector_objectgroup.cs


using System.Diagnostics;
using UnityEngine;
namespace UIWidgets.debugger
{
public class InspectorObjectGroupManager : Singleton<InspectorObjectGroupManager>
{
[SerializeField]
private int m_NextId = 0;
public string nextGroupName(string name)
{
return string.Format("pid{0}_{1}_{2}", Process.GetCurrentProcess().Id, name, m_NextId++);
}
}
public class Singleton<T>: ScriptableObject where T : ScriptableObject
{
private static T m_Instance;
private static bool m_CreateNonSingletonInstance;
private bool m_IsNonSingletonInstance;
public static T Instance
{
get
{
if (m_Instance == null)
m_Instance = ScriptableObject.CreateInstance<T>();
return m_Instance;
}
}
private void OnEnable()
{
if (Singleton<T>.m_CreateNonSingletonInstance)
{
this.m_IsNonSingletonInstance = true;
this.Initialize();
}
else if (this.m_IsNonSingletonInstance)
Object.DestroyImmediate((Object) this);
else if (m_Instance == null)
{
m_Instance = this as T;
this.Initialize();
}
else
{
Object.DestroyImmediate((Object) this);
}
}
protected virtual void Initialize()
{
}
public static T Create()
{
Singleton<T>.m_CreateNonSingletonInstance = true;
var instance = ScriptableObject.CreateInstance<T>();
Singleton<T>.m_CreateNonSingletonInstance = false;
return (T) instance;
}
}
}

3
Assets/UIWidgets/debugger/inspector_objectgroup.cs.meta


fileFormatVersion: 2
guid: b28531fd9ecf4d298f2e95968f81e838
timeCreated: 1540886500

146
Assets/UIWidgets/debugger/inspector_service.cs


using System.Collections.Generic;
using System.Linq;
using UIWidgets.editor;
using UIWidgets.widgets;
namespace UIWidgets.debugger
{
public delegate void SelectionChanged();
public class InspectorService
{
public readonly WindowAdapter window;
public SelectionChanged selectionChanged;
private readonly WidgetInspectorService _widgetInspectorService;
public InspectorService(WindowAdapter window)
{
this.window = window;
_widgetInspectorService = window.widgetInspectorService;
_widgetInspectorService.developerInspect += this.developerInspect; // todo dispose
}
public bool active
{
get { return window.alive; }
}
public void close()
{
setShowInspect(false);
_widgetInspectorService.developerInspect -= this.developerInspect;
}
public DiagnosticsNode getRootWidgetSummaryTree(string groupName)
{
return toNode(window.WithBindingFunc(() =>_widgetInspectorService.getRootWidgetSummaryTree(groupName)));
}
public DiagnosticsNode getRootWidget(string groupName)
{
return toNode(window.WithBindingFunc(() => _widgetInspectorService.getRootWidget(groupName)));
}
public DiagnosticsNode getRootRenderObject(string groupName)
{
return toNode(window.WithBindingFunc(() =>_widgetInspectorService.getRootRenderObject(groupName)));
}
public DiagnosticsNode getDetailsSubtree(InspectorInstanceRef instanceRef, string groupName)
{
return toNode(window.WithBindingFunc(()=> _widgetInspectorService.getDetailsSubtree(instanceRef.id, groupName)));
}
public DiagnosticsNode getSelection(DiagnosticsNode previousSelection, WidgetTreeType treeType, bool localOnly, string groupName)
{
InspectorInstanceRef previousSelectionRef =
previousSelection == null ? null : previousSelection.diagnosticRef;
string previousSelectionId = previousSelectionRef == null ? null : previousSelectionRef.id;
DiagnosticsNode result = null;
window.WithBinding(() =>
{
switch (treeType)
{
case WidgetTreeType.Widget:
result = localOnly
? toNode(_widgetInspectorService.getSelectedSummaryWidget(previousSelectionId, groupName))
: toNode(_widgetInspectorService.getSelectedWidget(previousSelectionId, groupName));
break;
case WidgetTreeType.Render:
result = toNode(
_widgetInspectorService.getSelectedRenderObject(previousSelectionId, groupName));
break;
}
});
if (result != null && result.diagnosticRef == previousSelectionRef)
{
return previousSelection;
}
else
{
return result;
}
}
public bool setSelection(InspectorInstanceRef inspectorInstanceRef, string groupName)
{
return window.WithBindingFunc(() => _widgetInspectorService.setSelectionById(inspectorInstanceRef.id, groupName));
}
public void setShowInspect(bool show)
{
window.WithBinding(() =>
{
_widgetInspectorService.debugShowInspector = show;
});
}
public bool getShowInspect()
{
return window.WithBindingFunc(() => _widgetInspectorService.debugShowInspector);
}
public List<DiagnosticsNode> getProperties(InspectorInstanceRef inspectorInstanceRef, string groupName)
{
var list = window.WithBindingFunc(() =>
_widgetInspectorService.getProperties(inspectorInstanceRef.id, groupName));
return list.Select(json => toNode(json, isProperty: true)).ToList();
}
public void disposeGroup(string groupName)
{
window.WithBinding(() => _widgetInspectorService.disposeGroup(groupName));
}
private DiagnosticsNode toNode(Dictionary<string, object> json, bool isProperty = false)
{
if (json == null)
{
return null;
}
return new DiagnosticsNode(json, isProperty);
}
private void developerInspect()
{
if (selectionChanged != null)
{
selectionChanged();
}
}
}
public enum WidgetTreeType
{
Widget,
Render
}
}

258
Assets/UIWidgets/debugger/inspector_treeview.cs


using System;
using System.Collections.Generic;
using System.Reflection;
using UIWidgets.foundation;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEngine;
namespace UIWidgets.debugger
{
public class InspectorTreeView : TreeView
{
private static int m_NextId = 0;
private DiagnosticsNode m_Node;
private readonly Dictionary<InspectorInstanceRef, InspectorTreeItem> m_ValueToNode =
new Dictionary<InspectorInstanceRef, InspectorTreeItem>();
public delegate void NodeSelectionChanged(DiagnosticsNode node);
public NodeSelectionChanged onNodeSelectionChanged;
public InspectorTreeView(TreeViewState state) : base(state)
{
// todo better way to enable horizontal scroll in treeview
setFieldValueRelection(this, new List<string> {"m_GUI", "m_UseHorizontalScroll"}, true);
useScrollView = true;
showBorder = true;
}
public DiagnosticsNode node
{
set
{
m_Node = value;
Reload();
}
get { return m_Node; }
}
public DiagnosticsNode selectedNode
{
get
{
var selection = GetSelection();
if (selection.Count <= 0)
{
return null;
}
var item = FindItem(selection[0], rootItem) as InspectorTreeItem;
return item == null ? null : item.node;
}
}
public InspectorTreeItem getTreeItemByValueRef(InspectorInstanceRef instanceRef, TreeViewItem from = null)
{
InspectorTreeItem item;
m_ValueToNode.TryGetValue(instanceRef, out item);
return item;
}
protected override void RowGUI(TreeView.RowGUIArgs args)
{
var item = args.item as InspectorTreeItem;
if (item == null || item.node == null || !item.node.isProperty)
{
base.RowGUI(args);
return;
}
var node = item.node;
var rect = args.rowRect;
rect.xMin += GetContentIndent(item);
var xoffset = rect.xMin;
if (node.showName && !string.IsNullOrEmpty(node.name))
{
xoffset = labelGUI(xoffset, rect, string.Format("{0}{1} ", node.name, node.separator));
}
var properties = node.valuePropertiesJson;
var iconSize = rect.height;
if (node.isColorProperty)
{
if (Event.current.type == EventType.Repaint)
{
int alpha = Util.GetIntProperty(properties, "alpha");
int red = Util.GetIntProperty(properties, "red");
int green = Util.GetIntProperty(properties, "green");
int blue = Util.GetIntProperty(properties, "blue");
var color = new UnityEngine.Color(red / 255.0f, green / 255.0f, blue / 255.0f, alpha / 255.0f);
Util.DrawColorIcon(new Rect(xoffset, rect.yMin, rect.height, rect.height), color);
}
xoffset += iconSize;
}
labelGUI(xoffset, rect, node.description);
}
protected override void SelectionChanged(IList<int> selectedIds)
{
DiagnosticsNode node = null;
if (selectedIds.Count > 0)
{
var id = selectedIds[0];
var item = FindItem(id, rootItem) as InspectorTreeItem;
if (item != null)
{
node = item.node;
}
}
if (onNodeSelectionChanged != null)
{
onNodeSelectionChanged(node);
}
}
protected override TreeViewItem BuildRoot()
{
m_NextId = 0;
m_ValueToNode.Clear();
var root = new TreeViewItem(m_NextId++, -1);
root.children = new List<TreeViewItem>();
if (m_Node != null)
{
root.AddChild(build(m_Node, false));
}
SetupDepthsFromParentsAndChildren(root);
return root;
}
private float labelGUI(float offset, Rect rowRect, string text)
{
float minWidth, maxWidth;
GUI.skin.label.CalcMinMaxWidth(new GUIContent(text), out minWidth, out maxWidth);
rowRect.xMin = offset;
rowRect.width = maxWidth;
GUI.Label(rowRect, text);
return rowRect.xMax;
}
private InspectorTreeItem build(DiagnosticsNode node, bool inProperty)
{
D.assert(node != null);
var item = new InspectorTreeItem(node, m_NextId++);
inProperty = inProperty || node.isProperty;
if (!inProperty && node.valueRef != null)
{
m_ValueToNode[node.valueRef] = item;
}
foreach (var propertyNode in node.inlineProperties)
{
item.AddChild(build(propertyNode, inProperty));
}
var children = node.children;
foreach (var childNode in children)
{
item.AddChild(build(childNode, inProperty));
}
return item;
}
private void setFieldValueRelection(object obj, List<string> fields, object value)
{
for (var i = 0; i < fields.Count; ++i)
{
if (obj == null)
{
return;
}
FieldInfo fieldInfo = null;
for (var type = obj.GetType(); type != null && fieldInfo == null; type = type.BaseType)
{
fieldInfo = type.GetField(fields[i],
BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
}
if (fieldInfo == null)
{
return;
}
if (i + 1 < fields.Count)
{
obj = fieldInfo.GetValue(obj);
}
else
{
fieldInfo.SetValue(obj, value);
}
}
}
}
public class InspectorTreeItem : TreeViewItem
{
public readonly DiagnosticsNode node;
public InspectorTreeItem(DiagnosticsNode node, int id) : base(id)
{
this.node = node;
}
public override string displayName
{
get { return node.name + node.description; }
}
}
public static class Util
{
private const float colorIconMargin = 1.0f;
public static int GetIntProperty(Dictionary<string, object> properties, string name)
{
object val;
properties.TryGetValue(name, out val);
if (val == null)
{
return -1;
}
return Convert.ToInt32(val);
}
public static void DrawColorIcon(Rect rect, Color color)
{
var innerRect = new Rect(rect.x + colorIconMargin, rect.y + colorIconMargin,
rect.width - 2 * colorIconMargin,
rect.height - 2 * colorIconMargin);
GUI.DrawTexture(innerRect, EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, true, 0,
Color.white, 0, 0);
GUI.DrawTexture(new Rect(innerRect.x, innerRect.y, innerRect.width / 2,
innerRect.height / 2), EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, true, 0,
Color.gray, 0, 0);
GUI.DrawTexture(new Rect(innerRect.x + innerRect.width / 2, innerRect.y + innerRect.height / 2,
innerRect.width / 2,
innerRect.height / 2), EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, true, 0,
Color.gray, 0, 0);
GUI.DrawTexture(innerRect,
EditorGUIUtility.whiteTexture, ScaleMode.StretchToFill, true, 0,
color, 0, 0);
}
}
}

3
Assets/UIWidgets/debugger/inspector_treeview.cs.meta


fileFormatVersion: 2
guid: f5253bdeb6f94869a44eff557fbf61c5
timeCreated: 1539849580

182
Assets/UIWidgets/debugger/inspector_window.cs


using System.Collections.Generic;
using System.Linq;
using RSG.Promises;
using UIWidgets.editor;
using UIWidgets.widgets;
using UnityEditor;
using UnityEngine;
namespace UIWidgets.debugger
{
public class WidgetsInpsectorWindow: EditorWindow
{
private InspectorService m_InspectorService;
private bool m_ShowInspect;
private readonly List<InspectorPanel> m_Panels = new List<InspectorPanel>();
private int m_PanelIndex = 0;
[SerializeField]
private List<PanelState> m_PanelStates = new List<PanelState>();
[MenuItem("Window/Analysis/UIWidgets Inspector")]
public static void Init()
{
WidgetsInpsectorWindow window = (WidgetsInpsectorWindow)EditorWindow.GetWindow(typeof(WidgetsInpsectorWindow));
window.Show();
}
private void OnGUI()
{
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));
DoSelectDropDown();
if (m_InspectorService != null)
{
EditorGUI.BeginChangeCheck();
var newShowInspect = GUILayout.Toggle(this.m_ShowInspect, new GUIContent("Inspect Element"), EditorStyles.toolbarButton);
if (EditorGUI.EndChangeCheck())
{
m_InspectorService.setShowInspect(newShowInspect);
}
}
EditorGUILayout.EndHorizontal();
EditorGUILayout.Space();
if (m_InspectorService != null)
{
EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(false));
m_Panels.Each((pannel, index) =>
{
if (GUILayout.Toggle(m_PanelIndex == index, pannel.title, EditorStyles.toolbarButton,
GUILayout.ExpandWidth(false), GUILayout.Width(100)))
{
m_PanelIndex = index;
}
});
EditorGUILayout.EndHorizontal();
m_Panels[m_PanelIndex].OnGUI();
}
}
private void DoSelectDropDown()
{
var currentWindow = m_InspectorService == null ? null : m_InspectorService.window;
var selectTitle = currentWindow != null ? currentWindow.editorWindow.titleContent : new GUIContent("<Please Select>");
if (GUILayout.Button(selectTitle, EditorStyles.toolbarDropDown))
{
var windows = new List<WindowAdapter>(WindowAdapter.windowAdapters.Where(w =>
{
return w.WithBindingFunc(() => WidgetsBinding.instance.renderViewElement != null);
}));
Rect rect = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight, EditorStyles.toolbarDropDown);
var menuPos = EditorGUI.IndentedRect(rect);
menuPos.y += EditorGUIUtility.singleLineHeight / 2;
int selectedIndex = 0;
var labels = new GUIContent[windows.Count + 1];
labels[0] = new GUIContent("none");
for (int i = 0; i < windows.Count; i++)
{
labels[i + 1] = windows[i].editorWindow.titleContent;
if (windows[i] == currentWindow)
{
selectedIndex = i + 1;
}
}
EditorUtility.DisplayCustomMenu(menuPos, labels, selectedIndex, (data, options, selected) =>
{
if (selected > 0)
{
var selectedWindow = windows[selected - 1];
if (selectedWindow != currentWindow)
{
inspect(selectedWindow);
}
}
else
{
if (m_InspectorService != null)
{
closeInspect();
}
}
}, null);
}
}
private void inspect(WindowAdapter window)
{
if (m_InspectorService != null) // stop previous inspect
{
closeInspect();
}
m_InspectorService = new InspectorService(window);
m_PanelIndex = 0;
var state = m_PanelStates.Find((s) => s.treeType == WidgetTreeType.Widget);
m_Panels.Add(new InspectorPanel(this, WidgetTreeType.Widget, m_InspectorService,
state == null ? (float?)null : state.splitOffset));
state = m_PanelStates.Find((s) => s.treeType == WidgetTreeType.Render);
m_Panels.Add(new InspectorPanel(this, WidgetTreeType.Render, m_InspectorService,
state == null ? (float?)null : state.splitOffset));
}
private void closeInspect()
{
if (m_InspectorService == null)
{
return;
}
m_InspectorService.close();
m_InspectorService = null;
foreach (var panel in m_Panels)
{
panel.Close();
}
m_Panels.Clear();
m_ShowInspect = false;
}
private void Update()
{
if (m_InspectorService != null && !m_InspectorService.active)
{
closeInspect();
Repaint();
}
bool showInspect = false;
if (m_InspectorService != null)
{
showInspect = m_InspectorService.getShowInspect();
}
if (showInspect != this.m_ShowInspect)
{
Repaint();
}
m_ShowInspect = showInspect;
for (int i = 0; i < m_Panels.Count; i++)
{
m_Panels[i].visibleToUser = m_PanelIndex == i;
m_Panels[i].Update();
}
if (m_Panels.Count > 0)
{
m_PanelStates = m_Panels.Select(p => p.PanelState).ToList();
}
}
void OnDestroy()
{
closeInspect();
}
}
}

3
Assets/UIWidgets/debugger/inspector_window.cs.meta


fileFormatVersion: 2
guid: 020aab88534245ff8ee7588460f7956f
timeCreated: 1539240190
正在加载...
取消
保存