Skip to content

Commit

Permalink
Merge pull request #210 from 2024FALL-SWPP/ref/chaehwan/design-pattern
Browse files Browse the repository at this point in the history
Ref/chaehwan/design pattern
  • Loading branch information
Prown0 authored Dec 21, 2024
2 parents eb9e459 + 9e5c016 commit f9c76dc
Show file tree
Hide file tree
Showing 13 changed files with 736 additions and 82 deletions.
570 changes: 511 additions & 59 deletions 302/Assets/Scenes/DefaultGameScene.unity

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 302/Assets/Scripts/FireExtinguisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private void Update()

CheckFireCollision();

if (Input.GetMouseButtonDown(1))
if (Input.GetMouseButtonDown(1) && Time.timeScale != 0.0f)
{
PutDown();
}
Expand Down
3 changes: 3 additions & 0 deletions 302/Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ private IEnumerator StartStage()
}

_anomalyController = AnomalyManager.Instance.GetAnomalyController();

yield return null;

_anomalyController.StartAnomaly();
}

Expand Down
23 changes: 22 additions & 1 deletion 302/Assets/Scripts/InteractionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class InteractionManager : AbstractStageObserver
// 클래스 이름
public override string Name { get; } = "InteractionManager";

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

/************
* messages *
************/
Expand All @@ -43,7 +46,7 @@ void OnDrawGizmos()

void Update()
{
if (cursor != null) {
if (cursor != null && Time.timeScale != 0.0f) {
if (PlayerManager.Instance.State == PlayerManager.PlayerState.Normal) {
Ray ray = playerCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0.0f));
RaycastHit hit;
Expand All @@ -70,6 +73,24 @@ void Update()
* 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;
}

// 필드를 초기화하는 메서드
protected override bool InitFields()
{
Expand Down
4 changes: 1 addition & 3 deletions 302/Assets/Scripts/LaptopFaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public class LaptopFaceController : LaptopScreenController
* fields *
**********/

// 오브젝트
public GameObject player;

// 내부 수치
private int TANGENT_MAX = 25;
private float TANGENT_CONST = 12.5f;
Expand Down Expand Up @@ -134,6 +131,7 @@ public void StartGazing()
// 쳐다보기 화면을 갱신하는 메서드
private void UpdateGazing()
{
GameObject player = GameObject.Find("Main Camera");
Vector3 forward = Vector3.ProjectOnPlane(transform.forward, Vector3.up).normalized;
Vector3 direction = Vector3.ProjectOnPlane(player.transform.position - transform.position, Vector3.up);
float dotProd = Vector3.Dot(direction, forward);
Expand Down
153 changes: 153 additions & 0 deletions 302/Assets/Scripts/PauseManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
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");
_canvas.gameObject.SetActive(false);
} 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.

26 changes: 13 additions & 13 deletions 302/Assets/Scripts/PlayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,14 @@ public enum PlayerState

void FixedUpdate()
{
if (State == PlayerState.Normal) {
if (State == PlayerState.Normal && Time.timeScale != 0.0f) {
HandleMovement();
}
}

void Start()
{
SetupComponents();
SetupPhysics();
Cursor.lockState = CursorLockMode.Locked;
}

void Update()
{
if (State == PlayerState.Normal) {
if (State == PlayerState.Normal && Time.timeScale != 0.0f) {
HandleInput();
HandleCamera();
}
Expand Down Expand Up @@ -134,15 +127,22 @@ protected override bool Awake_()
// 필드를 초기화하는 메서드
protected override bool InitFields()
{
GameObject obj = GameObject.Find("ScreenFader");
bool res = base.InitFields();

screenFader = FindObjectOfType<ScreenFader>();
if (screenFader == null) {
GameObject obj = new GameObject("ScreenFader");

if (obj != null) {
Log("Find `ScreenFader` success => Get `ScreenFader`");
screenFader = obj.GetComponent<ScreenFader>();
} else {
Log("Find `ScreenFader` failed => New `ScreenFader`");
obj = new GameObject("ScreenFader");
screenFader = obj.AddComponent<ScreenFader>();
}

SetupComponents();
SetupPhysics();
Cursor.lockState = CursorLockMode.Locked;

return res;
}

Expand Down
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 f9c76dc

Please sign in to comment.