浏览代码

Merge branch 'zxw/devTools' of github.com:Unity-Technologies/com.unity.uiwidgets into zxw/devTools

/zxw-devTools
Xingwei Zhu 3 年前
当前提交
63187185
共有 12 个文件被更改,包括 487 次插入135 次删除
  1. 4
      com.unity.uiwidgets.devtools/Editor/v2/src/framework/framework_core.cs
  2. 4
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics_node.cs
  3. 91
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs
  4. 146
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_screen_details_tab.cs
  5. 264
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs
  6. 1
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree.cs
  7. 4
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree_flutter.cs
  8. 24
      com.unity.uiwidgets.devtools/Editor/v2/src/service_manager.cs
  9. 34
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/layout_explorer/flex/flex.cs
  10. 50
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/layout_explorer/layout_explorer.cs

4
com.unity.uiwidgets.devtools/Editor/v2/src/framework/framework_core.cs


{
public static void initGlobals()
{
// setGlobal(ServiceConnectionManager, ServiceConnectionManager());
// setGlobal(MessageBus, MessageBus());
Globals.setGlobal(typeof(ServiceConnectionManager), new ServiceConnectionManager());
// Globals.setGlobal(MessageBus, MessageBus());
Globals.setGlobal(typeof(FrameworkController), new FrameworkController());
}
}

4
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics_node.cs


this.parent = parent;
}
RemoteDiagnosticsNode parent;
public RemoteDiagnosticsNode parent;
Future<string> propertyDocFuture;

List<RemoteDiagnosticsNode> _children;
static readonly CustomIconMaker iconMaker = new CustomIconMaker();
public bool isFlex => new List<string>{"Row", "Column", "Flex"}.Contains(widgetRuntimeType);
// Future<Dictionary<string, InstanceRef>> _valueProperties;
public readonly bool isProperty;

91
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs


}
}
class InspectorController
public class InspectorController
{
public InspectorController(
InspectorService inspectorService,

public readonly VoidCallback onLayoutExplorerSupported;
public InspectorTreeNode selectedNode;
bool isActive = false;
bool visibleToUser = true;

shutdownTree(false);
}
}
void _onExpand(InspectorTreeNode node) {
inspectorTree.maybePopulateChildren(node);

try
{
// var group = _treeGroups.next;
var group = new ObjectGroup("inspector",inspectorService);
// var node = detailsSubtree
// ? group.getDetailsSubtree(subtreeRoot, subtreeDepth: subtreeDepth)
// : group.getRoot(treeType);
// RemoteDiagnosticsNode node = null;
// group.getRoot(treeType).then_<RemoteDiagnosticsNode>((v) =>
// {
// node = v;
// if (node == null || group.disposed) {
// return new SynchronousFuture(null);
// }
// _treeGroups.promoteNext();
// // clearValueToInspectorTreeNodeMapping();
// if (node != null) {
// InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
// node:inspectorTree.createNode(),
// diagnosticsNode: node,
// expandChildren: true,
// expandProperties: false
// );
// inspectorTree.root = rootNode;
// } else {
// inspectorTree.root = inspectorTree.createNode();
// }
// return FutureOr.nil;
// });
RemoteDiagnosticsNode node = group._getRoot(treeType);
if (node == null || group.disposed) {
return new SynchronousFuture(null);
}
_treeGroups.promoteNext();
// clearValueToInspectorTreeNodeMapping();
if (node != null) {
InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
node:inspectorTree.createNode(),
diagnosticsNode: node,
expandChildren: true,
expandProperties: false
);
inspectorTree.root = rootNode;
} else {
inspectorTree.root = inspectorTree.createNode();
}
var group = _treeGroups.next;
RemoteDiagnosticsNode node = null;
group.getRoot(treeType).then_<RemoteDiagnosticsNode>((v) =>
{
node = v;
if (node == null || group.disposed) {
return new SynchronousFuture(null);
}
_treeGroups.promoteNext();
// clearValueToInspectorTreeNodeMapping();
if (node != null) {
InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
node:inspectorTree.createNode(),
diagnosticsNode: node,
expandChildren: true,
expandProperties: false
);
inspectorTree.root = rootNode;
} else {
inspectorTree.root = inspectorTree.createNode();
}
return FutureOr.nil;
});
// refreshSelection(newSelection, detailsSelection, setSubtreeRoot);
} catch (Exception e) {
Debug.Log(e);

inspectorService.inferPubRootDirectoryIfNeeded();
// updateSelectionFromService(firstFrame: true);
} else {
// var ready = inspectorService.isWidgetTreeReady();
bool ready = true;
flutterAppFrameReady = ready;
if (isActive && ready) {
maybeLoadUI();
}
var ready = inspectorService.isWidgetTreeReady();
ready.then_<bool>((v) =>
{
flutterAppFrameReady = v;
if (isActive && v) {
maybeLoadUI();
}
return FutureOr.value(null);
});
}
}

146
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_screen_details_tab.cs


using System.Collections.Generic;
using Unity.UIWidgets.material;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.DevTools.inspector.layout_explorer;
using Unity.UIWidgets.painting;
class InspectorDetailsTabController : StatefulWidget
class InspectorDetailsTabController : StatefulWidget
{
public InspectorDetailsTabController(
Widget detailsTree = null,
Widget actionButtons = null,
InspectorController controller = null,
bool? layoutExplorerSupported = null,
Key key = null
) : base(key: key)
public InspectorDetailsTabController(
Widget detailsTree = null,
Widget actionButtons = null,
InspectorController controller = null,
bool? layoutExplorerSupported = null,
Key key = null
) : base(key: key)
{
this.detailsTree = detailsTree;
this.actionButtons = actionButtons;
this.controller = controller;
this.layoutExplorerSupported = layoutExplorerSupported;
}
this.detailsTree = detailsTree;
this.actionButtons = actionButtons;
this.controller = controller;
this.layoutExplorerSupported = layoutExplorerSupported;
}
public readonly Widget detailsTree;
public readonly Widget actionButtons;
public readonly InspectorController controller;
public readonly bool? layoutExplorerSupported;
public readonly Widget detailsTree;
public readonly Widget actionButtons;
public readonly InspectorController controller;
public readonly bool? layoutExplorerSupported;
public override State createState()
{
return new _InspectorDetailsTabControllerState();
}
public override State createState()
{
return new _InspectorDetailsTabControllerState();
}
class _InspectorDetailsTabControllerState : State<InspectorDetailsTabController>
class _InspectorDetailsTabControllerState : State<InspectorDetailsTabController>
{
private static readonly int _detailsTreeTabIndex = 0;
TabController _tabControllerWithLayoutExplorer;
TabController _tabControllerWithoutLayoutExplorer;
public override Widget build(BuildContext context)
public override Widget build(BuildContext context)
{
return new Container(child: new Text("this is a text!"));
}
// var tabs = new List<Widget>();
// tabs.Add(_buildTab("Details Tree"));
// if (widget.layoutExplorerSupported.Value)
// {
// tabs.Add(_buildTab("Layout Explorer"));
// }
//
// var tabViews = new List<Widget>();
// tabViews.Add(widget.detailsTree);
// if (widget.layoutExplorerSupported.Value)
// {
// tabViews.Add(new LayoutExplorerTab(controller: widget.controller));
// }
//
// var _tabController = widget.layoutExplorerSupported.Value
// ? _tabControllerWithLayoutExplorer
// : _tabControllerWithoutLayoutExplorer;
//
// var theme = Theme.of(context);
// var focusColor = theme.focusColor;
// var borderSide = new BorderSide(color: focusColor);
// var hasActionButtons = widget.actionButtons != null &&
// _tabController.index == _detailsTreeTabIndex;
//
// return new Column(
// children: new List<Widget>
// {
// new SizedBox(
// height: 50.0f,
// child: new Row(
// crossAxisAlignment: CrossAxisAlignment.end,
// children: new List<Widget>
// {
// new Container(
// color: focusColor,
// child: new TabBar(
// controller: _tabController,
// labelColor: theme.textTheme.bodyText1.color,
// tabs: tabs,
// isScrollable: true
// )
// ),
// new Expanded(
// child: new Container(
// decoration: new BoxDecoration(border: new Border(bottom: borderSide)),
// child: hasActionButtons
// ? widget.actionButtons
// : new SizedBox()
// )
// ),
// }
// )
// ),
// new Expanded(
// child: new Container(
// decoration: new BoxDecoration(
// border: new Border(
// left: borderSide,
// bottom: borderSide,
// right: borderSide
// )
// ),
// child: new TabBarView(
// physics: ThemeUtils.defaultTabBarViewPhysics,
// controller: _tabController,
// children: tabViews
// )
// )
// )
// }
// );
//
// Widget _buildTab(string tabName)
// {
// return new Tab(
// child: new Text(
// tabName,
// overflow: TextOverflow.ellipsis
// )
// );
// }
return new Container(child: new Text("Not Implement yet"));
}
}

264
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs


using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.widgets;
using UnityEngine;
namespace Unity.UIWidgets.DevTools.inspector
{

{
groupName = $"{debugName}_${InspectorService.nextGroupId}";
InspectorService.nextGroupId++;
this.inspectorService = inspectorService;
}
/// Object group all objects in this arena are allocated with.

// EvalOnDartLibrary inspectorLibrary => inspectorService.inspectorLibrary;
public Future dispose() {
// var disposeComplete = invokeVoidServiceMethod("disposeGroup", groupName);

}
bool useDaemonApi => inspectorService.useDaemonApi;
// There is no excuse to call this method on a disposed group.
D.assert(!disposed);
switch (type) {
case FlutterTreeType.widget:

throw new Exception("Unexpected FlutterTreeType");
}
public RemoteDiagnosticsNode _getRoot(FlutterTreeType type) {
// There is no excuse to call this method on a disposed group.
D.assert(!disposed);
switch (type) {
case FlutterTreeType.widget:
return _getRootWidget();
case FlutterTreeType.renderObject:
return null;
Future<RemoteDiagnosticsNode> invokeServiceMethodReturningNode(string methodName) {
if (disposed) return null;
if (useDaemonApi) {
return parseDiagnosticsNodeDaemon(invokeServiceMethodDaemon(methodName));
throw new Exception("Unexpected FlutterTreeType");
// else {
// return parseDiagnosticsNodeObservatory(
// invokeServiceMethodObservatory(methodName));
// }
return null;
RemoteDiagnosticsNode _getRootWidget() {
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
Future<object> invokeServiceMethodDaemon(string methodName, string objectGroup = null) {
return invokeServiceMethodDaemonParams(methodName,
new Dictionary<string, object>(){
{"objectGroup",objectGroup ?? groupName}
}
);
}
Future<object> invokeServiceMethodDaemonParams(
string methodName,
Dictionary<string, object> _params
) {
if (methodName == "getRootWidgetSummaryTree")
{
return getRootWidgetSummaryTreeFake();
}
if (methodName == "getRootRenderObject")
{
return getRootRenderObjectFake();
}
var callMethodName = $"ext.flutter.inspector.{methodName}";
if (!Globals.serviceManager.serviceExtensionManager
.isServiceExtensionAvailable(callMethodName)) {
return null;
}
return _callServiceExtension(callMethodName, _params);
}
Future<object> _callServiceExtension(
string extension, Dictionary<string, object> args) {
if (disposed)
{
return new SynchronousFuture<object>(null);
}
return null;
// return inspectorLibrary.addRequest(this, () => {
// var r = inspectorService.vmService.callServiceExtension(
// extension,
// isolateId: inspectorService.inspectorLibrary.isolateId,
// args: args
// );
// if (disposed) return null;
// var json = r.json;
// if (json["errorMessage"] != null) {
// throw new Exception($"{extension} -- {json["errorMessage"]}");
// }
// return json["result"];
// });
}
public Future<object> getRootWidgetSummaryTreeFake()
{
Dictionary<string, object> widgetTree = new Dictionary<string, object>();
widgetTree["hasChildren"] = true;
widgetTree["name"] = "inspector";

widgetTree["widgetRuntimeType"] = "class";
widgetTree["propertyType"] = "Widget";
widgetTree["creationLocation"] = new Dictionary<string, object>()
{
{"name", "inspector2"},

{
{"name", "inspector3"},
{"type", "class"},
{"widgetRuntimeType", "class"},
{"propertyType", "RenderObject"},
{"description","second level widget"},
{
"text", new List<Dictionary<string,object>>()

{"hasChildren", true},
{"name","inspector4"},
{"propertyType", "RenderObject"},
{"description","third level widget"},
{"creationLocation", new Dictionary<string, object>()
{

{
{"name", "inspector5"},
{"type", "class"},
{"propertyType", "RenderObject"},
{"widgetRuntimeType", "class"},
{"description","second level widget"},
{"te1",new Text("text1a")},
{"te2",new Text("text2a")},

{
{"name","properties1"},
{"type", "property"},
{"propertyType", "RenderObject"},
{"description","this is a description"},
},
new Dictionary<string, object>()

{"propertyType", "RenderObject"},
return new RemoteDiagnosticsNode(widgetTree,
inspectorService: FutureOr.value(inspectorService),
true,
null);
return new SynchronousFuture<object>(widgetTree);
}
Future<object> getRootRenderObjectFake()
{
Debug.Log("At getRootRenderObjectFake : not implement yet");
return new SynchronousFuture<object>("At getRootRenderObjectFake : not implement yet");
}
Future<RemoteDiagnosticsNode> parseDiagnosticsNodeDaemon(
Future<object> json) {
if (disposed) return null;
return json.then((value) =>
{
var res = FutureOr.value(parseDiagnosticsNodeHelper((Dictionary<string,object>)value));
return res;
}).to<RemoteDiagnosticsNode>();
}
RemoteDiagnosticsNode parseDiagnosticsNodeHelper(
Dictionary<string, object> jsonElement) {
if (disposed) return null;
if (jsonElement == null) return null;
return new RemoteDiagnosticsNode(jsonElement, FutureOr.value(this), false, null);
// Future<RemoteDiagnosticsNode> parseDiagnosticsNodeObservatory(
// FutureOr<InstanceRef> instanceRefFuture) {
// return parseDiagnosticsNodeHelper(instanceRefToJson(instanceRefFuture));
// }
//
// Future<InstanceRef> invokeServiceMethodObservatory(string methodName) {
// return invokeServiceMethodObservatory1(methodName, groupName);
// }
//
// Future<InstanceRef> invokeServiceMethodObservatory1(
// string methodName, string arg1) {
// return inspectorLibrary.eval(
// "WidgetInspectorService.instance.$methodName('$arg1')",
// isAlive: this
// );
// }
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
Dictionary<string, object> widgetTree = new Dictionary<string, object>();
widgetTree["hasChildren"] = true;
widgetTree["name"] = "inspector";
widgetTree["children"] = new List<object>()
{
new Text("text1"),
new Text("text2"),
new Text("text3"),
new Text("text4"),
new Text("text5"),
};
widgetTree["properties"] = new List<object>()
{
"properties_1",
"properties_2",
"properties_3",
"properties_4",
"properties_5",
};
return Future.value(FutureOr.value(new RemoteDiagnosticsNode(widgetTree,
inspectorService: FutureOr.value(inspectorService),
true,
null))).to<RemoteDiagnosticsNode>();
return invokeServiceMethodReturningNode("getRootWidgetSummaryTree");
}
Future<RemoteDiagnosticsNode> getRootWidgetFullTree() {
return invokeServiceMethodReturningNode("getRootWidget");
Future<RemoteDiagnosticsNode> getSummaryTreeWithoutIds() {
return parseDiagnosticsNodeDaemon(
invokeServiceMethodDaemon("getRootWidgetSummaryTree"));
}
Future<RemoteDiagnosticsNode> getRootRenderObject()
{
return Future.value(FutureOr.value(null)).to<RemoteDiagnosticsNode>();
Future<RemoteDiagnosticsNode> getRootRenderObject() {
D.assert(!disposed);
return invokeServiceMethodReturningNode("getRootRenderObject");
public Future<RemoteDiagnosticsNode> getDetailsSubtree(

public ObjectGroup next {
get
{
// _next ??= inspectorService.createObjectGroup(debugName);
if (_next == null)
{
_next = inspectorService.createObjectGroup(debugName);
}
return _next;
}

public class InspectorService
{
// VmService vmService;
return Future.value("aaa").to<string>();
return Future.value("null").to<string>();
ObjectGroup createObjectGroup(string debugName) {
public ObjectGroup createObjectGroup(string debugName) {
}
public bool useDaemonApi {
get
{
return true;
}
}
public Future<bool> isWidgetTreeReady() {
return invokeBoolServiceMethodNoArgs("isWidgetTreeReady");
}
Future<bool> invokeBoolServiceMethodNoArgs(string methodName) {
if (useDaemonApi) {
return invokeServiceMethodDaemonNoGroupArgs(methodName).then_<bool>((v)=>
{
if (v == null)
{
return false;
}
return (bool)v;
});
}
else {
// return (invokeServiceMethodObservatoryNoGroup(methodName))
// ?.valueAsString ==
// "true";
return null;
}
}
Future<object> invokeServiceMethodDaemonNoGroupArgs(string methodName,
List<string> args = null) {
Dictionary<string, object> _params = new Dictionary<string, object>();
if (args != null) {
for (int i = 0; i < args.Count; ++i) {
_params[$"arg{i}"] = args[i];
}
}
return invokeServiceMethodDaemonNoGroup(methodName, _params);
}
Future<object> invokeServiceMethodDaemonNoGroup(
string methodName, Dictionary<string, object> args) {
if (methodName == "isWidgetTreeReady")
{
return new SynchronousFuture<object>(true);
}
Debug.Log("Function invokeServiceMethodDaemonNoGroup : not implement yet");
return new SynchronousFuture<object>(false);
// string callMethodName = $"ext.flutter.inspector.{methodName}";
// if (!Globals.serviceManager.serviceExtensionManager
// .isServiceExtensionAvailable(callMethodName)) {
// return new SynchronousFuture<object>(new Dictionary<string,object>()
// {
// {"result", null}
// });
// }
//
// var r = vmService.callServiceExtension(
// callMethodName,
// isolateId: inspectorLibrary.isolateId,
// args: args
// );
// var json = r.json;
// if (json["errorMessage"] != null) {
// throw new Exception($"{methodName} -- {json["errorMessage"]}");
// }
// return json["result"];
}
// static Future<InspectorService> create(VmService vmService) async {

1
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree.cs


}
public InspectorTreeRow getCachedRow(int index) {
Debug.Log("getCachedRow: " + index);
_maybeClearCache();
while (cachedRows.Count <= index) {
cachedRows.Add(null);

4
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree_flutter.cs


public override void setState(VoidCallback fn)
{
fn();
Debug.Log("setState here");
if (client != null)
{
client.onChanged();

public Ticker createTicker(TickerCallback onTick)
{
Debug.Log("CreateTicker");
return null;
return new Ticker(null);
}
}

24
com.unity.uiwidgets.devtools/Editor/v2/src/service_manager.cs


using System.Collections.Generic;
namespace Unity.UIWidgets.DevTools
{
public class ServiceConnectionManager

_isolateManager = new IsolateManager();
ServiceExtensionManager serviceExtensionManager = new ServiceExtensionManager();
isolateManager._serviceExtensionManager = serviceExtensionManager;
serviceExtensionManager._isolateManager = isolateManager;
_isolateManager = isolateManager;
_serviceExtensionManager = serviceExtensionManager;
public ServiceExtensionManager serviceExtensionManager =>
_serviceExtensionManager;
ServiceExtensionManager _serviceExtensionManager;
public ServiceExtensionManager _serviceExtensionManager;
}
public class ServiceExtensionManager
{
public IsolateManager _isolateManager;
List<string> _serviceExtensions = new List<string>();
List<string> _pendingServiceExtensions = new List<string>();
public bool isServiceExtensionAvailable(string name) {
return _serviceExtensions.Contains(name) ||
_pendingServiceExtensions.Contains(name);
}
}
}

34
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/layout_explorer/flex/flex.cs


using Unity.UIWidgets.foundation;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.DevTools.inspector.layout_explorer.flex
{
public class FlexLayoutExplorerWidget : StatefulWidget {
public FlexLayoutExplorerWidget(
InspectorController inspectorController,
Key key = null
) : base(key: key)
{
this.inspectorController = inspectorController;
}
public readonly InspectorController inspectorController;
public static bool shouldDisplay(RemoteDiagnosticsNode node) {
return (node?.isFlex ?? false) || (node?.parent?.isFlex ?? false);
}
public override State createState()
{
return new _FlexLayoutExplorerWidgetState();
}
}
public class _FlexLayoutExplorerWidgetState : State<FlexLayoutExplorerWidget>
{
public override Widget build(BuildContext context)
{
return new Container(child: new Text("asdfafafa dakfiwejo"));
}
}
}

50
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/layout_explorer/layout_explorer.cs


using Unity.UIWidgets.DevTools.inspector.layout_explorer.flex;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
namespace Unity.UIWidgets.DevTools.inspector.layout_explorer
{
public class LayoutExplorerTab : StatefulWidget {
public LayoutExplorerTab(Key key = null, InspectorController controller = null) : base(key: key)
{
this.controller = controller;
}
public readonly InspectorController controller;
public override State createState()
{
return new _LayoutExplorerTabState();
}
}
public class _LayoutExplorerTabState : State<LayoutExplorerTab>
{
InspectorController controller => widget.controller;
RemoteDiagnosticsNode selected => controller?.selectedNode?.diagnostic;
Widget rootWidget(RemoteDiagnosticsNode node) {
if (FlexLayoutExplorerWidget.shouldDisplay(node))
return new FlexLayoutExplorerWidget(controller);
return new Center(
child: new Text(
"Currently, Layout Explorer only supports Flex-based widgets" +
"(e.g., Row, Column, Flex) or their direct children.",
textAlign: TextAlign.center,
overflow: TextOverflow.clip
)
);
}
public override Widget build(BuildContext context)
{
return rootWidget(selected);
}
}
}
正在加载...
取消
保存