Added basic CogwheelConsoleUI and implementation

This commit is contained in:
Spudnut2000 2024-10-02 22:48:21 -05:00
parent 86e8b2168c
commit ef73de5a86
242 changed files with 25684 additions and 5194 deletions

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/.." vcs="Git" />
</component>
</project>

View File

@ -45,13 +45,17 @@
<Analyzer Include="/home/spudnut/Unity/Hub/Editor/2022.3.36f1/Editor/Data/Tools/Unity.SourceGenerators/Unity.Properties.SourceGenerator.dll" /> <Analyzer Include="/home/spudnut/Unity/Hub/Editor/2022.3.36f1/Editor/Data/Tools/Unity.SourceGenerators/Unity.Properties.SourceGenerator.dll" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Assets/Cogwheel/Scripts/Test.cs" />
<Compile Include="Assets/Cogwheel/Scripts/CommandAttribute.cs" /> <Compile Include="Assets/Cogwheel/Scripts/CommandAttribute.cs" />
<Compile Include="Assets/Cogwheel/Scripts/Command.cs" /> <Compile Include="Assets/Cogwheel/Scripts/Command.cs" />
<Compile Include="Assets/Cogwheel/Scripts/ICommandsManager.cs" /> <Compile Include="Assets/Cogwheel/Scripts/ICommandsManager.cs" />
<Compile Include="Assets/Cogwheel/Scripts/COGWHEEL.cs" /> <Compile Include="Assets/Cogwheel/Scripts/COGWHEEL.cs" />
<Compile Include="Assets/Cogwheel/Test.cs" />
<Compile Include="Assets/Cogwheel/Scripts/CommandsManager.cs" /> <Compile Include="Assets/Cogwheel/Scripts/CommandsManager.cs" />
<Compile Include="Assets/Cogwheel/Scripts/CogwheelSettings.cs" />
<Compile Include="Assets/Cogwheel/UI/CogwheelConsole.cs" />
<Compile Include="Assets/Cogwheel/Scripts/ICommand.cs" /> <Compile Include="Assets/Cogwheel/Scripts/ICommand.cs" />
<None Include="Assets/Cogwheel/UI/CogwheelConsoleUI.uxml" />
<None Include="Assets/Cogwheel/UI/CogwheelConsole.uss" />
<Reference Include="UnityEngine"> <Reference Include="UnityEngine">
<HintPath>/home/spudnut/Unity/Hub/Editor/2022.3.36f1/Editor/Data/Managed/UnityEngine/UnityEngine.dll</HintPath> <HintPath>/home/spudnut/Unity/Hub/Editor/2022.3.36f1/Editor/Data/Managed/UnityEngine/UnityEngine.dll</HintPath>
</Reference> </Reference>

View File

@ -1,12 +1,85 @@
using OpenCover.Framework.Model;
using UnityEngine;
namespace Cogwheel namespace Cogwheel
{ {
public static class COGWHEEL public static class COGWHEEL
{ {
public static ICommandsManager CommandsManager { get; } public static ICommandsManager CommandsManager { get; }
public static CogwheelSettings Settings { get; }
public static CogwheelConsole Console { get; private set; }
static COGWHEEL() static COGWHEEL()
{ {
CommandsManager = new CommandsManager(); CommandsManager = new CommandsManager();
CommandsManager.GetCommands();
Settings = Resources.Load<CogwheelSettings>("CogwheelSettings");
if (Settings is null)
{
Debug.LogError("CogwheelSettings not found. Make sure you have a CogwheelSettings asset in a Resources folder.");
return;
} }
Console = GameObject.Instantiate(Settings.CogwheelConsolePrefab).GetComponent<CogwheelConsole>();
}
#region BUILT-IN COMMANDS
[Command(Description = "Logs a message to the console.")]
public static void Log(string message)
{
Console.Log(message);
}
[Command(Description = "Logs an error message to the console.")]
public static void LogError(string message)
{
Console.LogError(message);
}
[Command(Description = "Clears the console.")]
public static void Clear()
{
Console.Clear();
}
[Command(Description = "Lists all available commands.")]
public static void Help()
{
foreach (var command in CommandsManager.Commands.Values)
{
if (command.Method.IsStatic)
{
Console.Log($"{command.Name} - {command.Description}");
}
else
{
if (CommandsManager.SceneContext is not null)
{
foreach (var behaviour in CommandsManager.SceneContext.GetComponents<MonoBehaviour>())
{
if (behaviour.GetType() == command.Method.DeclaringType)
{
Console.Log($"<color=green>({command.Method.DeclaringType.Name})</color> : {command.Name} - {command.Description}");
}
else
{
Console.Log($"<color=red>({command.Method.DeclaringType.Name})</color> : {command.Name} - {command.Description}");
}
}
}
else
{
Console.Log($"<color=red>({command.Method.DeclaringType.Name})</color> : {command.Name} - {command.Description}");
}
}
//Console.Log($"<color=green>({command.Method.DeclaringType.Name})</color> : {command.Name} - {command.Description}");
}
}
#endregion
} }
} }

View File

@ -0,0 +1,10 @@
using UnityEngine;
namespace Cogwheel
{
[CreateAssetMenu(fileName = "CogwheelSettings", menuName = "Cogwheel/CogwheelSettings", order = 0)]
public class CogwheelSettings : ScriptableObject
{
public CogwheelConsole CogwheelConsolePrefab;
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 53d39a5b2f874ce2b49327a3ec509eba
timeCreated: 1727924347

View File

@ -1,34 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Cogwheel;
using UnityEngine;
public class Test : MonoBehaviour
{
private void Start()
{
COGWHEEL.CommandsManager.GetCommands();
string commands = "";
foreach (var command in COGWHEEL.CommandsManager.Commands)
{
commands += command.Key + " | ";
}
Debug.Log(commands);
COGWHEEL.CommandsManager.SceneContext = gameObject;
COGWHEEL.CommandsManager.RunCommand("private 10 WHAT 100.5");
}
[Command(Description = "This is a test command")]
public static void TestMethod()
{
Debug.Log("TestMethod called");
}
[Command(CommandName = "private", Description = "This is a private command")]
private void PrivateCommand(int value, string text, float f)
{
Debug.Log($"PrivateCommand called: int is {value} and string is {text} and float is {f}");
}
}

View File

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using Cogwheel;
using UnityEngine;
public class Test : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Debug.Log(COGWHEEL.Settings.CogwheelConsolePrefab.name);
//COGWHEEL.CommandsManager.SceneContext = gameObject;
}
[Command(Description = "Test command.")]
private void TestCommand()
{
}
}

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 5f2dd85165475cf7a81bf4b02e9502f4 guid: 4a61e49036c312c83a47481446b0c01a
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c518ec6d6afdadbbf994a9fd6f78626c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,52 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Cogwheel;
using UnityEngine;
using UnityEngine.UIElements;
public class CogwheelConsole : MonoBehaviour
{
[SerializeField] private UIDocument uiDocument;
private VisualElement _consoleRoot;
private TextField _inputField;
private Label _outputLabel;
private void Start()
{
_consoleRoot = uiDocument.rootVisualElement;
_inputField = _consoleRoot.Q<TextField>("InputTextField");
_outputLabel = _consoleRoot.Q<Label>("ConsoleOutputLabel");
}
private void Update()
{
//if input field has focus and enter key is pressed
if (_inputField.panel.focusController.focusedElement == _inputField && Input.GetKeyDown(KeyCode.Return))
{
SubmitInput();
}
}
private void SubmitInput()
{
Log("> " + "<color=#555555><i>" + _inputField.value + "</i></color>");
var success = COGWHEEL.CommandsManager.RunCommand(_inputField.value);
}
public void Log(string message)
{
_outputLabel.text += message + "\n";
}
public void LogError(string message)
{
Log($"<color=red>{message}</color>");
}
public void Clear()
{
_outputLabel.text = "";
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8d41780c905fa36369633b75d47716d1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,64 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &1524229190056341568
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 7916664963331027706}
- component: {fileID: 3249832428090382412}
- component: {fileID: 9161624000669002432}
m_Layer: 0
m_Name: CogwheelConsole
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &7916664963331027706
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1524229190056341568}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 6.010771, y: 13.350267, z: 7.386556}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &3249832428090382412
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1524229190056341568}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 19102, guid: 0000000000000000e000000000000000, type: 0}
m_Name:
m_EditorClassIdentifier:
m_PanelSettings: {fileID: 11400000, guid: 110ff6e6352a3eb47ba7c89b45b7e81f, type: 2}
m_ParentUI: {fileID: 0}
sourceAsset: {fileID: 9197481963319205126, guid: 138eaa786512d37a2a5109ce71f5b46f, type: 3}
m_SortingOrder: 0
--- !u!114 &9161624000669002432
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1524229190056341568}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 8d41780c905fa36369633b75d47716d1, type: 3}
m_Name:
m_EditorClassIdentifier:
uiDocument: {fileID: 3249832428090382412}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 711d6fd55c44569cd91d159dcc393ac8
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,26 @@
#CogwheelConsoleRoot {
}
#ConsolePanel {
background-color: rgba(0, 0, 0, 0.9);
color: white;
padding: 1%;
}
#InputTextField {
margin: 0;
}
#InputTextField #unity-text-input {
background-color: rgba(0, 0, 0, 0.9);
color: white;
border-width: 1px;
padding: 0.5%;
margin: 0;
width: 100%;
}
#InputTextField Label{
display: none;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7724294777a80289a26a34dab7ad5c6
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12385, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

View File

@ -0,0 +1,38 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
m_Name: CogwheelConsolePanelSettings
m_EditorClassIdentifier:
themeUss: {fileID: -4733365628477956816, guid: 12eb8b4471de268a79c7e10c21bf4c2e, type: 3}
m_TargetTexture: {fileID: 0}
m_ScaleMode: 1
m_ReferenceSpritePixelsPerUnit: 100
m_Scale: 1
m_ReferenceDpi: 96
m_FallbackDpi: 96
m_ReferenceResolution: {x: 1200, y: 800}
m_ScreenMatchMode: 0
m_Match: 0
m_SortingOrder: 0
m_TargetDisplay: 0
m_ClearDepthStencil: 1
m_ClearColor: 0
m_ColorClearValue: {r: 0, g: 0, b: 0, a: 0}
m_DynamicAtlasSettings:
m_MinAtlasSize: 64
m_MaxAtlasSize: 4096
m_MaxSubTextureSize: 64
m_ActiveFilters: -1
m_AtlasBlitShader: {fileID: 9101, guid: 0000000000000000f000000000000000, type: 0}
m_RuntimeShader: {fileID: 9100, guid: 0000000000000000f000000000000000, type: 0}
m_RuntimeWorldShader: {fileID: 9102, guid: 0000000000000000f000000000000000, type: 0}
textSettings: {fileID: 0}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 110ff6e6352a3eb47ba7c89b45b7e81f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="False">
<Style src="project://database/Assets/Cogwheel/UI/CogwheelConsole.uss?fileID=7433441132597879392&amp;guid=a7724294777a80289a26a34dab7ad5c6&amp;type=3#CogwheelConsole" />
<ui:VisualElement name="CogwheelConsoleRoot" style="flex-grow: 1;">
<ui:VisualElement name="ConsolePanel" style="flex-grow: 1;">
<ui:ScrollView>
<ui:Label tabindex="-1" parse-escape-sequences="true" display-tooltip-when-elided="true" name="ConsoleOutputLabel" focusable="true" />
</ui:ScrollView>
</ui:VisualElement>
<ui:TextField picking-mode="Ignore" value="Command" name="InputTextField" />
</ui:VisualElement>
</ui:UXML>

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 138eaa786512d37a2a5109ce71f5b46f
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 216198494b1477d07ba31f9000f3c8fe
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 53d39a5b2f874ce2b49327a3ec509eba, type: 3}
m_Name: CogwheelSettings
m_EditorClassIdentifier:
CogwheelConsolePrefab: {fileID: 9161624000669002432, guid: 711d6fd55c44569cd91d159dcc393ac8, type: 3}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 024fb960bdc117e298a97c5be040fb57
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -227,6 +227,7 @@ GameObject:
- component: {fileID: 963194228} - component: {fileID: 963194228}
- component: {fileID: 963194227} - component: {fileID: 963194227}
- component: {fileID: 963194226} - component: {fileID: 963194226}
- component: {fileID: 963194229}
m_Layer: 0 m_Layer: 0
m_Name: Main Camera m_Name: Main Camera
m_TagString: MainCamera m_TagString: MainCamera
@ -308,54 +309,21 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1759035993 --- !u!114 &963194229
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1759035995}
- component: {fileID: 1759035994}
m_Layer: 0
m_Name: GameObject
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1759035994
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1759035993} m_GameObject: {fileID: 963194225}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f2dd85165475cf7a81bf4b02e9502f4, type: 3} m_Script: {fileID: 11500000, guid: 4a61e49036c312c83a47481446b0c01a, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
--- !u!4 &1759035995
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1759035993}
serializedVersion: 2
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1660057539 &9223372036854775807 --- !u!1660057539 &9223372036854775807
SceneRoots: SceneRoots:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_Roots: m_Roots:
- {fileID: 963194228} - {fileID: 963194228}
- {fileID: 705507995} - {fileID: 705507995}
- {fileID: 1759035995}

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7c8e63dd709e88e8eb592b34e41bb4f8
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0b00155eccd085c2c90729bf12f61892
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1 @@
@import url("unity-theme://default");

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 12eb8b4471de268a79c7e10c21bf4c2e
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 12388, guid: 0000000000000000e000000000000000, type: 0}
disableValidation: 0

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=7020124F_002D9FFC_002D4AC3_002D8F3D_002DAAB8E0240759_002Ff_003ATextField_002Ecs_002Fl_003A_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003F_002E_002E_003Fhome_003Fspudnut_003F_002Econfig_003FJetBrains_003FRider2024_002E2_003Fresharper_002Dhost_003FDecompilerCache_003Fdecompiler_003F0573bd80495f428abbe796964d4fd509178400_003F21_003F331cf713_003FTextField_002Ecs/@EntryIndexedValue">ForceIncluded</s:String></wpf:ResourceDictionary>

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More