From 56303f6a9bf0e2eefe247852bf9d5a2a05afa6c8 Mon Sep 17 00:00:00 2001 From: "qsxft258@gmail.com" Date: Thu, 4 Sep 2025 23:27:58 +0900 Subject: [PATCH] =?UTF-8?q?Fix=20:=20=EC=95=84=EC=9D=B4=EC=8B=9C=EC=95=84?= =?UTF-8?q?=20=EC=BD=98=EC=84=9C=ED=8A=B8=20=EB=B0=B0=EA=B2=BD=20=EC=88=98?= =?UTF-8?q?=EC=A0=95=20=EB=B0=8F=20=ED=94=8C=EB=9D=BC=EC=9D=B4=20=EC=B9=B4?= =?UTF-8?q?=EB=A9=94=EB=9D=BC=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Scene/[아이시아]데뷔 콘서트 배경.unity | 4 +- Assets/Scripts/FlyCamera.cs | 198 ++++++++++++++++++ Assets/Scripts/FlyCamera.cs.meta | 2 + 3 files changed, 202 insertions(+), 2 deletions(-) create mode 100644 Assets/Scripts/FlyCamera.cs create mode 100644 Assets/Scripts/FlyCamera.cs.meta diff --git a/Assets/ResourcesData/Background/[아이시아]데뷔 콘서트 배경/Scene/[아이시아]데뷔 콘서트 배경.unity b/Assets/ResourcesData/Background/[아이시아]데뷔 콘서트 배경/Scene/[아이시아]데뷔 콘서트 배경.unity index 24407f3d..a3a5fe7a 100644 --- a/Assets/ResourcesData/Background/[아이시아]데뷔 콘서트 배경/Scene/[아이시아]데뷔 콘서트 배경.unity +++ b/Assets/ResourcesData/Background/[아이시아]데뷔 콘서트 배경/Scene/[아이시아]데뷔 콘서트 배경.unity @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6d284cbd8e9a58a31a386491fafa45ffa25a40a8103e355c1f194403a9205b51 -size 358649 +oid sha256:4494fb92816aeca80d3ad6782cf5ec8701b405bc8022199d33a54556262b34e3 +size 371357 diff --git a/Assets/Scripts/FlyCamera.cs b/Assets/Scripts/FlyCamera.cs new file mode 100644 index 00000000..8d477943 --- /dev/null +++ b/Assets/Scripts/FlyCamera.cs @@ -0,0 +1,198 @@ +using System.IO; +using UnityEngine; + +public class FlyCamera : MonoBehaviour +{ + [Header("Movement Settings")] + public float moveSpeed = 10f; + public float fastMoveSpeed = 50f; + public float mouseSensitivity = 2f; + + [Header("FOV Settings")] + public float minFOV = 10f; + public float maxFOV = 120f; + public float fovScrollSpeed = 10f; + + [Header("Screenshot Settings")] + public KeyCode screenshotKey = KeyCode.F2; + + private Camera cam; + private float rotationX = 0f; + private bool isFlyCamEnabled = true; + private float screenshotFlashTime = 0f; + private bool showScreenshotFlash = false; + + private void Start() + { + cam = GetComponent(); + if (cam == null) + { + cam = Camera.main; + } + + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + + CreateScreenshotDirectory(); + } + + private void Update() + { + if (!isFlyCamEnabled) return; + + HandleMouseLook(); + HandleMovement(); + HandleFOVControl(); + HandleScreenshot(); + HandleScreenshotFlash(); + + if (Input.GetKeyDown(KeyCode.Escape)) + { + ToggleCursor(); + } + + if (Cursor.lockState != CursorLockMode.Locked && Input.GetMouseButtonDown(0)) + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + } + + private void HandleMouseLook() + { + if (Cursor.lockState != CursorLockMode.Locked) return; + + float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity; + float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity; + + rotationX -= mouseY; + rotationX = Mathf.Clamp(rotationX, -90f, 90f); + + transform.rotation = Quaternion.Euler(rotationX, transform.eulerAngles.y + mouseX, 0f); + } + + private void HandleMovement() + { + Vector3 movement = Vector3.zero; + float currentSpeed = Input.GetKey(KeyCode.LeftShift) ? fastMoveSpeed : moveSpeed; + + if (Input.GetKey(KeyCode.W)) + movement += transform.forward; + if (Input.GetKey(KeyCode.S)) + movement -= transform.forward; + if (Input.GetKey(KeyCode.A)) + movement -= transform.right; + if (Input.GetKey(KeyCode.D)) + movement += transform.right; + if (Input.GetKey(KeyCode.Q)) + movement -= transform.up; + if (Input.GetKey(KeyCode.E)) + movement += transform.up; + + transform.position += movement * currentSpeed * Time.deltaTime; + } + + private void HandleFOVControl() + { + float scroll = Input.GetAxis("Mouse ScrollWheel"); + if (scroll != 0f) + { + cam.fieldOfView = Mathf.Clamp(cam.fieldOfView - scroll * fovScrollSpeed, minFOV, maxFOV); + } + } + + private void HandleScreenshot() + { + if (Input.GetKeyDown(screenshotKey)) + { + TakeScreenshot(); + } + } + + private void CreateScreenshotDirectory() + { + string screenshotDir = Path.Combine(Application.dataPath, "..", "Screenshots"); + if (!Directory.Exists(screenshotDir)) + { + Directory.CreateDirectory(screenshotDir); + } + } + + private void TakeScreenshot() + { + StartCoroutine(CaptureScreenshotDelayed()); + } + + private System.Collections.IEnumerator CaptureScreenshotDelayed() + { + yield return new WaitForEndOfFrame(); + + string timestamp = System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); + string filename = $"Screenshot_{timestamp}.png"; + string screenshotDir = Path.Combine(Application.dataPath, "..", "Screenshots"); + string fullPath = Path.Combine(screenshotDir, filename); + + ScreenCapture.CaptureScreenshot(fullPath); + Debug.Log($"Screenshot saved: {fullPath}"); + + showScreenshotFlash = true; + screenshotFlashTime = 0.2f; + } + + private void HandleScreenshotFlash() + { + if (showScreenshotFlash) + { + screenshotFlashTime -= Time.deltaTime; + if (screenshotFlashTime <= 0f) + { + showScreenshotFlash = false; + } + } + } + + private void OnGUI() + { + if (showScreenshotFlash) + { + GUI.color = new Color(1f, 1f, 1f, 0.8f); + GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), Texture2D.whiteTexture); + + GUIStyle style = new GUIStyle(); + style.fontSize = 36; + style.normal.textColor = Color.black; + style.alignment = TextAnchor.MiddleCenter; + + GUI.Label(new Rect(0, Screen.height / 2 - 50, Screen.width, 100), "Screenshot Captured!", style); + } + } + + private void ToggleCursor() + { + if (Cursor.lockState == CursorLockMode.Locked) + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + else + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + } + + public void EnableFlyCamera(bool enable) + { + isFlyCamEnabled = enable; + if (enable) + { + Cursor.lockState = CursorLockMode.Locked; + Cursor.visible = false; + } + else + { + Cursor.lockState = CursorLockMode.None; + Cursor.visible = true; + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/FlyCamera.cs.meta b/Assets/Scripts/FlyCamera.cs.meta new file mode 100644 index 00000000..9cb9d3c7 --- /dev/null +++ b/Assets/Scripts/FlyCamera.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: 146c26530590c884b8b31c7abc88671a \ No newline at end of file