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