From 5a54050742a5b454909b8ef4dfe10ae895c82144 Mon Sep 17 00:00:00 2001 From: excitedneon Date: Mon, 8 May 2017 02:29:12 +0300 Subject: [PATCH] Implemented the DebugConsole and added a global version, Term. --- Assets/Scenes/TestMap.unity | 386 +++++++++++++++++- Assets/Scripts/Console.meta | 9 + Assets/Scripts/Console/DebugConsole.cs | 120 ++++++ .../{ => Console}/DebugConsole.cs.meta | 0 .../{ => Console}/DebugConsoleAction.cs | 8 +- .../{ => Console}/DebugConsoleAction.cs.meta | 0 Assets/Scripts/Console/Term.cs | 38 ++ Assets/Scripts/Console/Term.cs.meta | 12 + Assets/Scripts/DebugConsole.cs | 18 - Assets/Scripts/PlayerController.cs | 14 +- Assets/Scripts/Spawner.cs | 2 +- ProjectSettings/InputManager.asset | 16 + 12 files changed, 590 insertions(+), 33 deletions(-) create mode 100644 Assets/Scripts/Console.meta create mode 100644 Assets/Scripts/Console/DebugConsole.cs rename Assets/Scripts/{ => Console}/DebugConsole.cs.meta (100%) rename Assets/Scripts/{ => Console}/DebugConsoleAction.cs (61%) rename Assets/Scripts/{ => Console}/DebugConsoleAction.cs.meta (100%) create mode 100644 Assets/Scripts/Console/Term.cs create mode 100644 Assets/Scripts/Console/Term.cs.meta delete mode 100644 Assets/Scripts/DebugConsole.cs diff --git a/Assets/Scenes/TestMap.unity b/Assets/Scenes/TestMap.unity index c123430..fd78733 100644 --- a/Assets/Scenes/TestMap.unity +++ b/Assets/Scenes/TestMap.unity @@ -108,6 +108,225 @@ NavMeshSettings: tileSize: 256 accuratePlacement: 0 m_NavMeshData: {fileID: 0} +--- !u!1 &270758321 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 270758322} + - component: {fileID: 270758325} + - component: {fileID: 270758324} + - component: {fileID: 270758323} + m_Layer: 5 + m_Name: InputField + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &270758322 +RectTransform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 270758321} + 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_Children: + - {fileID: 792995700} + - {fileID: 396674781} + m_Father: {fileID: 566501561} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 0} + m_AnchoredPosition: {x: 0, y: 25} + m_SizeDelta: {x: -20, y: 28} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &270758323 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 270758321} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 575553740, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 0.9098039, g: 0.9098039, b: 0.9098039, a: 1} + m_HighlightedColor: {r: 0.9098039, g: 0.9098039, b: 0.9098039, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 270758324} + m_TextComponent: {fileID: 396674782} + m_Placeholder: {fileID: 792995701} + m_ContentType: 0 + m_InputType: 0 + m_AsteriskChar: 42 + m_KeyboardType: 0 + m_LineType: 0 + m_HideMobileInput: 0 + m_CharacterValidation: 0 + m_CharacterLimit: 0 + m_OnEndEdit: + m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 1463006271} + m_MethodName: CallCommand + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + m_TypeName: UnityEngine.UI.InputField+SubmitEvent, UnityEngine.UI, Version=1.0.0.0, + Culture=neutral, PublicKeyToken=null + m_OnValueChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.InputField+OnChangeEvent, UnityEngine.UI, Version=1.0.0.0, + Culture=neutral, PublicKeyToken=null + m_CaretColor: {r: 0.9098039, g: 0.9098039, b: 0.9098039, a: 1} + m_CustomCaretColor: 1 + m_SelectionColor: {r: 1, g: 1, b: 1, a: 0.141} + m_Text: + m_CaretBlinkRate: 1.25 + m_CaretWidth: 3 + m_ReadOnly: 0 +--- !u!114 &270758324 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 270758321} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 0} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_Sprite: {fileID: 10911, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 +--- !u!222 &270758325 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 270758321} +--- !u!1 &396674780 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 396674781} + - component: {fileID: 396674783} + - component: {fileID: 396674782} + m_Layer: 5 + m_Name: Text + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &396674781 +RectTransform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 396674780} + 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_Children: [] + m_Father: {fileID: 270758322} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &396674782 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 396674780} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.9098039, g: 0.9098039, b: 0.9098039, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_FontData: + m_Font: {fileID: 12800000, guid: 2073ef28104464427b1884c25180485b, type: 3} + m_FontSize: 28 + m_FontStyle: 0 + m_BestFit: 0 + m_MinSize: 2 + m_MaxSize: 40 + m_Alignment: 6 + m_AlignByGeometry: 0 + m_RichText: 0 + m_HorizontalOverflow: 1 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: +--- !u!222 &396674783 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 396674780} --- !u!1 &566501560 GameObject: m_ObjectHideFlags: 0 @@ -131,18 +350,19 @@ RectTransform: m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 566501560} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + 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_Children: - {fileID: 1815899004} - m_Father: {fileID: 822377732} + - {fileID: 270758322} + m_Father: {fileID: 2000206070} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0.5} + m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: 0, y: 0} + m_SizeDelta: {x: 854, y: 1000} m_Pivot: {x: 0.5, y: 0} --- !u!114 &566501562 MonoBehaviour: @@ -221,6 +441,80 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 3 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &792995699 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 792995700} + - component: {fileID: 792995702} + - component: {fileID: 792995701} + m_Layer: 5 + m_Name: Placeholder + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &792995700 +RectTransform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 792995699} + 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_Children: [] + m_Father: {fileID: 270758322} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: -0.5} + m_SizeDelta: {x: -20, y: -13} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &792995701 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 792995699} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 708705254, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0.9098039, g: 0.9098039, b: 0.9098039, a: 0.3529412} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_FontData: + m_Font: {fileID: 12800000, guid: 2073ef28104464427b1884c25180485b, type: 3} + m_FontSize: 20 + m_FontStyle: 2 + m_BestFit: 0 + m_MinSize: 2 + m_MaxSize: 40 + m_Alignment: 0 + m_AlignByGeometry: 0 + m_RichText: 1 + m_HorizontalOverflow: 0 + m_VerticalOverflow: 0 + m_LineSpacing: 1 + m_Text: +--- !u!222 &792995702 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 792995699} --- !u!1 &822377728 GameObject: m_ObjectHideFlags: 0 @@ -306,7 +600,7 @@ RectTransform: m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0} m_Children: - - {fileID: 566501561} + - {fileID: 2000206070} m_Father: {fileID: 0} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -758,6 +1052,50 @@ Transform: m_Father: {fileID: 949094013} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &1463006270 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 1463006272} + - component: {fileID: 1463006271} + m_Layer: 0 + m_Name: DebugConsole + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1463006271 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1463006270} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f48658c47755046fc9ea156fe103aace, type: 3} + m_Name: + m_EditorClassIdentifier: + Panel: {fileID: 2000206069} + InputField: {fileID: 270758323} + TextField: {fileID: 1815899005} + DebugConsoleInUse: 0 +--- !u!4 &1463006272 +Transform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 1463006270} + 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_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1810916631 GameObject: m_ObjectHideFlags: 0 @@ -890,10 +1228,46 @@ MonoBehaviour: m_HorizontalOverflow: 0 m_VerticalOverflow: 0 m_LineSpacing: 1 - m_Text: Hello, world! + m_Text: 'Use the "help" command for a list of commands. + +' --- !u!222 &1815899006 CanvasRenderer: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_GameObject: {fileID: 1815899003} +--- !u!1 &2000206069 +GameObject: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + serializedVersion: 5 + m_Component: + - component: {fileID: 2000206070} + m_Layer: 5 + m_Name: DebugConsoleRoot + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2000206070 +RectTransform: + m_ObjectHideFlags: 0 + m_PrefabParentObject: {fileID: 0} + m_PrefabInternal: {fileID: 0} + m_GameObject: {fileID: 2000206069} + 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_Children: + - {fileID: 566501561} + m_Father: {fileID: 822377732} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 1} + m_AnchoredPosition: {x: 0, y: 500} + m_SizeDelta: {x: 100, y: -1000} + m_Pivot: {x: 0.5, y: 0.5} diff --git a/Assets/Scripts/Console.meta b/Assets/Scripts/Console.meta new file mode 100644 index 0000000..4ce0852 --- /dev/null +++ b/Assets/Scripts/Console.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: 60bfefc2063c5423a84c0c0d325f9757 +folderAsset: yes +timeCreated: 1494199011 +licenseType: Free +DefaultImporter: + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Console/DebugConsole.cs b/Assets/Scripts/Console/DebugConsole.cs new file mode 100644 index 0000000..5929f10 --- /dev/null +++ b/Assets/Scripts/Console/DebugConsole.cs @@ -0,0 +1,120 @@ +using System.Collections; +using System.Collections.Generic; +using System.Text.RegularExpressions; +using UnityEngine; +using UnityEngine.UI; + +public class DebugConsole : MonoBehaviour { + private static readonly Regex CommandPartRegex = new Regex("([^ \"]+ )|(\"[^\"]+\")"); + + public GameObject Panel; + public InputField InputField; + public Text TextField; + public bool Visible = false; + + private Dictionary Actions = new Dictionary(); + + public void CallCommand() { + if (InputField.text.Length == 0) { + return; + } + Println(InputField.text); + List Arguments = new List(); + MatchCollection Matches = CommandPartRegex.Matches(InputField.text + " "); + for (int i = 0; i < Matches.Count; i++) { + Arguments.Add(Matches[i].Value.Replace('"', ' ').Trim()); + } + foreach (string Action in Actions.Keys) { + string[] Parts = Action.Split(' '); + if (Arguments.Count == Parts.Length && Arguments[0].Equals(Parts[0])) { + Arguments.RemoveAt(0); + Actions[Action].Call(Arguments); + break; + } + } + InputField.text = ""; + InputField.ActivateInputField(); + } + + /// + /// Adds a command to be used in the console. + /// + /// The command template that should be used. + /// eg. "print (text)" or "add (number) (number)" + /// Description. + /// Action. + public void AddCommand(string command, string description, DebugConsoleAction.Action action) { + string PrettyDescription = command; + foreach (string Line in description.Split('\n')) { + PrettyDescription += "\n " + Line; + } + Actions[command] = new DebugConsoleAction(PrettyDescription, action); + } + + public void Println(string text) { + Print(text + "\n"); + } + + // TODO: Handle removing history when it gets very long. Very long console logs might cause problems when displaying new prints. + public void Print(string text) { + TextField.text += text; + } + + private void Start() { + AddCommand("help", "Lists all commands.", (args) => { + Println("Commands:"); + foreach (string Action in Actions.Keys) { + Println("- " + Action); + } + }); + + AddCommand("help (command)", "Describes the given command.", (args) => { + // Check complete versions of the names (so you can do eg. help "help (command)") + foreach (string Action in Actions.Keys) { + if (Action.Equals(args[0])) { + Println(Actions[Action].Description); + return; + } + } + // Check just names + foreach (string Action in Actions.Keys) { + string[] Parts = Action.Split(' '); + if (Parts[0].Equals(args[0])) { + Println(Actions[Action].Description); + return; + } + } + Println("That command doesn't exist."); + }); + + AddCommand("print (text)", "Prints the given text.", (args) => { + Println(args[0]); + }); + + Term.SetDebugConsole(this); + } + + private void Update() { + if (Input.GetButtonDown("Console Toggle")) { + Visible = !Visible; + } + RectTransform Rect = Panel.GetComponent(); + Vector2 OffsetMin = Rect.offsetMin; + if (Visible) { + if (OffsetMin.y > 1) { + OffsetMin.y = Mathf.Lerp(OffsetMin.y, 0, 5f * Time.deltaTime); + } + if (!InputField.isFocused) { + InputField.ActivateInputField(); + } + } else { + if (1000 - OffsetMin.y > 1) { + OffsetMin.y = Mathf.Lerp(OffsetMin.y, 1000, 1f * Time.deltaTime); + } + if (InputField.isFocused) { + InputField.DeactivateInputField(); + } + } + Rect.offsetMin = OffsetMin; + } +} diff --git a/Assets/Scripts/DebugConsole.cs.meta b/Assets/Scripts/Console/DebugConsole.cs.meta similarity index 100% rename from Assets/Scripts/DebugConsole.cs.meta rename to Assets/Scripts/Console/DebugConsole.cs.meta diff --git a/Assets/Scripts/DebugConsoleAction.cs b/Assets/Scripts/Console/DebugConsoleAction.cs similarity index 61% rename from Assets/Scripts/DebugConsoleAction.cs rename to Assets/Scripts/Console/DebugConsoleAction.cs index 32224be..effa0ff 100644 --- a/Assets/Scripts/DebugConsoleAction.cs +++ b/Assets/Scripts/Console/DebugConsoleAction.cs @@ -1,9 +1,9 @@ using System.Collections.Generic; public class DebugConsoleAction { - public delegate void Action(List args); + public delegate void Action(List command); + public readonly string Description; - private string Description; private Action ActionFunc; public DebugConsoleAction(string description, Action actionFunc) { @@ -11,7 +11,7 @@ public class DebugConsoleAction { this.ActionFunc = actionFunc; } - public void Call(List args) { - ActionFunc(args); + public void Call(List command) { + ActionFunc(command); } } diff --git a/Assets/Scripts/DebugConsoleAction.cs.meta b/Assets/Scripts/Console/DebugConsoleAction.cs.meta similarity index 100% rename from Assets/Scripts/DebugConsoleAction.cs.meta rename to Assets/Scripts/Console/DebugConsoleAction.cs.meta diff --git a/Assets/Scripts/Console/Term.cs b/Assets/Scripts/Console/Term.cs new file mode 100644 index 0000000..361c4a8 --- /dev/null +++ b/Assets/Scripts/Console/Term.cs @@ -0,0 +1,38 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +/// +/// A class that has static functions for printing text in the DebugConsole. +/// +public class Term { + private static DebugConsole Console; + + public static void SetDebugConsole(DebugConsole console) { + Console = console; + } + + public static bool IsVisible() { + if (Console == null) { + return false; + } else { + return Console.Visible; + } + } + + public static void Println(string text) { + if (Console == null) { + Debug.Log(text); + } else { + Console.Println(text); + } + } + + public static void Print(string text) { + if (Console == null) { + Debug.Log(text); + } else { + Console.Print(text); + } + } +} diff --git a/Assets/Scripts/Console/Term.cs.meta b/Assets/Scripts/Console/Term.cs.meta new file mode 100644 index 0000000..f9d6dc6 --- /dev/null +++ b/Assets/Scripts/Console/Term.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 11a1769f2da944fa4bb3dd393335b39d +timeCreated: 1494199000 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/DebugConsole.cs b/Assets/Scripts/DebugConsole.cs deleted file mode 100644 index 1703c08..0000000 --- a/Assets/Scripts/DebugConsole.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -public class DebugConsole : MonoBehaviour { - private Dictionary Actions = new Dictionary(); - - /// - /// Adds a command to be used in the console. - /// - /// The command template that should be used. - /// eg. "print (text)" or "add (number) (number)" - /// Description. - /// Action. - public void AddCommand(string command, string description, DebugConsoleAction.Action action) { - Actions[command] = new DebugConsoleAction(description, action); - } -} diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index a9883ec..b801513 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -5,11 +5,17 @@ using UnityEngine; public class PlayerController : MonoBehaviour { public Character Character; - void Update() { - Vector3 Move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); - if (Move.sqrMagnitude != 0) { - Character.Move(transform.TransformDirection(Move)); + private void Update() { + if (!Term.IsVisible()) { + // Handle inputs + Vector3 Move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); + if (Move.sqrMagnitude != 0) { + Character.Move(transform.TransformDirection(Move)); + } else if (Character.Moving()) { + Character.Stop(); + } } else if (Character.Moving()) { + // The debug console is open, stop the player. Character.Stop(); } } diff --git a/Assets/Scripts/Spawner.cs b/Assets/Scripts/Spawner.cs index bddfcb7..c88578e 100644 --- a/Assets/Scripts/Spawner.cs +++ b/Assets/Scripts/Spawner.cs @@ -41,7 +41,7 @@ public class Spawner : MonoBehaviour { } private void Update() { - if (Input.GetButtonDown("Jump")) { + if (Input.GetButtonDown("Jump") && !Term.IsVisible()) { Spawn(EntityType.NPC, new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-2f, 2f))); } } diff --git a/ProjectSettings/InputManager.asset b/ProjectSettings/InputManager.asset index ffa8b9b..415c823 100644 --- a/ProjectSettings/InputManager.asset +++ b/ProjectSettings/InputManager.asset @@ -101,6 +101,22 @@ InputManager: type: 0 axis: 0 joyNum: 0 + - serializedVersion: 3 + m_Name: Console Toggle + descriptiveName: + descriptiveNegativeName: + negativeButton: + positiveButton: tab + altNegativeButton: + altPositiveButton: + gravity: 1000 + dead: 0.001 + sensitivity: 1000 + snap: 0 + invert: 0 + type: 0 + axis: 0 + joyNum: 0 - serializedVersion: 3 m_Name: Mouse X descriptiveName: