Skip to content

Commit

Permalink
[v0.0.1] First release
Browse files Browse the repository at this point in the history
  • Loading branch information
g0dzZz-coder committed Jan 23, 2025
1 parent 3fe9fe6 commit 332e559
Show file tree
Hide file tree
Showing 58 changed files with 1,036 additions and 27 deletions.
15 changes: 0 additions & 15 deletions Editor/Depra.Template.Editor.asmdef

This file was deleted.

7 changes: 7 additions & 0 deletions LICENSE.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions README.md.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Runtime.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Runtime/Attributes.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions Runtime/Attributes/DevelopmentCommandAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-License-Identifier: Apache-2.0
// © 2025 Nikolay Melnikov <[email protected]>

using System;
using System.Runtime.CompilerServices;
using UnityEngine;

namespace Depra.Console.Development
{
/// <summary>
/// Marks the associated method as a command.
/// This means it will be usable as a command from a console.
/// </summary>
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = true, Inherited = false)]
public sealed class DevelopmentCommandAttribute : Attribute
{
private static readonly char[] BANNED_ALIAS_CHARS = { ' ', '(', ')', '{', '}', '[', ']', '<', '>' };

public readonly string Alias;
public readonly string Usage;
public readonly string Description;
public readonly bool Valid = true;

public DevelopmentCommandAttribute(string alias, string usage = "", string description = "") : this(alias)
{
Usage = usage;
Description = description;
}

public DevelopmentCommandAttribute([CallerMemberName] string alias = "")
{
Alias = alias.ToLower();
foreach (var symbol in BANNED_ALIAS_CHARS)
{
if (Alias.Contains(symbol) == false)
{
continue;
}

Debug.LogError(
"Development Processor Error: " +
$"Command with alias '{Alias}' contains the char '{symbol}' which is banned. " +
"Unexpected behaviour may occur.");

Valid = false;
}
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Attributes/DevelopmentCommandAttribute.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Runtime/Commands.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions Runtime/Commands/CloseCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// SPDX-License-Identifier: Apache-2.0
// © 2025 Nikolay Melnikov <[email protected]>

using System.Linq;
using UnityEngine;

namespace Depra.Console.Development
{
[System.Serializable]
public sealed class CloseCommand : IDevelopmentCommand
{
[field: SerializeField] public string Alias { get; set; } = "close";
[field: SerializeField] public string Usage { get; set; } = "close";
[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)));

bool IDevelopmentCommand.Execute(string[] args)
{
if (Console != null)
{
Console.Show = false;
}

return Console != null;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Commands/CloseCommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions Runtime/Commands/DestroyCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: Apache-2.0
// © 2025 Nikolay Melnikov <[email protected]>

using System.Linq;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Depra.Console.Development
{
[System.Serializable]
public sealed class DestroyCommand : IDevelopmentCommand
{
[field: SerializeField] public string Alias { get; set; } = "destroy";
[field: SerializeField] public string Usage { get; set; } = "destroy 'gameobject-name'";
[field: SerializeField] public string Description { get; set; } = "Destroy GameObject.";

bool IDevelopmentCommand.Execute(string[] args)
{
if (args.Length != 1)
{
return false;
}

var gameObjectName = args[0];
// @HACK: Active and inactive GameObjects.
var gameObjectsToDestroy = Resources
.FindObjectsOfTypeAll<GameObject>()
.Where(gameObject => gameObjectName.Equals(gameObject.name.ToLower())).ToList();

for (var index = gameObjectsToDestroy.Count - 1; index >= 0; index--)
{
Object.Destroy(gameObjectsToDestroy[index]);
}

return true;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Commands/DestroyCommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions Runtime/Commands/DevelopmentCommandList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: Apache-2.0
// © 2025 Nikolay Melnikov <[email protected]>

using System.Collections.Generic;

namespace Depra.Console.Development
{
public sealed class DevelopmentCommandList : IDevelopmentCommands
{
private readonly List<IDevelopmentCommand> _commands = new();

public DevelopmentCommandList Add(IDevelopmentCommand command)
{
_commands.Add(command);
return this;
}

int IDevelopmentCommands.Count => _commands.Count;
IDevelopmentCommand IDevelopmentCommands.this[int index] => _commands[index];

bool IDevelopmentCommands.Contains(IDevelopmentCommand command) => _commands.Contains(command);
void IDevelopmentCommands.Add(IDevelopmentCommand command) => _commands.Add(command);
void IDevelopmentCommands.Remove(IDevelopmentCommand command) => _commands.Remove(command);
}
}
3 changes: 3 additions & 0 deletions Runtime/Commands/DevelopmentCommandList.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 94 additions & 0 deletions Runtime/Commands/GameObjectCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// SPDX-License-Identifier: Apache-2.0
// © 2025 Nikolay Melnikov <[email protected]>

using System;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Depra.Console.Development
{
[Serializable]
public sealed class GameObjectCommand : IDevelopmentCommand
{
[field: SerializeField] public string Alias { get; set; } = "gameobject";
[field: SerializeField] public string Usage { get; set; } = "gameobject 'gameobject-name' destroy|activate|deactivate|move|rotate [0.0,0.0,0.0]";
[field: SerializeField] public string Description { get; set; } = "Operations on GameObjects.";

bool IDevelopmentCommand.Execute(string[] args)
{
if (args.Length <= 1)
{
return false;
}

var name = args[0];
var command = args[1];

GameObject gameObject = null;
// @HACK: Active and inactive GameObjects.
var gameObjects = Resources.FindObjectsOfTypeAll<GameObject>();
for (var index = 0; index < gameObjects.Length && gameObject == null; ++index)
{
if (name.Equals(gameObjects[index].name.ToLower()))
{
gameObject = gameObjects[index];
}
}

if (gameObject != null)
{
switch (command)
{
case "destroy":
#if UNITY_EDITOR
Object.DestroyImmediate(gameObject, true);
#else
Object.Destroy(gameObject);
#endif
return true;

case "activate":
gameObject.SetActive(true);
return true;

case "deactivate":
gameObject.SetActive(false);
return true;

case "move":
if (args.Length == 3)
{
gameObject.transform.position = args[2].ToVector3();

return true;
}

break;

case "rotate":
if (args.Length == 3)
{
var euler = args[2].ToVector3();
gameObject.transform.Rotate(Vector3.right, euler.x);
gameObject.transform.Rotate(Vector3.up, euler.y);
gameObject.transform.Rotate(Vector3.forward, euler.z);

return true;
}

break;

default:
Debug.LogWarning($"'{command}' unrecognized.");
break;
}
}
else
{
Debug.LogWarning($"GameObject '{name}' not found.");
}

return false;
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Commands/GameObjectCommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions Runtime/Commands/IDevelopmentCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
// © 2025 Nikolay Melnikov <[email protected]>

namespace Depra.Console.Development
{
public interface IDevelopmentCommand
{
string Alias { get; set; }
string Usage { get; set; }
string Description { get; set; }

bool Execute(string[] args);
}
}
11 changes: 11 additions & 0 deletions Runtime/Commands/IDevelopmentCommand.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions Runtime/Commands/IDevelopmentCommands.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: Apache-2.0
// © 2025 Nikolay Melnikov <[email protected]>

using System.Collections.Generic;
using System.Runtime.CompilerServices;

namespace Depra.Console.Development
{
public interface IDevelopmentCommands
{
int Count { get; }
IDevelopmentCommand this[int index] { get; }

bool Contains(IDevelopmentCommand command);
void Add(IDevelopmentCommand command);
void Remove(IDevelopmentCommand command);
}

public static class DevelopmentCommandsExtensions
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddCommands(this IDevelopmentCommands self, IEnumerable<IDevelopmentCommand> commands)
{
foreach (var command in commands)
{
self.Add(command);
}
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void RemoveCommands(this IDevelopmentCommands self, IEnumerable<IDevelopmentCommand> commands)
{
foreach (var command in commands)
{
self.Remove(command);
}
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Commands/IDevelopmentCommands.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 332e559

Please sign in to comment.