Skip to content

Commit

Permalink
이상현상 30 refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
seozzi committed Dec 15, 2024
1 parent a244b62 commit c57d3e7
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 22 deletions.
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

0 comments on commit c57d3e7

Please sign in to comment.