fzhangtj
6 年前
当前提交
f05de4ec
共有 33 个文件被更改,包括 2880 次插入 和 89 次删除
-
1Assets/UIWidgets/Tests/EditableTextWiget.cs
-
1Assets/UIWidgets/Tests/Paragraph.cs
-
4Assets/UIWidgets/Tests/Widgets.cs
-
67Assets/UIWidgets/editor/editor_window.cs
-
14Assets/UIWidgets/foundation/diagnostics.cs
-
2Assets/UIWidgets/painting/box_decoration.cs
-
27Assets/UIWidgets/painting/text_span.cs
-
7Assets/UIWidgets/rendering/box.cs
-
172Assets/UIWidgets/rendering/editable.cs
-
2Assets/UIWidgets/rendering/object.cs
-
30Assets/UIWidgets/rendering/paragraph.cs
-
4Assets/UIWidgets/rendering/proxy_box.cs
-
4Assets/UIWidgets/rendering/sliver.cs
-
5Assets/UIWidgets/rendering/stack.cs
-
9Assets/UIWidgets/rendering/view.cs
-
3Assets/UIWidgets/ui/painting/picture.cs
-
127Assets/UIWidgets/widgets/basic.cs
-
3Assets/UIWidgets/widgets/binding.cs
-
97Assets/UIWidgets/widgets/app.cs
-
3Assets/UIWidgets/widgets/app.cs.meta
-
1001Assets/UIWidgets/widgets/widget_inspector.cs
-
3Assets/UIWidgets/widgets/widget_inspector.cs.meta
-
410Assets/UIWidgets/debugger/diagnostics.cs
-
309Assets/UIWidgets/debugger/inpsector_panel.cs
-
3Assets/UIWidgets/debugger/inpsector_panel.cs.meta
-
66Assets/UIWidgets/debugger/inspector_objectgroup.cs
-
3Assets/UIWidgets/debugger/inspector_objectgroup.cs.meta
-
146Assets/UIWidgets/debugger/inspector_service.cs
-
258Assets/UIWidgets/debugger/inspector_treeview.cs
-
3Assets/UIWidgets/debugger/inspector_treeview.cs.meta
-
182Assets/UIWidgets/debugger/inspector_window.cs
-
3Assets/UIWidgets/debugger/inspector_window.cs.meta
|
|||
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))) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: a65e962810af4caba850ebe722776ee9 |
|||
timeCreated: 1540267826 |
1001
Assets/UIWidgets/widgets/widget_inspector.cs
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
fileFormatVersion: 2 |
|||
guid: bbffff803c4d4fd5b368c62f161e9e59 |
|||
timeCreated: 1539239769 |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
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; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 077d49fa7e054bfbafc94954e83c1b2e |
|||
timeCreated: 1540292151 |
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b28531fd9ecf4d298f2e95968f81e838 |
|||
timeCreated: 1540886500 |
|
|||
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 |
|||
} |
|||
} |
|
|||
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); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: f5253bdeb6f94869a44eff557fbf61c5 |
|||
timeCreated: 1539849580 |
|
|||
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(); |
|||
} |
|||
} |
|||
|
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 020aab88534245ff8ee7588460f7956f |
|||
timeCreated: 1539240190 |
撰写
预览
正在加载...
取消
保存
Reference in new issue