浏览代码

update inspector date 7.1

/zxw-devTools
guanghuispark 3 年前
当前提交
3700e350
共有 30 个文件被更改,包括 813 次插入127 次删除
  1. 21
      com.unity.uiwidgets.devtools/Editor/v2/src/CollapsibleAnimationMixin.mixin.gen.cs
  2. 23
      com.unity.uiwidgets.devtools/Editor/v2/src/CollapsibleAnimationMixin.mixin.njk
  3. 114
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics_node.cs
  4. 29
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs
  5. 52
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs
  6. 108
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree.cs
  7. 28
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_tree_flutter.cs
  8. 9
      com.unity.uiwidgets.devtools/Editor/v2/src/theme.cs
  9. 238
      com.unity.uiwidgets.devtools/Editor/v2/src/ui/icons.cs
  10. 8
      com.unity.uiwidgets.devtools/Editor/v2/src/utils.cs
  11. 206
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics.cs
  12. 34
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_text_styles.cs
  13. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class.png
  14. 4
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class@2x.png
  15. 3
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class_abstract.png
  16. 3
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class_abstract@2x.png
  17. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/fields.png
  18. 4
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/fields@2x.png
  19. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/info.png
  20. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/info@2x.png
  21. 4
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/interface.png
  22. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/interface@2x.png
  23. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method.png
  24. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method@2x.png
  25. 3
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method_abstract.png
  26. 4
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method_abstract@2x.png
  27. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/property.png
  28. 5
      Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/property@2x.png

21
com.unity.uiwidgets.devtools/Editor/v2/src/CollapsibleAnimationMixin.mixin.gen.cs


public abstract class CollapsibleAnimationMixinTickerProviderStateMixin<T> : TickerProviderStateMixin<T> where T : StatefulWidget {
AnimationController expandController;
bool shouldShow()
{
return isExpanded;
}
public abstract bool shouldShow();
void onExpandChanged(bool expanded)
{
}
public abstract void onExpandChanged(bool expanded);
public bool isExpanded
{

public override void initState() {
base.initState();
expandArrowAnimation = new CurvedAnimation(curve: Curves.easeInOutCubic, parent: new AnimationController(
duration: new TimeSpan(0,0,0,0,200),
expandController = new AnimationController(
duration: new TimeSpan(0, 0, 0, 0, 200),
));
);
expandArrowAnimation = new CurvedAnimation(curve: Curves.easeInOutCubic, parent: expandController);
}

23
com.unity.uiwidgets.devtools/Editor/v2/src/CollapsibleAnimationMixin.mixin.njk


public abstract class {{className | safe}} : {{with | safe}} where T : StatefulWidget {
AnimationController expandController;
Animation<float> expandArrowAnimation;
public Animation<float> expandArrowAnimation;
bool shouldShow()
{
return isExpanded;
}
public abstract bool shouldShow();
void onExpandChanged(bool expanded)
{
}
public abstract void onExpandChanged(bool expanded);
public bool isExpanded
{

public override void initState() {
base.initState();
expandArrowAnimation = new CurvedAnimation(curve: Curves.easeInOutCubic, parent: new AnimationController(
duration: new TimeSpan(0,0,0,0,200),
expandController = new AnimationController(
duration: new TimeSpan(0, 0, 0, 0, 200),
));
);
expandArrowAnimation = new CurvedAnimation(curve: Curves.easeInOutCubic, parent: expandController);
}

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


namespace Unity.UIWidgets.DevTools.inspector
{
public static class DiagnosticsNodeUtils
{
public static EnumUtils<DiagnosticLevel> diagnosticLevelUtils
{
get
{
List<DiagnosticLevel> styles = new List<DiagnosticLevel>();
foreach (DiagnosticLevel style in Enum.GetValues(typeof(DiagnosticLevel)))
{
styles.Add(style);
}
return new EnumUtils<DiagnosticLevel>(styles);
}
}
}
public class RemoteDiagnosticsNode : DiagnosticableTree {
public RemoteDiagnosticsNode(
Dictionary<string, object> json,

}
public string separator => showSeparator ? ":" : "";
public bool showSeparator => getBooleanMember("showSeparator", true);
public bool hasDefaultValue => json.ContainsKey("defaultValue");
public bool isSummaryTree => getBooleanMember("summaryTree", false);
public bool isCreatedByLocalProject {
get
{
return getBooleanMember("createdByLocalProject", false);
}
}
public string description => getStringMember("description");
public string name
{
get

}
}
public Dictionary<string, object> valuePropertiesJson
{
get
{
if (json.ContainsKey("valueProperties"))
{
return (Dictionary<string, object>) json["valueProperties"];
}
return new Dictionary<string, object>(){{"valueProperties","null"}};
}
}
public bool hasChildren {
get
{

}
public bool isDiagnosticableValue {
get
{
return getBooleanMember("isDiagnosticableValue", false);
}
}
public bool showName => getBooleanMember("showName", true);
public DiagnosticLevel level => getLevelMember("level", DiagnosticLevel.info);
public string propertyType => getStringMember("propertyType");
bool getBooleanMember(string memberName, bool defaultValue)
{
if (json.ContainsKey(memberName))

return (bool)json[memberName];
}
return false;
return defaultValue;
DiagnosticLevel getLevelMember(
string memberName, DiagnosticLevel defaultValue)
{
string value = null;
if (json.ContainsKey(memberName))
{
value = (string)json[memberName];
}
if (value == null) {
return defaultValue;
}
var level = DiagnosticsNodeUtils.diagnosticLevelUtils.enumEntry(value);
D.assert(level != null, () => $"Unabled to find level for {value}");
if (level != null)
{
return level;
}
return defaultValue;
}
List<RemoteDiagnosticsNode> _childrenFuture;
public List<RemoteDiagnosticsNode> children {
get
{
// _computeChildren();
return _childrenFuture;
}
}
// void _computeChildren() {
// _maybePopulateChildren();
// if (!hasChildren || _children != null) {
// return;
// }
//
// if (_childrenFuture != null) {
// return;
// }
//
// _childrenFuture = _getChildrenHelper();
// try {
// _children = _childrenFuture;
// } finally {
// if (_children == null)
// {
// _children = new List<RemoteDiagnosticsNode>();
// }
// }
// }
public List<RemoteDiagnosticsNode> inlineProperties {
get
{

}
void _maybePopulateChildren() {
public void _maybePopulateChildren() {
if (!hasChildren || _children != null) {
return;
}

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


using System.Text.RegularExpressions;
using Unity.UIWidgets.async;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
public static class InspectorControllerUtils
{
public static TextStyle textStyleForLevel(DiagnosticLevel level, ColorScheme colorScheme) {
switch (level) {
case DiagnosticLevel.hidden:
return inspector_text_styles.unimportant(colorScheme);
case DiagnosticLevel.warning:
return inspector_text_styles.warning(colorScheme);
case DiagnosticLevel.error:
return inspector_text_styles.error(colorScheme);
case DiagnosticLevel.debug:
case DiagnosticLevel.info:
case DiagnosticLevel.fine:
default:
return inspector_text_styles.regular;
}
}
}
class InspectorController
{
public InspectorController(

// onNodeAdded: _onNodeAdded,
// onHover: highlightShowNode,
// onSelectionChange: selectionChanged,
// onExpand: _onExpand,
onExpand: _onExpand,
onClientActiveChange: _onClientChange
);
if (isSummaryTree) {

}
}
void _onExpand(InspectorTreeNode node) {
inspectorTree.maybePopulateChildren(node);
}
void _onClientChange(bool added) {
_clientCount += added ? 1 : -1;

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


Dictionary<string, object> widgetTree = new Dictionary<string, object>();
widgetTree["hasChildren"] = true;
widgetTree["name"] = "inspector";
widgetTree["type"] = "root";
widgetTree["propertyType"] = "IconData";
widgetTree["description"] = "root widget";
{"name", "inspector2"},
{"creationLocation1",new Text("creationLocation1")},
};

};
widgetTree["children"] = new List<Dictionary<string, object>>()
{
{
{
{"name", "inspector3"},
{"type", "class"},
{"description","second level widget"},
"text1", new List<Dictionary<string,object>>()
"text", new List<Dictionary<string,object>>()
{"name","inspector2"},
{"name","inspector4"},
{"description","third level widget"},
{"creationLocation", new Dictionary<string, object>()
{
{"creationLocation1",new Text("creationLocation1")},

},
new Dictionary<string, object>()
{
{"name", "inspector5"},
{"type", "class"},
{"description","second level widget"},
{"te1",new Text("text1a")},
{"te2",new Text("text2a")},
{"te3",new Text("text3a")},

};
// widgetTree["properties"] = new List<Dictionary<string, object>>()
// {
// new Dictionary<string, object>()
// {
// {"properties1",new Text("properties1")},
// {"properties2",new Text("properties2")},
// {"properties3",new Text("properties3")},
// {"properties4",new Text("properties4")},
// {"properties5",new Text("properties5")},
// },
// new Dictionary<string, object>()
// {
// {"pro1",new Text("pro1a")},
// {"pro2",new Text("pro2a")},
// {"pro3",new Text("pro3a")},
// {"pro4",new Text("pro4a")},
// {"pro5",new Text("pro5a")},
// }
// };
widgetTree["properties"] = new List<Dictionary<string, object>>()
{
new Dictionary<string, object>()
{
{"name","properties1"},
{"type", "property"},
{"description","this is a description"},
},
new Dictionary<string, object>()
{
{"name","properties2"},
{"type", "property"},
{"description","this is a description"},
}
};
return new RemoteDiagnosticsNode(widgetTree,
inspectorService: FutureOr.value(inspectorService),
true,

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


using System.Collections.Generic;
using System;using System.Collections.Generic;
using System.Text.RegularExpressions;
using uiwidgets;
using Unity.UIWidgets.async;
using Unity.UIWidgets.DevTools.inspector;

public static readonly float columnWidth = 16.0f;
public static readonly float verticalPadding = 10.0f;
public static readonly float rowHeight = 24.0f;
public static readonly Regex treeNodePrimaryDescriptionPattern = new Regex(@"^([\w ]+)(.*)$");
public static readonly Regex assertionThrownBuildingError = new Regex(
@"^(The following assertion was thrown building [a-zA-Z]+)(\(.*\))(:)$");
public static bool isLight = false;
public static Color selectedRowBackgroundColor
{

}
}
InspectorTreeNode selection => _selection;
InspectorTreeNode _selection;
public InspectorTreeNode root
{
get

InspectorTreeNode _hover;
List<InspectorTreeRow> cachedRows = new List<InspectorTreeRow>();
void nodeChanged(InspectorTreeNode node) {
if (node == null) return;
setState(() => {
node.isDirty = true;
});
}
void _maybeClearCache() {
if (root.isDirty) {
cachedRows.Clear();

}
void expandPath(InspectorTreeNode node) {
setState(() => {
_expandPath(node);
});
}
void _expandPath(InspectorTreeNode node) {
while (node != null) {
if (!node.isExpanded) {
node.isExpanded = true;
}
node = node.parent;
}
}
public InspectorTreeRow getCachedRow(int index) {
Debug.Log("getCachedRow: " + index);

}
}
}
public void onExpandRow(InspectorTreeRow row) {
setState(() => {
row.node.isExpanded = true;
if (config.onExpand != null) {
config.onExpand(row.node);
}
});
}
public void onCollapseRow(InspectorTreeRow row) {
setState(() => {
row.node.isExpanded = false;
});
}
public void maybePopulateChildren(InspectorTreeNode treeNode) {
RemoteDiagnosticsNode diagnostic = treeNode.diagnostic;
if (diagnostic != null &&
diagnostic.hasChildren &&
(treeNode.hasPlaceholderChildren || treeNode.children.isEmpty())) {
try {
var children = diagnostic.children;
if (treeNode.hasPlaceholderChildren || treeNode.children.isEmpty()) {
setupChildren(
diagnostic,
treeNode,
children,
expandChildren: true,
expandProperties: false
);
nodeChanged(treeNode);
if (treeNode == selection) {
expandPath(treeNode);
}
}
} catch (Exception e) {
Debug.Log(e.ToString());
}
}
}
public delegate void TreeEventCallback(InspectorTreeNode node);
public delegate void OnClientActiveChange(bool added);
public class InspectorTreeConfig {

// NodeAddedCallback onNodeAdded,
OnClientActiveChange onClientActiveChange = null,
VoidCallback onSelectionChange = null
// TreeEventCallback onExpand,
// TreeEventCallback onHover
VoidCallback onSelectionChange = null,
TreeEventCallback onExpand = null,
TreeEventCallback onHover = null
)
{
this.summaryTree = summaryTree;

this.onExpand = onExpand;
this.onHover = onHover;
}
public readonly bool summaryTree;

public readonly OnClientActiveChange onClientActiveChange;
// public readonly TreeEventCallback onExpand;
// public readonly TreeEventCallback onHover;
public readonly TreeEventCallback onExpand;
public readonly TreeEventCallback onHover;
}

{
return (diagnostic?.hasChildren == true || children.isNotEmpty()) &&
allowExpandCollapse;
}
}
public bool? shouldShow {
get
{
if (_shouldShow != null)
{
return _shouldShow;
}
_shouldShow = (parent == null || parent.isExpanded && (parent._shouldShow != null && parent.shouldShow.Value));
return _shouldShow;
}
}
public bool hasPlaceholderChildren {
get
{
return children.Count == 1 && children.First().diagnostic == null;
}
}

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


public readonly _InspectorTreeState inspectorTreeState;
InspectorTreeNode node
public InspectorTreeNode node
{
get
{

expandArrowAnimation: expandArrowAnimation,
controller: widget.inspectorTreeState.controller,
onToggle: () => {
// setExpanded(!isExpanded);
setExpanded(!isExpanded);
public new bool isExpanded => widget.node.isExpanded;
public override void onExpandChanged(bool expanded) {
setState(() => {
var row = widget.row;
if (expanded) {
widget.inspectorTreeState.controller.onExpandRow(row);
} else {
widget.inspectorTreeState.controller.onCollapseRow(row);
}
});
}
public override bool shouldShow() => widget.node.shouldShow.Value;
}
public class InspectorTreeControllerFlutter : InspectorTreeController

// controller.navigateRight();
// return true;
// }
Debug.Log("enter _handleKeyEvent");
return false;
}

width: controller.rowWidth + controller.maxRowIndent,
child: new Scrollbar(
child: new GestureDetector(
onTap: null,// gestureTapCallback,
onTap: null, // gestureTapCallback,
child: new Focus(
onKey: _handleKeyEvent,
autofocus: widget.isSummaryTree,

child: new Container(
height: _InspectorTreeRowWidgetUtils.rowHeight,
padding: EdgeInsets.symmetric(horizontal: 4.0f),
child: new Text(node.ToString())// new DiagnosticsNodeDescription(node.diagnostic)
child: new DiagnosticsNodeDescription(node.diagnostic)
)
)
),

9
com.unity.uiwidgets.devtools/Editor/v2/src/theme.cs


using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.DevTools.inspector;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;

{600, new Color(0xFF0175C2)},
{400, new Color(0xFF13B9FD)},
});
public static Color defaultBackground => InspectorTreeUtils.isLight ? Colors.white : Colors.black;
public static Color defaultForeground =>
InspectorTreeUtils.isLight ? Colors.black : Color.fromARGB(255, 187, 187, 187);
public static Color grey => Color.fromARGB(255, 128, 128, 128);
}
}

238
com.unity.uiwidgets.devtools/Editor/v2/src/ui/icons.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.DevTools.inspector;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;

{
public static Image createImageIcon(string url, float size = ThemeUtils.defaultIconSize) {
return new Image(
image: new AssetImage(url),
image: new FileImage(url),
height: size,
width: size
);

public class ColorIconMaker {
Dictionary<Color, ColorIcon> iconCache = new Dictionary<Color, ColorIcon>();
public ColorIcon getCustomIcon(Color color) {
return iconCache.putIfAbsent(color, () => new ColorIcon(color));
}
}
class CustomIcon : StatelessWidget {
public class CustomIcon : StatelessWidget {
public CustomIcon(
IconKind kind = null,
string text = null,

}
class CustomIconMaker {
public class CustomIconMaker {
CustomIcon getCustomIcon(string fromText,
IconKind kind = null, bool isAbstract = false) {
if (kind == null)
CustomIcon getCustomIcon(string fromText,
IconKind kind = null, bool isAbstract = false)
kind = IconKind.classIcon;
}
if (fromText?.isEmpty() != false) {
return null;
}
string text = toUpperCase(fromText[0].ToString());
string mapKey = $"{text}_{kind.name}_{isAbstract}";
if (kind == null)
{
kind = IconKind.classIcon;
}
if (fromText?.isEmpty() != false) {
return null;
}
string text = toUpperCase(fromText[0].ToString());
string mapKey = $"{text}_{kind.name}_{isAbstract}";
return iconCache.putIfAbsent(mapKey, () => {
return new CustomIcon(kind: kind, text: text, isAbstract: isAbstract);
});
}
return iconCache.putIfAbsent(mapKey, () => {
return new CustomIcon(kind: kind, text: text, isAbstract: isAbstract);
});
}
string toUpperCase(string str)
{
if (str != null)
string toUpperCase(string str)
string retStr = string.Empty;
for (int i = 0; i < str.Length; i++)
if (str != null)
if (str[i]>='a'&&str[i]<='z')
string retStr = string.Empty;
for (int i = 0; i < str.Length; i++)
retStr += (char)(str[i] - 'a' + 'A');
continue;
if (str[i]>='a'&&str[i]<='z')
{
retStr += (char)(str[i] - 'a' + 'A');
continue;
}
retStr += str[i];
retStr += str[i];
return retStr;
return retStr;
return "str is null";
return "str is null";
}
public CustomIcon fromWidgetName(string name) {
if (name == null) {
return null;
}
public CustomIcon fromWidgetName(string name) {
if (name == null) {
return null;
}
bool isPrivate = name.StartsWith("_");
while (name.isNotEmpty() && !isAlphabetic(name[0])) {
name = name.Substring(1);
}
bool isPrivate = name.StartsWith("_");
while (name.isNotEmpty() && !isAlphabetic(name[0])) {
name = name.Substring(1);
}
if (name.isEmpty()) {
return null;
}
if (name.isEmpty()) {
return null;
}
return getCustomIcon(
name,
kind: isPrivate ? IconKind.method : IconKind.classIcon
);
}
return getCustomIcon(
name,
kind: isPrivate ? IconKind.method : IconKind.classIcon
);
}
public CustomIcon fromInfo(String name) {
if (name == null) {
return null;
}
CustomIcon fromInfo(String name) {
if (name == null) {
return null;
}
if (name.isEmpty()) {
return null;
}
if (name.isEmpty()) {
return null;
}
return getCustomIcon(name, kind: IconKind.info);
}
return getCustomIcon(name, kind: IconKind.info);
}
bool isAlphabetic(int _char) {
return (_char < '0' || _char > '9') &&
_char != '_' &&
_char != '$';
}
}
bool isAlphabetic(int _char) {
return (_char < '0' || _char > '9') &&
_char != '_' &&
_char != '$';
}
}
class IconKind {
public class IconKind {
public IconKind(string name, Image icon, Image abstractIcon = null)
{
this.name = name;

public readonly string name;
public readonly Image icon;
public readonly Image abstractIcon;
}
public class ColorIcon : StatelessWidget {
public ColorIcon(Color color)
{
this.color = color;
}
public readonly Color color;
public override Widget build(BuildContext context) {
var colorScheme = Theme.of(context).colorScheme;
return new CustomPaint(
painter: new _ColorIconPainter(color, colorScheme),
size: new Size(ThemeUtils.defaultIconSize, ThemeUtils.defaultIconSize)
);
}
}
public static class FlutterMaterialIcons {
public static Icon getIconForCodePoint(int charCode, ColorScheme colorScheme) {
return new Icon(new IconData(charCode), color: ThemeUtils.defaultForeground);
}
}
class _ColorIconPainter : AbstractCustomPainter {
public _ColorIconPainter(Color color, ColorScheme colorScheme)
{
this.color = color;
this.colorScheme = colorScheme;
}
public readonly Color color;
public readonly ColorScheme colorScheme;
public static readonly float iconMargin = 1.0f;
public override void paint(Canvas canvas, Size size) {
// draw a black and gray grid to use as the background to disambiguate
// opaque colors from translucent colors.
Paint greyPaint = new Paint();
Paint defaultPaint = new Paint();
Paint paint = new Paint();
Paint paint2 = new Paint();
paint2.style = PaintingStyle.stroke;
paint2.color = ThemeUtils.defaultForeground;
paint.color = color;
defaultPaint.color = ThemeUtils.defaultBackground;
greyPaint.color = ThemeUtils.grey;
var iconRect = Rect.fromLTRB(
iconMargin,
iconMargin,
size.width - iconMargin,
size.height - iconMargin
);
canvas.drawRect(
Rect.fromLTRB(
iconMargin,
iconMargin,
size.width - iconMargin,
size.height - iconMargin
),
defaultPaint
);
canvas.drawRect(
Rect.fromLTRB(
iconMargin,
iconMargin,
size.width * 0.5f,
size.height * 0.5f
),
greyPaint
);
canvas.drawRect(
Rect.fromLTRB(
size.width * 0.5f,
size.height * 0.5f,
size.width - iconMargin,
size.height - iconMargin
),
greyPaint
);
canvas.drawRect(
iconRect,
paint
);
canvas.drawRect(
iconRect,
paint2
);
}
public override bool shouldRepaint(CustomPainter oldDelegate) {
// if (oldDelegate is _ColorIconPainter) {
// return ((_ColorIconPainter)oldDelegate).colorScheme.isLight != InspectorTreeUtils.isLight;
// }
return true;
}
}
}

8
com.unity.uiwidgets.devtools/Editor/v2/src/utils.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using UnityEngine;
namespace Unity.UIWidgets.DevTools
{

public static string getStringMember(Dictionary<string, object> json, string memberName) {
// TODO(jacobr): should we handle non-string values with a reasonable
// toString differently?
return json[memberName] as string;
if (json.ContainsKey(memberName))
{
return json[memberName] as string;
}
Debug.Log("key not found: " + memberName);
return "key not found: " + memberName;
}
public static int getIntMember(Dictionary<string, object> json, string memberName) {

206
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/diagnostics.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.DevTools.ui;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.DevTools.inspector
{
public static class DiagnosticsUtils
{
public static ColorIconMaker _colorIconMaker = new ColorIconMaker();
public static CustomIconMaker _customIconMaker = new CustomIconMaker();
public static readonly bool _showRenderObjectPropertiesAsLinks = false;
public static CustomIcon defaultIcon = _customIconMaker.fromInfo("Default");
}
class DiagnosticsNodeDescription : StatelessWidget {
public DiagnosticsNodeDescription(RemoteDiagnosticsNode diagnostic)
{
this.diagnostic = diagnostic;
}
public readonly RemoteDiagnosticsNode diagnostic;
Widget _paddedIcon(Widget icon) {
return new Padding(
padding: EdgeInsets.only(right: InspectorTreeUtils.iconPadding),
child: icon
);
}
void _addDescription(
List<Widget> output,
String description,
TextStyle textStyle,
ColorScheme colorScheme,
bool isProperty = false
) {
if (diagnostic.isDiagnosticableValue) {
var match = InspectorTreeUtils.treeNodePrimaryDescriptionPattern.Match(description);
if (match != null) {
output.Add(new Text(match.Groups[1].Value, style: textStyle));
if (match.Groups[2].Value.isNotEmpty()) {
output.Add(new Text(
match.Groups[2].Value,
style: inspector_text_styles.unimportant(colorScheme)
));
}
return;
}
} else if (diagnostic.type == "ErrorDescription") {
var match = InspectorTreeUtils.assertionThrownBuildingError.Match(description);
if (match != null) {
output.Add(new Text(match.Groups[1].Value, style: textStyle));
output.Add(new Text(match.Groups[3].Value, style: textStyle));
return;
}
}
if (description?.isNotEmpty() == true) {
output.Add(new Text(description, style: textStyle));
}
}
public override Widget build(BuildContext context) {
if (diagnostic == null) {
return new SizedBox();
}
var colorScheme = Theme.of(context).colorScheme;
var icon = diagnostic.icon;
var children = new List<Widget>();
if (icon != null) {
children.Add(_paddedIcon(icon));
}
string name = diagnostic.name;
TextStyle textStyle = InspectorControllerUtils.textStyleForLevel(diagnostic.level, colorScheme);
if (diagnostic.isProperty)
{
// Display of inline properties.
string propertyType = diagnostic.propertyType;
Dictionary<string, object> properties = diagnostic.valuePropertiesJson;
if (name?.isNotEmpty() == true && diagnostic.showName)
{
children.Add(new Text($"{name}{diagnostic.separator} ", style: textStyle));
}
if (diagnostic.isCreatedByLocalProject) {
textStyle =
textStyle.merge(inspector_text_styles.regularBold(colorScheme));
}
string description = diagnostic.description;
if (propertyType != null && properties != null)
{
switch (propertyType) {
case "Color":
{
int alpha = JsonUtils.getIntMember(properties, "alpha");
int red = JsonUtils.getIntMember(properties, "red");
int green = JsonUtils.getIntMember(properties, "green");
int blue = JsonUtils.getIntMember(properties, "blue");
// string radix(int chan) => chan.toRadixString(16).padLeft(2, '0');
string radix(int chan) => chan.ToString();
if (alpha == 255) {
description = $"#{radix(red)}{radix(green)}{radix(blue)}";
} else {
description =
$"#{radix(alpha)}{radix(red)}{radix(green)}{radix(blue)}";
}
Color color = Color.fromARGB(alpha, red, green, blue);
children.Add(_paddedIcon(DiagnosticsUtils._colorIconMaker.getCustomIcon(color)));
break;
}
case "IconData":
{
int codePoint =
JsonUtils.getIntMember(properties, "codePoint");
if (codePoint > 0) {
var icon_ = FlutterMaterialIcons.getIconForCodePoint(
codePoint,
colorScheme
);
if (icon_ != null) {
children.Add(_paddedIcon(icon_));
}
}
break;
}
}
}
if (DiagnosticsUtils._showRenderObjectPropertiesAsLinks
&& propertyType == "RenderObject") {
// textStyle = textStyle..merge(inspector_text_styles.link(colorScheme));
}
// TODO(jacobr): custom display for units, iterables, and padding.
_addDescription(
children,
description,
textStyle,
colorScheme,
isProperty: true
);
if (diagnostic.level == DiagnosticLevel.fine &&
diagnostic.hasDefaultValue) {
children.Add(new Text(" "));
children.Add(_paddedIcon(DiagnosticsUtils.defaultIcon));
}
} else {
// Non property, regular node case.
if (name?.isNotEmpty() == true && diagnostic.showName && name != "child") {
if (name.StartsWith("child ")) {
children.Add(new Text(
name,
style: inspector_text_styles.unimportant(colorScheme)
));
} else {
children.Add(new Text(name, style: textStyle));
}
if (diagnostic.showSeparator) {
children.Add(new Text(
diagnostic.separator,
style: inspector_text_styles.unimportant(colorScheme)
));
if (diagnostic.separator != " " &&
diagnostic.description.isNotEmpty()) {
children.Add(new Text(
" ",
style: inspector_text_styles.unimportant(colorScheme)
));
}
}
}
if (!diagnostic.isSummaryTree && diagnostic.isCreatedByLocalProject) {
textStyle =
textStyle.merge(inspector_text_styles.regularBold(colorScheme));
}
_addDescription(
children,
diagnostic.description,
textStyle,
colorScheme,
isProperty: false
);
}
return new Row(mainAxisSize: MainAxisSize.min, children: children);
}
}
}

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


using uiwidgets;
using Unity.UIWidgets.material;
using Unity.UIWidgets.ui;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.DevTools.inspector
{
public static class inspector_text_styles
{
public static TextStyle unimportant(ColorScheme colorScheme) => new TextStyle(
color: InspectorTreeUtils.isLight ? Colors.grey.shade500 : Colors.grey.shade600);
public static TextStyle regular = new TextStyle();
public static TextStyle warning(ColorScheme colorScheme) => new TextStyle(
color:
InspectorTreeUtils.isLight ? Colors.orange.shade900 : Colors.orange.shade400);
public static TextStyle error(ColorScheme colorScheme) => new TextStyle(
color: InspectorTreeUtils.isLight ? Colors.red.shade500 : Colors.red.shade400
);
public static TextStyle regularBold(ColorScheme colorScheme) => new TextStyle(
color: ThemeUtils.defaultForeground,
fontWeight: FontWeight.w700
);
public static TextStyle regularItalic(ColorScheme colorScheme) => new TextStyle(
color: ThemeUtils.defaultForeground,
fontStyle: FontStyle.italic
);
public static TextStyle unimportantItalic(ColorScheme colorScheme) =>
unimportant(colorScheme).merge(new TextStyle(
fontStyle: FontStyle.italic
));
}
}

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 192 B

4
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 286 B

3
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class_abstract.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 213 B

3
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/class_abstract@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 327 B

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/fields.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 214 B

4
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/fields@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 304 B

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/info.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 1.6 KiB

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/info@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 1.7 KiB

4
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/interface.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 206 B

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/interface@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 311 B

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 192 B

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 294 B

3
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method_abstract.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 213 B

4
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/method_abstract@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 345 B

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/property.png

之前 之后
宽度: 16  |  高度: 16  |  大小: 192 B

5
Samples/UIWidgetsSamples_2019_4/Assets/StreamingAssets/icons/custom/property@2x.png

之前 之后
宽度: 32  |  高度: 32  |  大小: 294 B
正在加载...
取消
保存