浏览代码

Merge pull request #1 from fzhangtj/debugger

inspector & mouse hover
/main
GitHub 6 年前
当前提交
3d9f8fc3
共有 47 个文件被更改,包括 3340 次插入110 次删除
  1. 1
      Assets/UIWidgets/Tests/EditableTextWiget.cs
  2. 1
      Assets/UIWidgets/Tests/Gestures.cs
  3. 1
      Assets/UIWidgets/Tests/Paragraph.cs
  4. 1
      Assets/UIWidgets/Tests/RenderBoxes.cs
  5. 1
      Assets/UIWidgets/Tests/RenderEditable.cs
  6. 17
      Assets/UIWidgets/Tests/Widgets.cs
  7. 66
      Assets/UIWidgets/async/timer.cs
  8. 88
      Assets/UIWidgets/editor/editor_window.cs
  9. 14
      Assets/UIWidgets/foundation/diagnostics.cs
  10. 49
      Assets/UIWidgets/gestures/binding.cs
  11. 11
      Assets/UIWidgets/gestures/converter.cs
  12. 54
      Assets/UIWidgets/gestures/events.cs
  13. 2
      Assets/UIWidgets/painting/box_decoration.cs
  14. 27
      Assets/UIWidgets/painting/text_span.cs
  15. 7
      Assets/UIWidgets/rendering/box.cs
  16. 172
      Assets/UIWidgets/rendering/editable.cs
  17. 2
      Assets/UIWidgets/rendering/object.cs
  18. 30
      Assets/UIWidgets/rendering/paragraph.cs
  19. 50
      Assets/UIWidgets/rendering/proxy_box.cs
  20. 4
      Assets/UIWidgets/rendering/sliver.cs
  21. 5
      Assets/UIWidgets/rendering/stack.cs
  22. 9
      Assets/UIWidgets/rendering/view.cs
  23. 3
      Assets/UIWidgets/ui/painting/picture.cs
  24. 2
      Assets/UIWidgets/ui/window.cs
  25. 156
      Assets/UIWidgets/widgets/basic.cs
  26. 3
      Assets/UIWidgets/widgets/binding.cs
  27. 54
      Assets/UIWidgets/widgets/editable_text.cs
  28. 100
      Assets/UIWidgets/Tests/MouseHover.cs
  29. 3
      Assets/UIWidgets/Tests/MouseHover.cs.meta
  30. 8
      Assets/UIWidgets/debugger.meta
  31. 97
      Assets/UIWidgets/widgets/app.cs
  32. 3
      Assets/UIWidgets/widgets/app.cs.meta
  33. 1001
      Assets/UIWidgets/widgets/widget_inspector.cs
  34. 3
      Assets/UIWidgets/widgets/widget_inspector.cs.meta
  35. 410
      Assets/UIWidgets/debugger/diagnostics.cs
  36. 309
      Assets/UIWidgets/debugger/inpsector_panel.cs
  37. 3
      Assets/UIWidgets/debugger/inpsector_panel.cs.meta
  38. 66
      Assets/UIWidgets/debugger/inspector_objectgroup.cs
  39. 3
      Assets/UIWidgets/debugger/inspector_objectgroup.cs.meta
  40. 146
      Assets/UIWidgets/debugger/inspector_service.cs
  41. 258
      Assets/UIWidgets/debugger/inspector_treeview.cs
  42. 3
      Assets/UIWidgets/debugger/inspector_treeview.cs.meta
  43. 182
      Assets/UIWidgets/debugger/inspector_window.cs
  44. 3
      Assets/UIWidgets/debugger/inspector_window.cs.meta
  45. 11
      Assets/UIWidgets/debugger/diagnostics.cs.meta
  46. 11
      Assets/UIWidgets/debugger/inspector_service.cs.meta

1
Assets/UIWidgets/Tests/EditableTextWiget.cs


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

1
Assets/UIWidgets/Tests/Gestures.cs


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

1
Assets/UIWidgets/Tests/Paragraph.cs


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

1
Assets/UIWidgets/Tests/RenderBoxes.cs


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

1
Assets/UIWidgets/Tests/RenderEditable.cs


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

17
Assets/UIWidgets/Tests/Widgets.cs


[NonSerialized] private bool hasInvoked = false;
Widgets() {
public Widgets() {
this._options = new Func<Widget>[] {
this.localImage,
this.container,

this.eventsPage,
this.asPage,
this.stack
this.stack,
this.mouseHover
};
this._optionStrings = this._options.Select(x => x.Method.Name).ToArray();
this._selected = 0;

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

}
Widget asPage() {
return new AsScreen();
return new WidgetsApp(null, new AsScreen());
}
Widget mouseHover()
{
return new WidgetsApp(null, new MouseHoverWidget(null));
}
}

"All Assets",
style: new TextStyle(
fontSize: 16,
color: CLColors.white
color: Color.fromARGB(100, 255, 255, 0)
)
)
),

)
);
}
public override Widget build(BuildContext context) {
var container = new Container(
// color: CLColors.background1,

66
Assets/UIWidgets/async/timer.cs


using System;
using System.Collections.Generic;
using UnityEngine;
namespace UIWidgets.async {

}
public Timer run(TimeSpan duration, Action callback) {
var timer = new TimerImpl(DateTime.Now + duration, callback);
var timer = new TimerImpl(duration, callback);
public Timer periodic(TimeSpan duration, Action callback)
{
var timer = new TimerImpl(duration, callback, periodic: true);
this._queue.enqueue(timer);
return timer;
}
List<TimerImpl> appendList = null;
if (timer.periodic && !timer.done)
{
if (appendList == null)
{
appendList = new List<TimerImpl>();
}
appendList.Add(timer);
}
}
if (appendList != null)
{
foreach (var timer in appendList)
{
this._queue.enqueue(timer);
}
public readonly DateTime deadline;
public readonly bool periodic;
public readonly TimeSpan internval;
private DateTime _deadline;
public TimerImpl(DateTime deadline, Action callback) {
this.deadline = deadline;
public TimerImpl(TimeSpan duration, Action callback, bool periodic = false) {
this._deadline = DateTime.Now + duration;
this.periodic = periodic;
if (periodic)
{
internval = duration;
}
public DateTime deadline
{
get { return _deadline; }
}
public bool done
{
get { return _done; }
}
this._done = true;
DateTime now = DateTime.Now;
if (!periodic)
{
this._done = true;
}
try {
this._callback();

}
if (periodic)
{
this._deadline = now + internval;
}
}

88
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.wantsMouseMove = false;
this.editorWindow.wantsMouseEnterLeaveWindow = false;
this.editorWindow.wantsMouseMove = true;
this.editorWindow.wantsMouseEnterLeaveWindow = true;
this._devicePixelRatio = EditorGUIUtility.pixelsPerPoint;

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;

}
}
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;
WidgetsBinding.instance = null;
}
}
private void doOnGUI() {
var evt = Event.current;

pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.move,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,
physicalY: evt.mousePosition.y * this._devicePixelRatio
);
} else if (evt.type == EventType.MouseMove)
{
pointerData = new PointerData(
timeStamp: DateTime.Now,
change: PointerChange.hover,
kind: PointerDeviceKind.mouse,
device: evt.button,
physicalX: evt.mousePosition.x * this._devicePixelRatio,

this._microtaskQueue.flushMicrotasks();
}
public override Timer run(TimeSpan duration, Action callback) {
return this._timerProvider.run(duration, callback);
public override Timer run(TimeSpan duration, Action callback, bool periodic = false)
{
return periodic
? this._timerProvider.periodic(duration, callback)
: this._timerProvider.run(duration, callback);
}
public void attachRootRenderBox(RenderBox root) {

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;
}

49
Assets/UIWidgets/gestures/binding.cs


using System;
using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.rendering;
using UIWidgets.scheduler;
using UIWidgets.ui;
using UnityEngine;

public readonly GestureArenaManager gestureArena;
public readonly Dictionary<int, HitTestResult> _hitTests = new Dictionary<int, HitTestResult>();
public readonly HashSet<HitTestTarget> lastMoveTargets = new HashSet<HitTestTarget>();
if (evt is PointerHoverEvent || evt is PointerMoveEvent)
{
this._handlePointerHoverEvent(evt);
}
HitTestResult result;
if (evt is PointerDownEvent) {
D.assert(!this._hitTests.ContainsKey(evt.pointer));

if (result != null) {
this.dispatchEvent(evt, result);
}
}
void _handlePointerHoverEvent(PointerEvent evt)
{
HitTestResult result = new HitTestResult();
this.hitTest(result, evt.position);
// enter event
foreach (var hitTestEntry in result.path)
{
if (lastMoveTargets.Contains(hitTestEntry.target))
{
hitTestEntry.target.handleEvent(evt, hitTestEntry);
lastMoveTargets.Remove(hitTestEntry.target);
}
else
{
hitTestEntry.target.handleEvent(new PointerEnterEvent(
timeStamp:evt.timeStamp,
pointer:evt.pointer,
device:evt.device,
kind:evt.kind
), hitTestEntry);
}
}
foreach (var lastMoveTarget in lastMoveTargets)
{
lastMoveTarget.handleEvent(new PointerLeaveEvent(
timeStamp:evt.timeStamp,
pointer:evt.pointer,
device:evt.device,
kind:evt.kind
), null);
}
lastMoveTargets.Clear();
foreach (var hitTestEntry in result.path)
{
lastMoveTargets.Add(hitTestEntry.target);
}
this.dispatchEvent(evt, result);
}
public virtual void hitTest(HitTestResult result, Offset position) {

11
Assets/UIWidgets/gestures/converter.cs


);
}
break;
case PointerChange.hover:
{
yield return new PointerHoverEvent(
timeStamp: timeStamp,
kind: kind,
device: datum.device,
position: position
);
break;
}
case PointerChange.up:
case PointerChange.cancel: {
D.assert(_pointers.ContainsKey(datum.device));

54
Assets/UIWidgets/gestures/events.cs


}
}
public class PointerHoverEvent : PointerEvent
{
public PointerHoverEvent(
DateTime timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
int device = 0,
Offset position = null)
: base(
timeStamp,
pointer: pointer,
kind: kind,
device: device,
position: position,
down: false) {
}
}
public class PointerEnterEvent : PointerEvent
{
public PointerEnterEvent(
DateTime timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
int device = 0,
Offset position = null)
: base(
timeStamp,
pointer: pointer,
kind: kind,
device: device,
position: position,
down: false) {
}
}
public class PointerLeaveEvent : PointerEvent
{
public PointerLeaveEvent(
DateTime timeStamp,
int pointer = 0,
PointerDeviceKind kind = PointerDeviceKind.mouse,
int device = 0,
Offset position = null)
: base(
timeStamp,
pointer: pointer,
kind: kind,
device: device,
position: position,
down: false) {
}
}
public class PointerDownEvent : PointerEvent {
public PointerDownEvent(
DateTime timeStamp,

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"));
}
}
}

50
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);

public delegate void PointerUpEventListener(PointerUpEvent evt);
public delegate void PointerCancelEventListener(PointerCancelEvent evt);
public delegate void PointerHoverEventListener(PointerHoverEvent evt);
public delegate void PointerEnterEventListener(PointerEnterEvent evt);
public delegate void PointerLeaveEventListener(PointerLeaveEvent evt);
public class RenderPointerListener : RenderProxyBoxWithHitTestBehavior {
public RenderPointerListener(

PointerCancelEventListener onPointerCancel = null,
PointerHoverEventListener onPointerHover = null,
PointerLeaveEventListener onPointerLeave = null,
PointerEnterEventListener onPointerEnter = null,
HitTestBehavior behavior = HitTestBehavior.deferToChild,
RenderBox child = null
) : base(behavior: behavior, child: child) {

this.onPointerCancel = onPointerCancel;
this.onPointerHover = onPointerHover;
this.onPointerLeave = onPointerLeave;
this.onPointerEnter = onPointerEnter;
}
public PointerDownEventListener onPointerDown;

public PointerCancelEventListener onPointerCancel;
public PointerHoverEventListener onPointerHover;
public PointerLeaveEventListener onPointerLeave;
public PointerEnterEventListener onPointerEnter;
}
}
public override void handleEvent(PointerEvent evt, HitTestEntry entry) {
D.assert(this.debugHandleEvent(evt, entry));

this.onPointerCancel((PointerCancelEvent) evt);
return;
}
if (this.onPointerHover != null && evt is PointerHoverEvent)
{
this.onPointerHover((PointerHoverEvent) evt);
return;
}
if (this.onPointerLeave != null && evt is PointerLeaveEvent)
{
this.onPointerLeave((PointerLeaveEvent) evt);
return;
}
if (this.onPointerEnter != null && evt is PointerEnterEvent)
{
this.onPointerEnter((PointerEnterEvent) evt);
return;
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {

listeners.Add("up");
if (this.onPointerCancel != null)
listeners.Add("cancel");
if (this.onPointerHover != null)
listeners.Add("hover");
if (this.onPointerEnter != null)
listeners.Add("enter");
if (this.onPointerLeave != null)
listeners.Add("leave");
if (listeners.isEmpty()) {
listeners.Add("<none>");
}

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,

2
Assets/UIWidgets/ui/window.cs


public abstract void flushMicrotasks();
public abstract Timer run(TimeSpan duration, Action callback);
public abstract Timer run(TimeSpan duration, Action callback, bool periodic = false);
public Timer run(Action callback) {
return this.run(TimeSpan.Zero, callback);

156
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));
}
}

PointerMoveEventListener onPointerMove = null,
PointerUpEventListener onPointerUp = null,
PointerCancelEventListener onPointerCancel = null,
PointerHoverEventListener onPointerHover = null,
PointerLeaveEventListener onPointerLeave = null,
PointerEnterEventListener onPointerEnter = null,
HitTestBehavior behavior = HitTestBehavior.deferToChild,
Widget child = null
) : base(key: key, child: child) {

this.onPointerCancel = onPointerCancel;
this.onPointerHover = onPointerHover;
this.onPointerLeave = onPointerLeave;
this.onPointerEnter = onPointerEnter;
this.behavior = behavior;
}

public readonly PointerUpEventListener onPointerUp;
public readonly PointerCancelEventListener onPointerCancel;
public readonly PointerHoverEventListener onPointerHover;
public readonly PointerEnterEventListener onPointerEnter;
public readonly PointerLeaveEventListener onPointerLeave;
public readonly HitTestBehavior behavior;

onPointerMove: this.onPointerMove,
onPointerUp: this.onPointerUp,
onPointerCancel: this.onPointerCancel,
onPointerEnter: this.onPointerEnter,
onPointerLeave: this.onPointerLeave,
onPointerHover: this.onPointerHover,
behavior: this.behavior
);
}

renderObject.onPointerMove = this.onPointerMove;
renderObject.onPointerUp = this.onPointerUp;
renderObject.onPointerCancel = this.onPointerCancel;
renderObject.onPointerEnter = this.onPointerEnter;
renderObject.onPointerHover = this.onPointerHover;
renderObject.onPointerLeave = this.onPointerLeave;
renderObject.behavior = this.behavior;
}

if (this.onPointerCancel != null) {
listeners.Add("cancel");
}
if (this.onPointerEnter != null) {
listeners.Add("enter");
}
if (this.onPointerHover != null) {
listeners.Add("hover");
}
if (this.onPointerLeave != null) {
listeners.Add("leave");
}
properties.add(new EnumerableProperty<string>("listeners", listeners, ifEmpty: "<none>"));
properties.add(new EnumProperty<HitTestBehavior>("behavior", this.behavior));
}

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) {

54
Assets/UIWidgets/widgets/editable_text.cs


using RSG;
using UIWidgets.animation;
using UIWidgets.foundation;
using UIWidgets.gestures;
using UnityEngine;
using Timer = UIWidgets.async.Timer;
namespace UIWidgets.widgets
{

public class EditableTextState : State<EditableText>, TextInputClient
{
const int _kObscureShowLatestCharCursorTicks = 3;
private ValueNotifier<bool> _showCursor = new ValueNotifier<bool>(true); // todo
private static TimeSpan _kCursorBlinkHalfPeriod = TimeSpan.FromMilliseconds(500);
private Timer _cursorTimer;
private ValueNotifier<bool> _showCursor = new ValueNotifier<bool>(true);
private GlobalKey _editableKey = GlobalKey.key();
private bool _didAutoFocus = false;

widget.controller.removeListener(_didChangeTextEditingValue);
_closeInputConnectionIfNeeded();
D.assert(!_hasInputConnection);
_stopCursorTimer();
D.assert(_cursorTimer == null);
widget.focusNode.removeListener(_handleFocusChanged);
base.dispose();
}

}
}
public bool cursorCurrentlyVisible
{
get { return _showCursor.value; }
}
public TimeSpan cursorBlinkInterval
{
get { return _kCursorBlinkHalfPeriod; }
}
private void _cursorTick() {
_showCursor.value = !_showCursor.value;
if (_obscureShowCharTicksPending > 0) {
setState(() => { _obscureShowCharTicksPending--;});
}
}
private void _startCursorTimer() {
_showCursor.value = true;
_cursorTimer = Window.instance.run(_kCursorBlinkHalfPeriod, _cursorTick, periodic:true);
}
private void _stopCursorTimer() {
if (_cursorTimer != null)
{
_cursorTimer.cancel();
}
_cursorTimer = null;
_showCursor.value = false;
_obscureShowCharTicksPending = 0;
}
private void _startOrStopCursorTimerIfNeeded() {
if (_cursorTimer == null && _hasFocus && _value.selection.isCollapsed)
{
_startCursorTimer();
}
else if (_cursorTimer != null && (!_hasFocus || !_value.selection.isCollapsed))
{
_stopCursorTimer();
}
}
private TextEditingValue _value
{
get { return widget.controller.value; }

private void _didChangeTextEditingValue()
{
_updateRemoteEditingValueIfNeeded();
_startOrStopCursorTimerIfNeeded();
_textChangedSinceLastCaretUpdate = true;
setState(() => { });
}

_openOrCloseInputConnectionIfNeeded();
_startOrStopCursorTimerIfNeeded();
if (!_hasFocus)
{
_value = new TextEditingValue(text: _value.text);

100
Assets/UIWidgets/Tests/MouseHover.cs


using System.Collections.Generic;
using UIWidgets.foundation;
using UIWidgets.painting;
using UIWidgets.rendering;
using UIWidgets.widgets;
using Color = UIWidgets.ui.Color;
namespace UIWidgets.Tests
{
public class MouseHoverWidget:StatefulWidget
{
public MouseHoverWidget(Key key) : base(key)
{
}
public override State createState()
{
return new _MouseHoverWidgetState();
}
}
class _MouseHoverWidgetState:State<MouseHoverWidget>
{
public static Widget createRow(bool canHover = true, bool nest = false)
{
Widget result = new Container(width: 200, height: 60, color: Color.fromARGB(255, 255, 0, 255));
if (canHover)
{
result = new HoverTrackWidget(null,
result);
}
if (nest)
{
result = new Container(child:result, padding: EdgeInsets.all(40), color: Color.fromARGB(255, 255, 0, 0));
result = new HoverTrackWidget(null,
result);
}
return result;
}
public override Widget build(BuildContext context)
{//1 131231
return new Container(
alignment: Alignment.center, color: Color.fromARGB(255, 0, 255, 0),
child: new Column(
mainAxisAlignment:MainAxisAlignment.spaceAround,
children: new List<Widget>
{
createRow(),
createRow(false),
createRow(),
createRow(true, true),
}));
}
}
public class HoverTrackWidget : StatefulWidget
{
public readonly Widget child;
public HoverTrackWidget(Key key, Widget child) : base(key)
{
this.child = child;
}
public override State createState()
{
return new _HoverTrackWidgetState();
}
}
class _HoverTrackWidgetState : State<HoverTrackWidget>
{
private bool hover;
public override Widget build(BuildContext context)
{
return new Listener(child:
new Container(
forgroundDecoration: hover ? new BoxDecoration(color: Color.fromARGB(80, 255, 255, 255)) : null,
child: widget.child
),
onPointerEnter: (evt) => {
if (mounted)
{
setState(() => { hover = true; });
} },
onPointerLeave: (evt) =>
{
if (mounted)
{
setState(() => { hover = false; });
}
}
);
}
}
}

3
Assets/UIWidgets/Tests/MouseHover.cs.meta


fileFormatVersion: 2
guid: ec7305290445466da6da50593cdaa4b7
timeCreated: 1542181137

8
Assets/UIWidgets/debugger.meta


fileFormatVersion: 2
guid: c0866eca57e1b4131977c85fa974ce37
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

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

11
Assets/UIWidgets/debugger/diagnostics.cs.meta


fileFormatVersion: 2
guid: acee278c0f2de45769aa7fbff6a8057c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

11
Assets/UIWidgets/debugger/inspector_service.cs.meta


fileFormatVersion: 2
guid: c52a0132d977144f091634e0b23f92c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存