Merge branch 'master' of https://github.com/Saltosion/Cyber into networking
This commit is contained in:
commit
aa73349f41
File diff suppressed because it is too large
Load Diff
2870
Assets/Scenes/backup
Normal file
2870
Assets/Scenes/backup
Normal file
File diff suppressed because it is too large
Load Diff
8
Assets/Scenes/backup.meta
Normal file
8
Assets/Scenes/backup.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: faf2baf6361bc0b4090624d03c960777
|
||||||
|
timeCreated: 1494202998
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
9
Assets/Scripts/Console.meta
Normal file
9
Assets/Scripts/Console.meta
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 60bfefc2063c5423a84c0c0d325f9757
|
||||||
|
folderAsset: yes
|
||||||
|
timeCreated: 1494199011
|
||||||
|
licenseType: Free
|
||||||
|
DefaultImporter:
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
120
Assets/Scripts/Console/DebugConsole.cs
Normal file
120
Assets/Scripts/Console/DebugConsole.cs
Normal file
@ -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<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>();
|
||||||
|
|
||||||
|
public void CallCommand() {
|
||||||
|
if (InputField.text.Length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Println(InputField.text);
|
||||||
|
List<string> Arguments = new List<string>();
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a command to be used in the console.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="command">The command template that should be used.
|
||||||
|
/// eg. "print (text)" or "add (number) (number)"</param>
|
||||||
|
/// <param name="description">Description.</param>
|
||||||
|
/// <param name="action">Action.</param>
|
||||||
|
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<RectTransform>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public class DebugConsoleAction {
|
public class DebugConsoleAction {
|
||||||
public delegate void Action(List<string> args);
|
public delegate void Action(List<string> command);
|
||||||
|
public readonly string Description;
|
||||||
|
|
||||||
private string Description;
|
|
||||||
private Action ActionFunc;
|
private Action ActionFunc;
|
||||||
|
|
||||||
public DebugConsoleAction(string description, Action actionFunc) {
|
public DebugConsoleAction(string description, Action actionFunc) {
|
||||||
@ -11,7 +11,7 @@ public class DebugConsoleAction {
|
|||||||
this.ActionFunc = actionFunc;
|
this.ActionFunc = actionFunc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Call(List<string> args) {
|
public void Call(List<string> command) {
|
||||||
ActionFunc(args);
|
ActionFunc(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
38
Assets/Scripts/Console/Term.cs
Normal file
38
Assets/Scripts/Console/Term.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// A class that has static functions for printing text in the DebugConsole.
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
12
Assets/Scripts/Console/Term.cs.meta
Normal file
12
Assets/Scripts/Console/Term.cs.meta
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 11a1769f2da944fa4bb3dd393335b39d
|
||||||
|
timeCreated: 1494199000
|
||||||
|
licenseType: Free
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
@ -1,18 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class DebugConsole : MonoBehaviour {
|
|
||||||
private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Adds a command to be used in the console.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="command">The command template that should be used.
|
|
||||||
/// eg. "print (text)" or "add (number) (number)"</param>
|
|
||||||
/// <param name="description">Description.</param>
|
|
||||||
/// <param name="action">Action.</param>
|
|
||||||
public void AddCommand(string command, string description, DebugConsoleAction.Action action) {
|
|
||||||
Actions[command] = new DebugConsoleAction(description, action);
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,11 +5,17 @@ using UnityEngine;
|
|||||||
public class PlayerController : MonoBehaviour {
|
public class PlayerController : MonoBehaviour {
|
||||||
public Character Character;
|
public Character Character;
|
||||||
|
|
||||||
void Update() {
|
private void Update() {
|
||||||
Vector3 Move = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
|
if (!Term.IsVisible()) {
|
||||||
if (Move.sqrMagnitude != 0) {
|
// Handle inputs
|
||||||
Character.Move(transform.TransformDirection(Move));
|
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()) {
|
} else if (Character.Moving()) {
|
||||||
|
// The debug console is open, stop the player.
|
||||||
Character.Stop();
|
Character.Stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class Spawner : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Update() {
|
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)));
|
Spawn(EntityType.NPC, new Vector3(Random.Range(-1f, 1f), 0, Random.Range(-2f, 2f)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,6 +101,22 @@ InputManager:
|
|||||||
type: 0
|
type: 0
|
||||||
axis: 0
|
axis: 0
|
||||||
joyNum: 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
|
- serializedVersion: 3
|
||||||
m_Name: Mouse X
|
m_Name: Mouse X
|
||||||
descriptiveName:
|
descriptiveName:
|
||||||
|
Loading…
Reference in New Issue
Block a user