public override Vector2 GetWindowSize() { const float MinWidth = 120f; const float MaxWidth = 300f; const float MaxHeight = 400f; if (_objectInfo.JsonData == null) { return(new Vector2(230f, 102f)); } if (_textSize.x > 0f) { return(_windowSize); } var textContent = new GUIContent(_objectInfo.JsonData); _textSize.x = TextStyle.CalcSize(textContent).x; if (_objectInfo.JsonHasErrors | _textSize.x > MaxWidth) { _textSize.x = MaxWidth; } if (_textSize.x < MinWidth) { _textSize.x = MinWidth; } _textSize.y = TextStyle.CalcHeight(textContent, _textSize.x); float visibleHeight = _textSize.y; EditorHelpers.AddLineHeight(ref visibleHeight); if (_objectInfo.JsonHasErrors) { EditorHelpers.AddLineHeight(ref visibleHeight, 20f); } _windowSize.x = _textSize.x + 6f; if (visibleHeight > MaxHeight) { visibleHeight = MaxHeight; _windowSize.x += 14f; // scroll bar } _windowSize.y = visibleHeight + 8f; return(_windowSize); }
public BinaryContainer DrawContainerContent(Rect position) { BinaryContainer updatedContainer = null; _nextLineIsEven = false; var pos = position.SliceTop(); GUI.contentColor = Color.white; EditorGUI.LabelField(pos.SliceRight(SizeWidth), _sizeText, Bold); GUI.contentColor = Color.grey; EditorGUI.LabelField(pos.SliceRight(36f), "Size:", NormalRight); GUI.contentColor = Color.white; EditorGUI.LabelField(pos.SliceRight(46f), Info.EntriesCount.ToString(), Bold); GUI.contentColor = Color.grey; EditorGUI.LabelField(pos.SliceRight(52f), "Objects:", NormalRight); EditorGUI.LabelField(pos.SliceLeft(60f), "Container", EditorStyles.boldLabel); GUI.contentColor = Color.white; if (Info.HasOldVersions) { var warnRect = position.SliceTop(EditorHelpers.GetLinesHeight(Editable ? 2 : 1)); if (Editable && GUI.Button(warnRect.SliceRight(75f), UpdateSerializersButton)) { updatedContainer = Info.GetContainer(); updatedContainer.UpdateSerializers(); } EditorGUI.HelpBox(warnRect, "Has old serializers (newer version exists). Marked with yellow", MessageType.Warning); } var colHeaderRect = position.SliceTop(); // reserve a line for columns rendering (later) position = position.Expand(2f); // negate window margins GUILayout.BeginArea(position); _scrollViewHeight = position.height; _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); _parentEntries.Clear(); foreach (var e in Info.RootObjects) { DrawEntry(e); } GetNextLineVisible(out var innerLineRect); float inScrollWidth = innerLineRect.width; EditorGUILayout.EndScrollView(); GUILayout.EndArea(); // we render column header section after the table because we want to know its layout // particularly the width of the view area as the vertical scroll bar may or may not be visible GUI.contentColor = Color.gray; colHeaderRect = colHeaderRect.SliceLeft(inScrollWidth, false); EditorGUI.LabelField(colHeaderRect.SliceLeft(_idWidth), "Id", NormalRight); EditorGUI.LabelField(colHeaderRect.SliceRight(18f), JsonLabel, NormalRight); if (GUI.Button(colHeaderRect.SliceRight(SizeWidth), RenderTotalSize ? TotalSizeHeader : DataSizeHeader, NormalRight)) { RenderTotalSize = !RenderTotalSize; } GUI.contentColor = RenderSelfSize ? Color.gray : new Color(0.5f, 0.5f, 0.5f, 0.4f); if (GUI.Button(colHeaderRect.SliceRight(SizeWidth), SelfSizeHeader, NormalRight)) { RenderSelfSize = !RenderSelfSize; } colHeaderRect.SliceLeft(16f); GUI.contentColor = Color.gray; if (GUI.Button(colHeaderRect, RenderRefType ? "Ref : Object" : "Object", Normal)) { RenderRefType = !RenderRefType; } if (!Editable & updatedContainer != null) { Debug.LogError("Trying to modify uneditable container!\n"); updatedContainer = null; } return(updatedContainer); }
public override void OnGUI(Rect rect) { if (_objectInfo.JsonData == null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.SelectableLabel(_objectInfo.Caption, GUILayout.MinWidth(50f), GUILayout.MaxHeight(EditorHelpers.GetLinesHeight(1))); if (GUILayout.Button("X", GUILayout.Width(20f))) { editorWindow.Close(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.HelpBox("The object seems to be rather large. It may take a while to create JSON representation of it. Do you want to continue?", MessageType.Warning); GUI.backgroundColor = Color.yellow; if (GUILayout.Button("Show Object Data as JSON")) { _containerInfo.UpdateJsonData(_objectInfo); } GUI.backgroundColor = Color.white; return; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.SelectableLabel(_objectInfo.Caption, GUILayout.MinWidth(50f), GUILayout.MaxHeight(EditorHelpers.GetLinesHeight(1))); if (GUILayout.Button("Copy", GUILayout.Width(42f))) { GUIUtility.systemCopyBuffer = _objectInfo.JsonData; } if (GUILayout.Button("X", GUILayout.Width(20f))) { editorWindow.Close(); } EditorGUILayout.EndHorizontal(); if (_objectInfo.JsonHasErrors) { var boxRect = GUILayoutUtility.GetRect(100f, 2000f, 20f, 20f); if (_objectInfo.JsonCreated) { EditorGUI.HelpBox(boxRect, "JSON errors displayed at the end of the text", MessageType.Warning); } else { EditorGUI.HelpBox(boxRect, "Failed to serialize to JSON", MessageType.Error); } } _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos, GUIStyle.none, GUI.skin.verticalScrollbar); var textRect = GUILayoutUtility.GetRect(_textSize.x, _textSize.y, TextStyle); // TODO: unity has a bug: SelectableLabel cannot select text after a certain line number EditorGUI.SelectableLabel(textRect, _objectInfo.JsonData, TextStyle); EditorGUILayout.EndScrollView(); }