|
| 1 | +using FMOD; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | +using UnityEngine; |
| 8 | +using UnityEngine.UI; |
| 9 | +using UnityEngine.SceneManagement; |
| 10 | + |
| 11 | +namespace SuperliminalPracticeMod |
| 12 | +{ |
| 13 | + class PracticeModManager : MonoBehaviour |
| 14 | + { |
| 15 | + public static PracticeModManager Instance; |
| 16 | + public bool noClip; |
| 17 | + public float noClipSpeed; |
| 18 | + public float defaultFarClipPlane; |
| 19 | + public GameObject player; |
| 20 | + public GameObject flashLight; |
| 21 | + public CharacterMotor playerMotor; |
| 22 | + public Camera playerCamera; |
| 23 | + public Text playerText; |
| 24 | + |
| 25 | + Vector3 storedPosition; |
| 26 | + Quaternion storedRotation; |
| 27 | + float storedScale; |
| 28 | + int storedMap; |
| 29 | + float storeTime; |
| 30 | + float teleportTime; |
| 31 | + |
| 32 | + |
| 33 | + void Awake() |
| 34 | + { |
| 35 | + PracticeModManager.Instance = this; |
| 36 | + noClip = false; |
| 37 | + noClipSpeed = 10.0f; |
| 38 | + defaultFarClipPlane = 999f; |
| 39 | + |
| 40 | + storedPosition = Vector3.zero; |
| 41 | + storedRotation = Quaternion.identity; |
| 42 | + storedScale = 1.0f; |
| 43 | + storedMap = -1; |
| 44 | + } |
| 45 | + |
| 46 | + void Update() |
| 47 | + { |
| 48 | + |
| 49 | + |
| 50 | + if (Input.GetKeyDown(KeyCode.K)) |
| 51 | + { |
| 52 | + noClip = !noClip; |
| 53 | + noClipSpeed = 10.0f; |
| 54 | + } |
| 55 | + |
| 56 | + if (GameManager.GM.player == null) |
| 57 | + return; |
| 58 | + |
| 59 | + if (player != GameManager.GM.player) |
| 60 | + { |
| 61 | + player = GameManager.GM.player; |
| 62 | + playerMotor = player.GetComponent<CharacterMotor>(); |
| 63 | + playerCamera = player.GetComponentInChildren<Camera>(); |
| 64 | + defaultFarClipPlane = playerCamera.farClipPlane; |
| 65 | + if(player.transform.Find("Flashlight") == null) |
| 66 | + { |
| 67 | + flashLight = new GameObject("Flashlight"); |
| 68 | + flashLight.SetActive(false); |
| 69 | + this.flashLight.transform.parent = player.transform; |
| 70 | + this.flashLight.transform.localPosition = new Vector3(0f, playerCamera.transform.localPosition.y, 0f); |
| 71 | + Light light = this.flashLight.AddComponent<Light>(); |
| 72 | + light.range = 10000f; |
| 73 | + light.intensity = 0.5f; |
| 74 | + } |
| 75 | + else |
| 76 | + { |
| 77 | + flashLight = player.transform.Find("Flashlight").gameObject; |
| 78 | + } |
| 79 | + |
| 80 | + if (GameObject.Find("PlayerText") == null && GameObject.Find("UI_PAUSE_MENU") != null) |
| 81 | + { |
| 82 | + playerText = NewPlayerText(); |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + |
| 87 | + playerMotor.enabled = !noClip; |
| 88 | + |
| 89 | + if (Input.GetKeyDown(KeyCode.F)) |
| 90 | + { |
| 91 | + flashLight.gameObject.SetActive(!flashLight.gameObject.activeSelf); |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | + if (noClip) |
| 96 | + { |
| 97 | + playerCamera.GetComponent<CameraSettingsLayer>().enabled = false; |
| 98 | + playerCamera.farClipPlane = 10000f; |
| 99 | + this.noClipSpeed += Input.mouseScrollDelta.y; |
| 100 | + this.noClipSpeed = Mathf.Max(0f, this.noClipSpeed); |
| 101 | + Vector3 directionVector = new Vector3(GameManager.GM.playerInput.GetAxisRaw("Move Horizontal"), 0f, GameManager.GM.playerInput.GetAxisRaw("Move Vertical")); |
| 102 | + if (Input.GetKey(KeyCode.Space)) |
| 103 | + { |
| 104 | + directionVector.y += 1f; |
| 105 | + } |
| 106 | + if (Input.GetKey(KeyCode.C) || Input.GetKey(KeyCode.LeftControl)) |
| 107 | + { |
| 108 | + directionVector.y -= 1f; |
| 109 | + } |
| 110 | + playerMotor.transform.Translate(directionVector.normalized * Time.deltaTime * this.noClipSpeed); |
| 111 | + } |
| 112 | + else |
| 113 | + { |
| 114 | + playerCamera.GetComponent<CameraSettingsLayer>().enabled = false; |
| 115 | + } |
| 116 | + |
| 117 | + if(playerText != null) |
| 118 | + { |
| 119 | + playerText.text = GetPlayerTextString(); |
| 120 | + } |
| 121 | + |
| 122 | + if (Input.GetKeyDown(KeyCode.F5)) |
| 123 | + StorePosition(); |
| 124 | + |
| 125 | + if (Input.GetKeyDown(KeyCode.F6)) |
| 126 | + TeleportPosition(); |
| 127 | + |
| 128 | + if (Input.GetKeyDown(KeyCode.F7)) |
| 129 | + ReloadCheckpoint(); |
| 130 | + |
| 131 | + if (Input.GetKeyDown(KeyCode.F8)) |
| 132 | + RestartMap(); |
| 133 | + } |
| 134 | + |
| 135 | + void LateUpdate() |
| 136 | + { |
| 137 | + if (noClip) |
| 138 | + { |
| 139 | + playerCamera.farClipPlane = 10000f; |
| 140 | + } |
| 141 | + else |
| 142 | + { |
| 143 | + playerCamera.farClipPlane = defaultFarClipPlane; |
| 144 | + } |
| 145 | + } |
| 146 | + |
| 147 | + Text NewPlayerText() |
| 148 | + { |
| 149 | + Text newText; |
| 150 | + GameObject gameObject = new GameObject("PlayerText"); |
| 151 | + gameObject.transform.parent = GameObject.Find("UI_PAUSE_MENU").transform.Find("Canvas"); |
| 152 | + gameObject.AddComponent<CanvasGroup>().interactable = false; |
| 153 | + newText = gameObject.AddComponent<Text>(); |
| 154 | + RectTransform component = newText.GetComponent<RectTransform>(); |
| 155 | + component.sizeDelta = new Vector2((float)(Screen.currentResolution.width / 3), (float)(Screen.currentResolution.height / 3)); |
| 156 | + component.pivot = new Vector2(0f, 1f); |
| 157 | + component.anchorMin = new Vector2(0f, 1f); |
| 158 | + component.anchorMax = new Vector2(0f, 1f); |
| 159 | + component.anchoredPosition = new Vector2(25f, -25f); |
| 160 | + foreach (Font font in Resources.FindObjectsOfTypeAll<Font>()) |
| 161 | + { |
| 162 | + if (font.name == "BebasNeue Bold") |
| 163 | + { |
| 164 | + newText.font = font; |
| 165 | + } |
| 166 | + } |
| 167 | + newText.text = "hello world"; |
| 168 | + newText.fontSize = 30; |
| 169 | + |
| 170 | + return newText; |
| 171 | + } |
| 172 | + |
| 173 | + string GetPlayerTextString() |
| 174 | + { |
| 175 | + Vector3 position = playerMotor.transform.localPosition; |
| 176 | + Vector3 velocity = playerMotor.GetComponent<CharacterController>().velocity; |
| 177 | + Vector3 rotation = playerMotor.transform.localRotation.eulerAngles; |
| 178 | + float scale = playerMotor.transform.localScale.x; |
| 179 | + string dynamicInfo = ""; |
| 180 | + |
| 181 | + if (noClip) |
| 182 | + dynamicInfo += "\nNoClip"; |
| 183 | + |
| 184 | + if (flashLight.activeSelf) |
| 185 | + dynamicInfo += "\nFlashlight"; |
| 186 | + |
| 187 | + if (Time.time - this.storeTime <= 1f) |
| 188 | + dynamicInfo += "\nPosition Stored"; |
| 189 | + |
| 190 | + if (Time.time - this.teleportTime <= 1f) |
| 191 | + dynamicInfo += "\nTeleport"; |
| 192 | + |
| 193 | + |
| 194 | + return string.Concat(new object[] |
| 195 | + { |
| 196 | + "Position: ", |
| 197 | + position.x.ToString("0.000"), |
| 198 | + ", ", |
| 199 | + position.y.ToString("0.000"), |
| 200 | + ", ", |
| 201 | + position.z.ToString("0.000"), |
| 202 | + "\n", |
| 203 | + "Rotation: ", |
| 204 | + playerCamera.transform.rotation.x.ToString("0.000"), |
| 205 | + ", ", |
| 206 | + rotation.y.ToString("0.000"), |
| 207 | + ", ", |
| 208 | + rotation.z.ToString("0.000"), |
| 209 | + "\n", |
| 210 | + "Scale: ", |
| 211 | + scale.ToString("0.0000")+"x", |
| 212 | + "\n", |
| 213 | + "Horizontal Velocity: ", |
| 214 | + Mathf.Sqrt(velocity.x * velocity.x + velocity.z * velocity.z).ToString("0.000")+" m/s", |
| 215 | + "\n", |
| 216 | + "Vertical Velocity: ", |
| 217 | + velocity.y.ToString("0.000")+" m/s", |
| 218 | + "\n", |
| 219 | + dynamicInfo |
| 220 | + }); |
| 221 | + |
| 222 | + |
| 223 | + } |
| 224 | + |
| 225 | + void StorePosition() |
| 226 | + { |
| 227 | + storedPosition = playerMotor.transform.position; |
| 228 | + storedRotation = playerMotor.transform.rotation; |
| 229 | + storedScale = playerMotor.transform.localScale.x; |
| 230 | + storedMap = SceneManager.GetActiveScene().buildIndex; |
| 231 | + storeTime = Time.time; |
| 232 | + } |
| 233 | + |
| 234 | + void TeleportPosition() |
| 235 | + { |
| 236 | + if(storedMap == SceneManager.GetActiveScene().buildIndex) |
| 237 | + { |
| 238 | + playerMotor.transform.position = storedPosition; |
| 239 | + playerMotor.transform.rotation = storedRotation; |
| 240 | + playerMotor.transform.localScale = new Vector3(storedScale, storedScale, storedScale); |
| 241 | + teleportTime = Time.time; |
| 242 | + } |
| 243 | + } |
| 244 | + |
| 245 | + void ReloadCheckpoint() |
| 246 | + { |
| 247 | + GameManager.GM.TriggerScenePreUnload(); |
| 248 | + GameManager.GM.GetComponent<SaveAndCheckpointManager>().ResetToLastCheckpoint(); |
| 249 | + } |
| 250 | + |
| 251 | + void RestartMap() |
| 252 | + { |
| 253 | + GameManager.GM.TriggerScenePreUnload(); |
| 254 | + GameManager.GM.GetComponent<SaveAndCheckpointManager>().RestartLevel(); |
| 255 | + } |
| 256 | + |
| 257 | + } |
| 258 | +} |
0 commit comments