void OnGUI() { var pos = new Rect(new Vector2(), position.size); pos = pos.Expand(-2f); // 2-pixel margins var line = pos.SliceTop(); EditorGUI.BeginDisabledGroup(Target == null); if (GUI.Button(line.SliceRight(60f), RefreshButton)) { Refresh(); } EditorGUI.EndDisabledGroup(); EditorGUI.LabelField(line.SliceLeft(38f), "Asset"); Target = (TextAsset)EditorGUI.ObjectField(line, Target, typeof(TextAsset), false); if (Target != null && (_containerView == null || _displayedAsset != Target)) { var info = new ContainerEditorInfo(Target); _displayedAsset = Target; _containerView = new ContainerEditorView(info, true); } if (Target == null) { Refresh(); } var updatedContainer = _containerView.Draw(pos); if (updatedContainer != null) { ContainerAssetUtils.WriteToTextAsset(updatedContainer, _displayedAsset); Refresh(); } }
public ContainerInspectorPopup(ContainerEditorInfo containerInfo, TextAsset asset) { _view = new ContainerEditorView(containerInfo, asset != null); _asset = asset; if (TextStyle == null) { TextStyle = new GUIStyle(EditorStyles.textArea); TextStyle.wordWrap = true; TextStyle.fontSize--; } }
public ContainerEditorView(ContainerEditorInfo info, bool editable) { InitStatic(); Info = info; if (info.IsValid) { info.UpdateDetailedInfo(); } _sizeText = new GUIContent(Size(Info.Size), $"Total size: {Info.Size}\nMeta data: {Info.MetaInfoSize}\nUseful: {Info.Size - Info.MetaInfoSize}"); _expandedObjects.Clear(); _idWidth = GetMaxIdWidth(Info, _idWidth); Editable = editable; }
private static float GetMaxIdWidth(ContainerEditorInfo info, float minValue = 0f) { int maxId = 0; if (info.RootObjects != null) { foreach (var root in info.RootObjects) { var rootId = GetMaxAbsId(root.Data); maxId = maxId > rootId ? maxId : rootId; } } float width = Bold.CalcSize(new GUIContent("-" + maxId)).x; return(width > minValue ? width : minValue); }
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--; } }
private void ForceUpdateContainer(SerializedProperty property) { var text = property.objectReferenceValue as TextAsset; _text = text; _container = text == null ? null : new ContainerEditorInfo(text, Event.current.alt); _color = Color.white; if (_container == null) { _infoLabel = notSelectedLabel; } else if (!_container.IsValid) { _color = Color.red; _infoLabel = invalidLabel; } else { string entitiesCount = _container.EntriesCount.ToString(); _infoLabel = new GUIContent(entitiesCount, $"Entities: {entitiesCount}, size: {ContainerEditorView.Size(_container.Size)} bytes"); } }