Skip to content

Commit

Permalink
Add PauseManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Prown0 committed Dec 21, 2024
1 parent 083b1cf commit dca8601
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 302/Assets/Scripts/InteractionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class InteractionManager : AbstractStageObserver
public override string Name { get; } = "InteractionManager";

// 클래스 인스턴스
public static PlayerManager Instance { get; private set; }
public static InteractionManager Instance { get; private set; }

/************
* messages *
Expand Down
152 changes: 152 additions & 0 deletions 302/Assets/Scripts/PauseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
using UnityEngine;

public class PauseManager : AbstractStageObserver
{
/**********
* fields *
**********/

// 캔버스 이름
public string nameCanvas;

// 종료를 위한 입력 시간
public double timeExit;

// 캔버스
private Canvas _canvas;

// 시간
private double _timeKeyDown;

/**************
* properties *
**************/

// 클래스 이름
public override string Name { get; } = "PauseManager";

// 클래스 인스턴스
public static PauseManager Instance { get; private set; }

/************
* messages *
************/

void Update()
{
double time = Time.unscaledTimeAsDouble;

if (Input.GetKeyDown(KeyCode.Escape)) {
_timeKeyDown = time;
} else if (Input.GetKey(KeyCode.Escape) && time - _timeKeyDown >= timeExit) {
ExitGame();
} else if (Input.GetKeyUp(KeyCode.Escape) && time - _timeKeyDown < timeExit) {
if (GameManager.Instance.State == GameManager.GameState.Playing) {
PauseGame();
} else if (GameManager.Instance.State == GameManager.GameState.Paused) {
ResumeGame();
}
}
}

/*************************************
* implementation: AbstractBehaviour *
*************************************/

// `Awake` 메시지 용 메서드
protected override bool Awake_()
{
bool res = false;

if (Instance == null) {
Log($"`Instance` has not been set => set `Instance` as `{Name}`");
Instance = this;
DontDestroyOnLoad(gameObject);
res = base.Awake_();
} else {
Log($"`Instance` has already been set => destroy `{gameObject.name}`");
Destroy(gameObject);
}

return res;
}

// `Start` 메시지 용 메서드
protected override bool Start_()
{
bool res = base.Start_();

// TODO: `Start` 메시지에서 해야할 것 넣기. 없으면 메서드를 아예 지워도 됨.
// 함수가 제대로 작동했으면 `true`를, 아니면 `false`를 반환.

return res;
}

// 필드를 초기화하는 메서드
protected override bool InitFields()
{
bool res = base.InitFields();

// TODO: 필드 초기화할 것 넣기. 없으면 메서드를 아예 지워도 됨.
// (사실 필드 말고 초기화할 것도 넣어도 됨....)
// 함수가 제대로 작동했으면 `true`를, 아니면 `false`를 반환.

return res;
}

/*****************************************
* implementation: AbstractStageObserver *
*****************************************/

// 단계 변경 시 불리는 메서드
public override bool UpdateStage()
{
GameObject obj = GameObject.Find(nameCanvas);
bool res = base.UpdateStage();

if (obj != null) {
Log($"Find `{nameCanvas}` success");

_canvas = obj.GetComponent<Canvas>();
if (_canvas != null) {
Log("Find `Canvas` success");
} else {
Log("Find `Canvas` failed", mode: 1);
res = false;
}
} else {
Log($"Find `{nameCanvas}` failed", mode: 1);
res = false;
}

return res;
}

/***************
* new methods *
***************/

private void PauseGame()
{
Log("Pause the game");
GameManager.Instance.PauseGame();
_canvas.gameObject.SetActive(true);
}

private void ResumeGame()
{
Log("Resume the game");
GameManager.Instance.ResumeGame();
_canvas.gameObject.SetActive(false);
}

private void ExitGame()
{
Log("Exit the game");
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
11 changes: 11 additions & 0 deletions 302/Assets/Scripts/PauseManager.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ public class Anomaly15_spider : AbstractAnomalyInteractable
private Transform cameraTransform;
private AudioSource audioSource;

private void Start()
protected override bool Start_()
{
bool res = base.Start_();

StartAnomaly();

return res;
}

public override bool StartAnomaly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ public override bool StartAnomaly()
return true;
}

private void Start()
protected override bool Start_()
{
bool res = base.Start_();

StartAnomaly();

return res;
}

public override bool ResetAnomaly()
Expand Down
6 changes: 5 additions & 1 deletion 302/Assets/Scripts/SpecificAnomalyManager/Anomaly17_mic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,13 @@ public override bool StartAnomaly()
return true;
}

private void Start()
protected override bool Start_()
{
bool res = base.Start_();

StartAnomaly();

return res;
}

public override bool ResetAnomaly()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class Anomaly29_banana : MonoBehaviour

void Start()
{
anomalyManager = FindObjectOfType<Anomaly29Controller>();
anomalyManager = FindObjectOfType<Anomaly29Controller>();
}

private void OnCollisionEnter(Collision collision)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ public class Anomaly30_window : AbstractAnomalyInteractable
private AudioSource audioSource;
private static GameObject coroutineRunner;

private void Start()
protected override bool Start_()
{
bool res = base.Start_();

StartAnomaly();

return res;
}

public override bool StartAnomaly()
Expand Down

0 comments on commit dca8601

Please sign in to comment.