console.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Rendering.PostProcessing;
  6. using UnityEngine.UI;
  7. public class console : MonoBehaviour
  8. {
  9. public GameObject UIObj;
  10. public InputField consoleInput;
  11. public Text consoleOutput;
  12. public PostProcessVolume pp;
  13. public Camera playerCam;
  14. //PostProcessingStuff
  15. Bloom bloom;
  16. AutoExposure exposure;
  17. AmbientOcclusion occlusion;
  18. void Start()
  19. {
  20. pp.profile.TryGetSettings(out bloom);
  21. pp.profile.TryGetSettings(out exposure);
  22. pp.profile.TryGetSettings(out occlusion);
  23. }
  24. // Update is called once per frame
  25. void Update()
  26. {
  27. if (Input.GetKeyDown(KeyCode.BackQuote))
  28. {
  29. bool isActive = !UIObj.activeSelf;
  30. UIObj.SetActive(isActive);
  31. consoleInput.interactable = isActive;
  32. if (isActive) consoleInput.Select();
  33. }
  34. if (Input.GetKeyDown(KeyCode.Return))
  35. {
  36. OnConsoleSubmit();
  37. }
  38. }
  39. public void OnConsoleInput(string text)
  40. {
  41. //Debug.Log(text);
  42. }
  43. public void OnConsoleSubmit()
  44. {
  45. string input = consoleInput.text.ToLower();
  46. char[] splitChars = { ' ' };
  47. string[] inputs = input.Split(splitChars, System.StringSplitOptions.RemoveEmptyEntries );
  48. try
  49. {
  50. switch (inputs[0])
  51. {
  52. case "set":
  53. switch (inputs[1])
  54. {
  55. case "fov":
  56. Camera.main.fieldOfView = int.Parse(inputs[2]);
  57. println($"<color=yellow>Done, cam fov : {Camera.main.fieldOfView}</color>");
  58. break;
  59. case "bloom":
  60. switch (inputs[2])
  61. {
  62. case "threshold":
  63. bloom.threshold.value = float.Parse(inputs[3]);
  64. println($"<color=yellow>Done, bloom threshold at {bloom.threshold.value}</color>");
  65. break;
  66. default:
  67. bloom.intensity.value = float.Parse(inputs[2]);
  68. println($"<color=yellow>Done, bloom intensity at {bloom.intensity.value}</color>");
  69. break;
  70. }
  71. break;
  72. case "exposure":
  73. switch (inputs[2])
  74. {
  75. case "max":
  76. exposure.maxLuminance.value = float.Parse(inputs[3]);
  77. println($"<color=yellow>Done, exposure max at {exposure.maxLuminance.value}</color>");
  78. break;
  79. case "min":
  80. exposure.minLuminance.value = float.Parse(inputs[3]);
  81. println($"<color=yellow>Done, exposure min at {exposure.minLuminance.value}</color>");
  82. break;
  83. }
  84. break;
  85. case "occlusion":
  86. switch (inputs[2])
  87. {
  88. case "thickness":
  89. occlusion.thicknessModifier.value = float.Parse(inputs[3]);
  90. println($"<color=yellow>Done, occlusion thickness at {occlusion.thicknessModifier.value}</color>");
  91. break;
  92. default:
  93. occlusion.intensity.value = float.Parse(inputs[2]);
  94. println($"<color=yellow>Done, occlusion intensity at {occlusion.intensity.value}</color>");
  95. break;
  96. }
  97. break;
  98. default:
  99. println("<color=red>Please specify a value to set, are you retarded?</color>");
  100. break;
  101. }
  102. break;
  103. case "help":
  104. println("Here are the commands you can use");
  105. println("");
  106. println("set fov <int>");
  107. println("set bloom <float>");
  108. println("set bloom threshold <float>");
  109. println("set occlusion <float>");
  110. println("set occlusion threshold <float>");
  111. println("");
  112. break;
  113. default:
  114. println("<color=red>Please enter a valid command</color>");
  115. break;
  116. }
  117. }
  118. catch(Exception e)
  119. {
  120. println($"<color=red>Error : {e.Message}</color>");
  121. // throw e;
  122. }
  123. consoleInput.text = "";
  124. }
  125. public void print(string input)
  126. {
  127. consoleOutput.text += input;
  128. }
  129. public void println(string input)
  130. {
  131. consoleOutput.text += input;
  132. consoleOutput.text += Environment.NewLine;
  133. }
  134. }