Skip to content

Commit

Permalink
[v0.0.4] Fix close command
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed Jan 23, 2025
1 parent d524896 commit ad22086
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 36 deletions.
8 changes: 3 additions & 5 deletions Runtime/Commands/CloseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ public sealed class CloseCommand : IDevelopmentCommand
[field: SerializeField] public string Description { get; set; } = "Close the development console.";

private IDevelopmentConsoleOutput _console;
private IDevelopmentConsoleOutput Console => _console ??=
(IDevelopmentConsoleOutput)Object
.FindObjectsOfType(typeof(Object))
.FirstOrDefault(x => x.GetType()
.IsAssignableFrom(typeof(IDevelopmentConsoleOutput)));
private IDevelopmentConsoleOutput Console => _console ??= Object
.FindObjectsOfType<MonoBehaviour>()
.FirstOrDefault(x => x is IDevelopmentConsoleOutput) as IDevelopmentConsoleOutput;

bool IDevelopmentCommand.Execute(string[] args)
{
Expand Down
19 changes: 5 additions & 14 deletions Runtime/IMGUI/IMGUIDevelopmentConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public sealed class IMGUIDevelopmentConsole : MonoBehaviour,
private bool _needFocus = true;
private float _lastInputTime = -1f;

private GUIStyle _styleTextX;
private GUIStyle _styleTextArea;
private GUIStyle _textStyle;
private Matrix4x4 _originalGUIMatrix;

private event Action<ConsoleAction> StateChanged;
Expand Down Expand Up @@ -70,19 +69,11 @@ public bool Show

private void DrawGUI()
{
_styleTextArea ??= new GUIStyle(GUI.skin.textArea)
{
fontStyle = FontStyle.Italic,
fontSize = _settings.FontSize,
alignment = TextAnchor.MiddleLeft,
normal = { textColor = _settings.FontColor }
};

_styleTextX ??= new GUIStyle(GUI.skin.textArea)
_textStyle ??= new GUIStyle(GUI.skin.textArea)
{
fontStyle = FontStyle.Bold,
fontSize = _settings.FontSize,
alignment = TextAnchor.MiddleCenter,
alignment = TextAnchor.MiddleLeft,
normal = { textColor = _settings.FontColor }
};

Expand All @@ -94,9 +85,9 @@ private void DrawGUI()

GUILayout.BeginHorizontal();
GUI.SetNextControlName(Settings.TEXT_INPUT_NAME);
Value = GUILayout.TextField(Value, _styleTextArea, GUILayout.ExpandHeight(true));
Value = GUILayout.TextField(Value, _textStyle, GUILayout.ExpandHeight(true));
var height = _settings.Height - _settings.Margin * 2f;
if (GUILayout.Button("X", _styleTextX, GUILayout.Width(_settings.Height), GUILayout.Height(height)))
if (GUILayout.Button("X", _textStyle, GUILayout.Width(_settings.Height), GUILayout.Height(height)))
{
Show = false;
}
Expand Down
31 changes: 15 additions & 16 deletions Samples~/DevelopmentConsoleShowcase.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
using UnityEngine;

namespace Depra.Console.Development.Samples {
[RequireComponent(typeof(ITextOutputPort))]
[RequireComponent(typeof(IDevelopmentConsoleInterface))]
internal sealed class DevelopmentConsoleShowcase : MonoBehaviour {
namespace Depra.Console.Development.Samples
{
[RequireComponent(typeof(IDevelopmentConsoleInput))]
[RequireComponent(typeof(IDevelopmentConsoleOutput))]
internal sealed class DevelopmentConsoleShowcase : MonoBehaviour
{
private DevelopmentConsole _console;

private void Start() {
_console = new DevelopmentConsole(
GetComponent<ITextOutputPort>(),
GetComponent<IDevelopmentConsoleInterface>());

_console.AddCommands(new IDevelopmentCommand[] {
new QuitCommand(),
new CloseCommand(),
new DestroyCommand(),
new PrimitiveCommand()
});
}
private void Start() => _console = new DevelopmentConsole(
inputPort: GetComponent<IDevelopmentConsoleInput>(),
outputPort: GetComponent<IDevelopmentConsoleOutput>(),
commands: new DevelopmentCommandList()
.Add(new QuitCommand())
.Add(new CloseCommand())
.Add(new CloseCommand())
.Add(new DestroyCommand())
.Add(new PrimitiveCommand()));

private void OnDestroy() => _console?.Dispose();
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "com.depra.console.dev",
"version": "0.0.3",
"version": "0.0.4",
"displayName": "Depra.Console.Development",
"description": "",
"unity": "2022.3",
Expand Down

0 comments on commit ad22086

Please sign in to comment.