예제 #1
0
 private static void InitStatic()
 {
     if (Bold != null)
     {
         return;
     }
     Bold = new GUIStyle(EditorStyles.whiteBoldLabel);
     Bold.normal.textColor = Color.white;
     Normal                = EditorStyles.whiteLabel;
     BoldRight             = new GUIStyle(Bold);
     BoldRight.alignment   = TextAnchor.LowerRight;
     NormalRight           = new GUIStyle(Normal);
     NormalRight.alignment = TextAnchor.LowerRight;
     _lineHeight           = EditorHelpers.GetLinesHeight(1);
 }
예제 #2
0
 // returns updated container if it was changed, null otherwise
 public static BinaryContainer Draw(this ContainerEditorView view, Rect position)
 {
     if (view == null)
     {
         var boxRect = position.SliceTop(EditorHelpers.GetLinesHeight(2));
         EditorGUI.HelpBox(boxRect, "Select a container asset", MessageType.Info);
         return(null);
     }
     if (!view.Info.IsValid)
     {
         var boxRect = position.SliceTop(EditorHelpers.GetLinesHeight(2));
         EditorGUI.HelpBox(boxRect, "This is not a valid container", MessageType.Error);
         return(null);
     }
     return(view.DrawContainerContent(position));
 }
예제 #3
0
        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);
        }
예제 #4
0
        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();
        }