Tweak post processing and debug console

- Tweak SSAO settings
- Add history browsing functionality to the console
- Add controls: "Previous Command" (up) and "Next Command" (down)
- Fix a bug in the console which prevented very long logs in the console
This commit is contained in:
excitedneon 2017-05-10 20:30:30 +03:00
parent 492502ef98
commit 9bb323ad07
4 changed files with 130 additions and 10 deletions

View File

@ -42,10 +42,10 @@ MonoBehaviour:
ambientOcclusion: ambientOcclusion:
m_Enabled: 1 m_Enabled: 1
m_Settings: m_Settings:
intensity: 0.65 intensity: 1
radius: 0.25 radius: 0.1
sampleCount: 10 sampleCount: 16
downsampling: 1 downsampling: 0
forceForwardCompatibility: 0 forceForwardCompatibility: 0
ambientOnly: 0 ambientOnly: 0
highPrecision: 0 highPrecision: 0

View File

@ -456,7 +456,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0} m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1} m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 1000} m_SizeDelta: {x: 0, y: 300}
m_Pivot: {x: 0.5, y: 0} m_Pivot: {x: 0.5, y: 0}
--- !u!114 &566501562 --- !u!114 &566501562
MonoBehaviour: MonoBehaviour:
@ -756,7 +756,7 @@ MonoBehaviour:
m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3} m_Script: {fileID: 1980459831, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_UiScaleMode: 0 m_UiScaleMode: 1
m_ReferencePixelsPerUnit: 100 m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1 m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600} m_ReferenceResolution: {x: 800, y: 600}
@ -1328,7 +1328,10 @@ MonoBehaviour:
Panel: {fileID: 2000206069} Panel: {fileID: 2000206069}
InputField: {fileID: 270758323} InputField: {fileID: 270758323}
TextField: {fileID: 1815899005} TextField: {fileID: 1815899005}
Visible: 0 Visible: 1
RowLength: 80
MaxLinesUntilCleanup: 30
LineCountSavedFromCleanup: 15
--- !u!4 &1463006272 --- !u!4 &1463006272
Transform: Transform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -1602,6 +1605,7 @@ MonoBehaviour:
ID: 0 ID: 0
Mesh: {fileID: 1229079791} Mesh: {fileID: 1229079791}
BlinkLength: 1 BlinkLength: 1
BlinkBrightness: 1.5
BlinkColor: {r: 1, g: 0.6, b: 0, a: 1} BlinkColor: {r: 1, g: 0.6, b: 0, a: 1}
--- !u!65 &1988211394 --- !u!65 &1988211394
BoxCollider: BoxCollider:

View File

@ -35,7 +35,27 @@ namespace Cyber.Console {
/// </summary> /// </summary>
public bool Visible = false; public bool Visible = false;
/// <summary>
/// The length of a row in the console in characters.
/// </summary>
public int RowLength = 80;
/// <summary>
/// The linecount threshold when the <see cref="TextField"/> is cleaned
/// up so it has <see cref="LineCountSavedFromCleanup"/> lines left.
/// </summary>
public int MaxLinesUntilCleanup = 48;
/// <summary>
/// See <see cref="MaxLinesUntilCleanup"/>.
/// </summary>
public int LineCountSavedFromCleanup = 24;
private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>(); private Dictionary<string, DebugConsoleAction> Actions = new Dictionary<string, DebugConsoleAction>();
private List<string> Lines = new List<string>();
private List<string> Commands = new List<string>();
private int LastCommandIndex = 0;
private string LastUnexecutedCommand = "";
/// <summary> /// <summary>
/// Creates a new <see cref="DebugConsole"/>, and sets the <see cref="Term"/>'s singleton. /// Creates a new <see cref="DebugConsole"/>, and sets the <see cref="Term"/>'s singleton.
@ -51,7 +71,11 @@ namespace Cyber.Console {
if (InputField.text.Length == 0) { if (InputField.text.Length == 0) {
return; return;
} }
// Log this command
Println(InputField.text); Println(InputField.text);
Commands.Add(InputField.text);
LastCommandIndex = Commands.Count;
List<string> Arguments = new List<string>(); List<string> Arguments = new List<string>();
MatchCollection Matches = CommandPartRegex.Matches(InputField.text + " "); MatchCollection Matches = CommandPartRegex.Matches(InputField.text + " ");
for (int i = 0; i < Matches.Count; i++) { for (int i = 0; i < Matches.Count; i++) {
@ -65,6 +89,8 @@ namespace Cyber.Console {
break; break;
} }
} }
// Clear the input field
InputField.text = ""; InputField.text = "";
InputField.ActivateInputField(); InputField.ActivateInputField();
} }
@ -93,12 +119,40 @@ namespace Cyber.Console {
} }
/// <summary> /// <summary>
/// Prints text into the Console. /// Prints text into the Console. Wraps text at <see cref="RowLength"/>.
/// </summary> /// </summary>
/// <remarks>
/// If the linecount exceeds <see cref="MaxLinesUntilCleanup"/>, the
/// console is cleared to the point that it only has
/// <see cref="LineCountSavedFromCleanup"/> lines.
/// </remarks>
/// <param name="text">Text.</param> /// <param name="text">Text.</param>
/// \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) { public void Print(string text) {
TextField.text += text;
// Wrap lines and log them to Lines
int Index = 0;
int EscapeIndex = 0;
do {
int NewLineIndex = text.IndexOf("\n", Index) + 1;
if (NewLineIndex == 0 || NewLineIndex > Index + RowLength) {
NewLineIndex = Index + Mathf.Min(text.Length - Index, RowLength);
}
string Line = text.Substring(Index, NewLineIndex - Index).Replace("\n", "");
Index = NewLineIndex;
Lines.Add(Line);
TextField.text += Line + "\n";
EscapeIndex++;
} while (Index < text.Length && EscapeIndex < 10);
if (Lines.Count > MaxLinesUntilCleanup) {
// The print history is too long, clear up until there are only
// a small amount left (so the user doesn't notice the cleanup)
string NewLog = "";
Lines.RemoveRange(0, Lines.Count - LineCountSavedFromCleanup);
foreach (string Line in Lines) {
NewLog += Line;
}
TextField.text = NewLog;
}
} }
private void Start() { private void Start() {
@ -135,6 +189,18 @@ namespace Cyber.Console {
AddCommand("shutdown", "Shuts the game down.", (args) => { AddCommand("shutdown", "Shuts the game down.", (args) => {
Application.Quit(); Application.Quit();
}); });
// Set an accurate row length (if the panel is set)
if (Panel != null && Panel.GetComponent<RectTransform>() != null) {
CharacterInfo CharInfo;
TextField.font.RequestCharactersInTexture("W", TextField.fontSize,
TextField.fontStyle);
TextField.font.GetCharacterInfo('W', out CharInfo,
TextField.fontSize, TextField.fontStyle);
float CharacterWidth = CharInfo.glyphWidth - 1;
float PanelWidth = Panel.GetComponent<RectTransform>().rect.width;
RowLength = (int) (PanelWidth / CharacterWidth);
}
} }
private void Update() { private void Update() {
@ -145,6 +211,24 @@ namespace Cyber.Console {
if (Input.GetButtonDown("Enter Command")) { if (Input.GetButtonDown("Enter Command")) {
CallCommand(); CallCommand();
} }
if (Input.GetButtonDown("Previous Command")) {
if (LastCommandIndex - 1 >= 0) {
if (LastCommandIndex == Commands.Count) {
// The last command is the last one that was executed
// Save the currently written command so it can be returned to
LastUnexecutedCommand = InputField.text;
}
InputField.text = Commands[--LastCommandIndex];
}
}
if (Input.GetButtonDown("Next Command")) {
if (LastCommandIndex + 1 < Commands.Count) {
InputField.text = Commands[++LastCommandIndex];
} else if (LastCommandIndex + 1 == Commands.Count) {
LastCommandIndex++;
InputField.text = LastUnexecutedCommand;
}
}
// Slide up/down animation // Slide up/down animation
RectTransform Rect = Panel.GetComponent<RectTransform>(); RectTransform Rect = Panel.GetComponent<RectTransform>();

View File

@ -133,6 +133,38 @@ InputManager:
type: 0 type: 0
axis: 0 axis: 0
joyNum: 0 joyNum: 0
- serializedVersion: 3
m_Name: Previous Command
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: up
altNegativeButton:
altPositiveButton:
gravity: 1000
dead: 0.001
sensitivity: 1000
snap: 0
invert: 0
type: 0
axis: 0
joyNum: 0
- serializedVersion: 3
m_Name: Next Command
descriptiveName:
descriptiveNegativeName:
negativeButton:
positiveButton: down
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: