-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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; | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.