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

Ref/chaehwan/interface #183

Merged
merged 2 commits into from
Dec 4, 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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using UnityEngine;

public class SCH_AnomalyManager : SCH_AnomalyObject
public abstract class AbstractAnomalyController : AbstractAnomalyObject
{
/**********
* fields *
Expand All @@ -14,38 +14,34 @@ public class SCH_AnomalyManager : SCH_AnomalyObject
public GameObject[] prefabs;

// 이상현상 오브젝트 리스트
protected List<SCH_AnomalyObject> objects;
protected List<AbstractAnomalyObject> objects;

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

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

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

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

// Manager
Manager = this;
Log("Initialize `Manager` success");

// objects
objects = new List<SCH_AnomalyObject>();
objects = new List<AbstractAnomalyObject>();
Log("Initialize `objects` success");

return res;
}

/*************************************
* implementation: SCH_AnomalyObject *
*************************************/
/*****************************************
* implementation: AbstractAnomalyObject *
*****************************************/

// 이상현상을 시작하는 메서드
public override bool StartAnomaly()
Expand All @@ -60,7 +56,7 @@ public override bool StartAnomaly()
res = false;
}

foreach (SCH_AnomalyObject obj in objects) {
foreach (AbstractAnomalyObject obj in objects) {
Log($"Call `{obj.Name}.StartAnomaly` for {obj.gameObject.name} begin");
if (obj.StartAnomaly()) {
Log($"Call `{obj.Name}.StartAnomaly` success");
Expand All @@ -78,7 +74,7 @@ public override bool ResetAnomaly()
{
bool res = base.ResetAnomaly();

foreach (SCH_AnomalyObject obj in objects) {
foreach (AbstractAnomalyObject obj in objects) {
Log($"Call `{obj.Name}.ResetAnomaly` for {obj.gameObject.name} begin");
if (obj.ResetAnomaly()) {
Log($"Call `{obj.Name}.ResetAnomaly` success");
Expand All @@ -95,26 +91,6 @@ public override bool ResetAnomaly()
* virtual methods *
*******************/

// 상호작용 성공 시 불리는 메서드
public virtual bool InteractionSuccess()
{
bool res = true;

Log("Call `GameManager.SetStageClear` begin");
GameManager.Instance.SetStageClear();
Log("Call `GameManager.SetStageClear` end");

Log("Call `ResetAnomaly` begin");
if (ResetAnomaly()) {
Log("Call `ResetAnomaly` success");
} else {
Log("Call `ResetAnomaly` failed", mode: 1);
res = false;
}

return res;
}

// 오브젝트를 초기화하는 메서드
protected virtual bool InitObjects()
{
Expand All @@ -125,11 +101,10 @@ protected virtual bool InitObjects()
GameObject gameObj = GameObject.Find(name);

if (gameObj != null) {
SCH_AnomalyObject obj = gameObj.GetComponent<SCH_AnomalyObject>();
AbstractAnomalyObject obj = gameObj.GetComponent<AbstractAnomalyObject>();

if (obj != null) {
obj.enabled = true;
obj.Manager = this;
objects.Add(obj);
Log($"Find `{name}` success: {obj.Name}");
} else {
Expand All @@ -147,10 +122,9 @@ protected virtual bool InitObjects()
GameObject gameObj = Instantiate(prefab);

if (gameObj != null) {
SCH_AnomalyObject obj = gameObj.GetComponent<SCH_AnomalyObject>();
AbstractAnomalyObject obj = gameObj.GetComponent<AbstractAnomalyObject>();

if (obj != null) {
obj.Manager = this;
objects.Add(obj);
Log($"Instantiate `{prefab.name}` success: {obj.Name}");
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using UnityEngine;

[RequireComponent(typeof(Collider))]
public class SCH_AnomalyInteractable : SCH_AnomalyObject, IInteractable
public class AbstractAnomalyInteractable : AbstractAnomalyObject, IInteractable
{
/**********
* fields *
Expand All @@ -19,43 +19,34 @@ public class SCH_AnomalyInteractable : SCH_AnomalyObject, IInteractable
**************/

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

/*********************************
* implementation: IInteractable *
*********************************/

// 상호작용 프롬프트 텍스트 반환 (예: "E키를 눌러 책상 조사하기")
public string GetInteractionPrompt()
public virtual string GetInteractionPrompt()
{
return prompt;
}

// 상호작용 시 실행될 메서드
public void OnInteract()
public virtual void OnInteract()
{
Log($"Interaction with `{gameObject.name}`");

if (Manager != null) {
Log($"Call `{Manager.Name}.InteractionSuccess` begin");
Manager.InteractionSuccess();
Log($"Call `{Manager.Name}.InteractionSuccess` end");
} else {
Log($"Call `{Manager.Name}.InteractionSuccess` failed", mode: 1);
}

canInteract = false;
}

// 현재 상호작용 가능한지 여부 반환
public bool CanInteract(float distance)
public virtual bool CanInteract(float distance)
{
return canInteract && distance <= distanceInteractionMax;
}

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

// 필드를 초기화하는 메서드
protected override bool InitFields()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
public class SCH_AnomalyObject : SCH_Behaviour
public abstract class AbstractAnomalyObject : AbstractBehaviour
{
/**************
* properties *
**************/

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

// 이상현상 매니저
public SCH_AnomalyManager Manager { get; set; }
public override string Name { get; } = "AbstractAnomalyObject";

/*******************
* virtual methods *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using UnityEngine;

public class SCH_Behaviour : MonoBehaviour
public abstract class AbstractBehaviour : MonoBehaviour
{
/**************
* properties *
**************/

// 클래스 이름
public virtual string Name { get; } = "SCH_Behaviour";
public virtual string Name { get; } = "AbstractBehaviour";

/************
* messages *
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions 302/Assets/Scripts/IStageObserver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public interface IStageObserver
{
// 단계 변경 시 불리는 메서드
public bool UpdateStage();
}
11 changes: 11 additions & 0 deletions 302/Assets/Scripts/IStageObserver.cs.meta

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

12 changes: 6 additions & 6 deletions 302/Assets/Scripts/LaptopFaceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ void Update()
}
}

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

// 필드를 초기화하는 메서드
protected override bool InitFields()
Expand Down Expand Up @@ -121,9 +121,9 @@ public override void ResetScreen()
screen.Apply();
}

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

// 쳐다보기 시작하는 메서드
public void StartGazing()
Expand Down
14 changes: 7 additions & 7 deletions 302/Assets/Scripts/LaptopScreenController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using UnityEngine;

public class LaptopScreenController : SCH_Behaviour
public class LaptopScreenController : AbstractBehaviour
{
/**********
* fields *
Expand Down Expand Up @@ -40,9 +40,9 @@ public int Index {
}
}

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

// `Awake` 메시지 용 메서드
protected override bool Awake_()
Expand All @@ -56,9 +56,9 @@ protected override bool Awake_()
return res;
}

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

public virtual void ResetScreen()
{
Expand Down
8 changes: 4 additions & 4 deletions 302/Assets/Scripts/SlideController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;

public class SlideController : SCH_Behaviour
public class SlideController : AbstractBehaviour
{
/**********
* fields *
Expand Down Expand Up @@ -54,9 +54,9 @@ void Update()
UpdateTrickling();
}

/********************************
* implmentation: SCH_Behaviour *
********************************/
/************************************
* implmentation: AbstractBehaviour *
************************************/

// 필드를 초기화하는 메서드
protected override bool InitFields()
Expand Down
50 changes: 46 additions & 4 deletions 302/Assets/Scripts/SlideManager.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using UnityEngine;

public class SlideManager : SCH_Behaviour
public class SlideManager : AbstractBehaviour, IStageObserver
{
/**********
* fields *
Expand Down Expand Up @@ -38,9 +38,51 @@ public class SlideManager : SCH_Behaviour
// 클래스 인자
public static SlideManager Instance { get; private set; }

/*********************************
* implementation: SCH_Behaviour *
*********************************/
/**********************************
* implementation: IStageObserver *
**********************************/

public bool UpdateStage()
{
int stage = GameManager.Instance.GetCurrentStage();
bool res = true;

if (stage == 0) {
GenerateSlideList();
if (FindSlides()) {
_objectLeft.transform.Translate(Vector3.down * 100.0f);
_objectRight.transform.Translate(Vector3.down * 100.0f);
Log("Set slide success: off");
} else {
Log("Set slide failed", mode: 1);
res = false;
}
} else if (stage > 0 && stage <= numStage) {
if (FindSlides()) {
int index = _slideList[stage - 1];

_controllerLeft.Index = index;
_controllerRight.Index = index;

_controllerLeft.ResetSlide();
_controllerRight.ResetSlide();

Log($"Set slide success: {index}");
} else {
Log("Set slide failed", mode: 1);
res = false;
}
} else {
Log($"Invalid stage: {stage}", mode: 1);
res = false;
}

return res;
}

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

// `Awake` 메시지 용 메서드
protected override bool Awake_()
Expand Down
Loading
Loading