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(); }
public ObjectContentPopupWindow(ContainerEditorInfo containerInfo, ContainerEditorInfo.InnerObjectInfo objInfo) { _containerInfo = containerInfo; _objectInfo = objInfo; if (_objectInfo.JsonData == null & _objectInfo.TotalSize <= AutoCreateJsonSize) { _containerInfo.UpdateJsonData(_objectInfo); } if (TextStyle == null) { TextStyle = new GUIStyle(EditorStyles.textArea); TextStyle.wordWrap = true; TextStyle.fontSize--; } }