Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

이상현상 30 refactoring #206

Merged
merged 1 commit into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly30Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ public class Anomaly30Controller : AbstractAnomalyObject
private bool isAnomalyStopped = false; // Flag to stop attaching scripts
private Anomaly30_thunderstorm thunderstorm;

void Start()
public override bool StartAnomaly()
{
bool res = base.StartAnomaly();

gameManager = GameObject.Find("GameManager").GetComponent<GameManager>();
player = GameObject.Find("Player");
mainCamera = Camera.main;
Expand All @@ -46,8 +48,30 @@ void Start()

// 20초 후 창문 열기 중지
StartCoroutine(EndWindowsOpeningAfterTime(20f));

return res;
}

private void Start()
{
StartAnomaly();
}

public override bool ResetAnomaly()
{
bool res = base.ResetAnomaly();

isAnomalyStopped = true;
StopAnomaly();
gameManager.SetStageClear();

thunderstorm.DestroyThunderstormScreen(); // 비디오 화면 제거
CloseAllWindows();

return res;
}


private IEnumerator ApplyAnomalyWindowScriptsAndCollider()
{
yield return new WaitForSeconds(2f); // 2초 후 시작
Expand Down Expand Up @@ -82,13 +106,7 @@ private IEnumerator ApplyAnomalyWindowScriptsAndCollider()
private IEnumerator EndWindowsOpeningAfterTime(float time)
{
yield return new WaitForSeconds(time);

isAnomalyStopped = true;
StopAnomaly();
gameManager.SetStageClear();

thunderstorm.DestroyThunderstormScreen(); // 비디오 화면 제거
CloseAllWindows();
ResetAnomaly();
}

private void CloseAllWindows()
Expand Down
42 changes: 28 additions & 14 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly30_window.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Collections;
using UnityEngine;

public class Anomaly30_window : InteractableObject, IInteractable
public class Anomaly30_window : AbstractAnomalyInteractable
{
public override string Name { get; } = "Anomaly30_window";

public float swingAngle = 60f;
private const float soundDuration = 0.672f; // 사운드 주기(창문 열리고 닫히는 한 주기과 맞추기 위함)
private readonly float swingSpeed = Mathf.PI / soundDuration;
Expand All @@ -21,8 +23,15 @@ public class Anomaly30_window : InteractableObject, IInteractable
private AudioSource audioSource;
private static GameObject coroutineRunner;

void Start()
private void Start()
{
StartAnomaly();
}

public override bool StartAnomaly()
{
bool res = base.StartAnomaly();

anomalyManager = FindObjectOfType<Anomaly30Controller>();

// 창문 닫을 때 복구할 초기 rotation
Expand All @@ -41,7 +50,10 @@ void Start()

// 15초 동안 이 창문을 닫지 않을 시 발동
Invoke(nameof(EndAnomaly), anomalyDuration);
}

return res;
}


private IEnumerator SwingWindow()
{
Expand Down Expand Up @@ -87,13 +99,18 @@ private IEnumerator CloseWindowCoroutine()
// initial rotation으로 return animation
while (elapsedTime < closeDuration)
{
if (this == null || transform == null) yield break;

transform.rotation = Quaternion.Slerp(currentRotation, initialRotation, elapsedTime / closeDuration);
elapsedTime += Time.deltaTime;
yield return null;
}

transform.rotation = initialRotation;
Destroy(this);
if (this != null && transform != null)
{
transform.rotation = initialRotation;
Destroy(this);
}
}

private void EndAnomaly()
Expand All @@ -102,29 +119,26 @@ private void EndAnomaly()
{
anomalyManager.PlayerDieFromStorm(transform.position);
}

Destroy(this);
}

public override string GetInteractionPrompt()
{
return "Press Left Click to close the window.";
}

public override bool CanInteract(float distance)
{
return !hasInteracted;
}
// modified by 신채환
// CanInteract 메서드가 거리를 인자로 받도록 변경

public override void OnInteract()
{
if (hasInteracted) return;

hasInteracted = true;
CloseWindow();
}

public override bool CanInteract(float distance)
{
if (distance < 5.0f) return true;
else return false;
}

// Persistent Coroutine Runner
private class CoroutineRunner : MonoBehaviour
Expand Down
Loading