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 override void OnGUI(Rect rect) { var pos = new Rect(new Vector2(), GetWindowSize()); pos = pos.Expand(-2f); // 2-pixel margins var updatedContainer = _view.Draw(pos); if (updatedContainer != null && _asset != null) { ContainerAssetUtils.WriteToTextAsset(updatedContainer, _asset); var container = ContainerRef.FromTextAsset(_asset).Container as BinaryContainer; _view = new ContainerEditorView(new ContainerEditorInfo(container), _asset); } }
// 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)); }
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"); } }
private void Refresh() { _containerView = null; _displayedAsset = null; }