-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
Base commit for Console
- Loading branch information
There are no files selected for viewing
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,45 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Console | ||
{ | ||
[AutoRegisterConsoleCommand] | ||
public class ExitCommand : IConsoleCommand | ||
{ | ||
public void Execute(string[] args) | ||
{ | ||
if (Application.isEditor) | ||
{ | ||
#if UNITY_EDITOR | ||
UnityEditor.EditorApplication.isPlaying = false; | ||
#endif | ||
} | ||
else | ||
Application.Quit(); | ||
|
||
} | ||
|
||
public string GetHelp() | ||
{ | ||
return @"usage: exit | ||
" + GetSummary(); | ||
} | ||
|
||
public string GetName() | ||
{ | ||
return "exit"; | ||
} | ||
|
||
public IEnumerable<Console.Alias> GetAliases() | ||
{ | ||
yield return Console.Alias.Get("quit", "exit"); | ||
} | ||
|
||
public string GetSummary() | ||
{ | ||
return "Exits the game"; | ||
} | ||
} | ||
|
||
} |
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,99 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Console | ||
{ | ||
[AutoRegisterConsoleCommand] | ||
public class PhysicsCommand : IConsoleCommand | ||
{ | ||
public void Execute(string[] args) | ||
{ | ||
int count = args.Length; | ||
if (count > 0) | ||
{ | ||
switch (args[0].ToLower()) | ||
{ | ||
case "simulation": | ||
if(count > 1) | ||
{ | ||
int steps; | ||
|
||
if(args[1].ToLower() == "auto") | ||
{ | ||
Physics.autoSimulation = true; | ||
Console.Log(GetName(), "Set simulation physics to Auto"); | ||
} | ||
else if (args[1].ToLower() == "off") | ||
{ | ||
Physics.autoSimulation = false; | ||
Console.Log(GetName(), "Set simulation physics to OFF"); | ||
} | ||
else if (int.TryParse(args[1], out steps)) | ||
{ | ||
Physics.defaultSolverIterations = steps; | ||
Console.Log(GetName(), string.Format("Set physics steps to {0}",steps)); | ||
} | ||
else | ||
{ | ||
Console.Log(GetName(), "Invalid simulation value : " + args[1], LogType.Error); | ||
Console.Log(GetName(), GetHelp()); | ||
} | ||
} | ||
else | ||
{ | ||
Console.Log(GetName(), string.Format("Simulation : {0}, {1} step(s)", | ||
Physics.autoSimulation ? "auto" : "manual", | ||
Physics.defaultSolverIterations | ||
)); | ||
} | ||
break; | ||
case "gravity": | ||
if(count == 1) | ||
{ | ||
Console.Log(GetName(), string.Format("Gravity Vector : {0}", Physics.gravity)); | ||
} | ||
else if (count == 4) | ||
{ | ||
float x, y, z; | ||
if(float.TryParse(args[1], out x) && float.TryParse(args[2], out y) && float.TryParse(args[3], out z)) | ||
{ | ||
Physics.gravity = new Vector3(x, y, z); | ||
Console.Log(GetName(), string.Format("Set Gravity Vector : {0}", Physics.gravity)); | ||
} | ||
} | ||
break; | ||
default: | ||
Console.Log(GetName(), string.Format("Invalid command : {0}", args[0]), LogType.Error); | ||
break; | ||
} | ||
} | ||
else | ||
Console.Log(GetName(), GetHelp()); | ||
} | ||
|
||
public string GetHelp() | ||
{ | ||
return @"usage: physics <i>command</i> | ||
* physics simulation (auto,off,intValue) : sets simulation | ||
* physics gravity (x)(y)(z): sets gravity vector | ||
"; | ||
} | ||
|
||
public string GetName() | ||
{ | ||
return "physics"; | ||
} | ||
|
||
public IEnumerable<Console.Alias> GetAliases() | ||
{ | ||
yield return Console.Alias.Get("gravity", "physics gravity"); | ||
} | ||
|
||
public string GetSummary() | ||
{ | ||
return "Performs physics debuging"; | ||
} | ||
} | ||
|
||
} |
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,103 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
namespace Console | ||
{ | ||
[AutoRegisterConsoleCommand] | ||
public class ScreenCommand : IConsoleCommand | ||
{ | ||
public void Execute(string[] args) | ||
{ | ||
if (args.Length == 0) | ||
Console.Log(GetHelp()); | ||
else | ||
{ | ||
switch(args[0].ToLower()) | ||
{ | ||
case "resolution": | ||
Resolution r = Screen.currentResolution; | ||
if (args.Length == 1) | ||
{ | ||
Console.Log(GetName(), string.Format("Current resolution is {0}x{1} at {2}Hz", Screen.width, Screen.height, r.refreshRate)); | ||
} | ||
else if(args.Length == 3) | ||
{ | ||
int width, height; | ||
if(int.TryParse(args[1], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out width) | ||
&& int.TryParse(args[2], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out height)) | ||
{ | ||
r.width = width; | ||
r.height = height; | ||
Screen.SetResolution(r.width,r.height,Screen.fullScreen, r.refreshRate); | ||
Console.Log(GetName(), string.Format("Setting resolution to {0}x{1} at {2}Hz", r.width, r.height, r.refreshRate)); | ||
} | ||
} | ||
else if(args.Length == 4) | ||
{ | ||
int width, height, rate; | ||
if (int.TryParse(args[1], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out width) | ||
&& int.TryParse(args[2], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out height) | ||
&& int.TryParse(args[3], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out rate)) | ||
{ | ||
r.width = width; | ||
r.height = height; | ||
r.refreshRate = rate; | ||
Screen.SetResolution(r.width, r.height, Screen.fullScreen, r.refreshRate); | ||
Console.Log(GetName(), string.Format("Setting resolution to {0}x{1} at {2}Hz", r.width, r.height, r.refreshRate)); | ||
} | ||
} | ||
break; | ||
case "fullscreen": | ||
bool fullscreen = Screen.fullScreen; | ||
if (args.Length == 1) | ||
{ | ||
Console.Log(Screen.fullScreen? "Running FullScreen" : "Running Windowed"); | ||
} | ||
else if (args.Length == 2) | ||
{ | ||
if (bool.TryParse(args[1], out fullscreen)) | ||
{ | ||
Screen.fullScreen = fullscreen; | ||
Console.Log(GetName(), "Setting screen to " + (fullscreen ? "fullscreen" : "windowed")); | ||
} | ||
} | ||
|
||
break; | ||
default: | ||
Console.Log(GetName(), "Unknown Command : " + args[0], LogType.Error); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public string GetHelp() | ||
{ | ||
return @"usage: screen <i>command</i> [params] | ||
read values | ||
* resolution | ||
* fullscreen | ||
store values | ||
* resolution <i>width</i> <i>height</i> [refreshrate] | ||
* fullscreen [true/false] | ||
"; | ||
} | ||
|
||
public IEnumerable<Console.Alias> GetAliases() | ||
{ | ||
yield return Console.Alias.Get("resolution", "screen resolution"); | ||
yield return Console.Alias.Get("fullscreen", "screen fullscreen"); | ||
} | ||
|
||
public string GetName() | ||
{ | ||
return "screen"; | ||
} | ||
|
||
public string GetSummary() | ||
{ | ||
return "Sets or gets various informations regarding screen"; | ||
} | ||
} | ||
|
||
} |
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,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
|
||
namespace Console | ||
{ | ||
[AutoRegisterConsoleCommand] | ||
public class ScreenshotCommand : IConsoleCommand | ||
{ | ||
public void Execute(string[] args) | ||
{ | ||
int size = 1; | ||
if(args.Length == 1) | ||
{ | ||
int.TryParse(args[0], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out size); | ||
size = Math.Min(size, 5); | ||
size = Math.Max(size, 1); | ||
} | ||
DateTime now = DateTime.Now; | ||
string datetime = string.Format("{0}{1}{2}-{3}{4}{5}",now.Year, now.Month, now.Day, now.Hour,now.Minute,now.Second); | ||
string filename = string.Format("Unity-{0}-{1}-{2}.png", Application.productName, SceneManager.GetActiveScene().name, datetime); | ||
Console.Log(GetName(), string.Format("Taking Screenshot at {0}x resolution : {1}",size, filename)); | ||
ScreenCapture.CaptureScreenshot(filename,1); | ||
} | ||
|
||
public string GetHelp() | ||
{ | ||
return @"usage: screenshot [supersize 1~5]"; | ||
} | ||
|
||
public string GetName() | ||
{ | ||
return "screenshot"; | ||
} | ||
|
||
public IEnumerable<Console.Alias> GetAliases() | ||
{ | ||
return null; | ||
} | ||
|
||
public string GetSummary() | ||
{ | ||
return "Takes a screenshot"; | ||
} | ||
} | ||
|
||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.