Skip to content

Commit

Permalink
Refactor anomalies No. 14, 25, and 26
Browse files Browse the repository at this point in the history
  • Loading branch information
Prown0 committed Dec 21, 2024
1 parent 6270511 commit 676f509
Show file tree
Hide file tree
Showing 6 changed files with 277 additions and 257 deletions.
8 changes: 6 additions & 2 deletions 302/Assets/Scenes/DefaultGameScene.unity
Original file line number Diff line number Diff line change
Expand Up @@ -10421,6 +10421,10 @@ PrefabInstance:
propertyPath: m_Name
value: LaptopFace
objectReference: {fileID: 0}
- target: {fileID: 1673758693359768105, guid: 7c34e61c4c1b39040bc8b4a56d34f904, type: 3}
propertyPath: m_TagString
value: floatable
objectReference: {fileID: 0}
- target: {fileID: 4455420850089973548, guid: 7c34e61c4c1b39040bc8b4a56d34f904, type: 3}
propertyPath: player
value:
Expand Down Expand Up @@ -43781,8 +43785,8 @@ MonoBehaviour:
- {fileID: 5605359256125054964, guid: 48c8f10abe45bef4098efae902701f34, type: 3}
numStage: 8
numAnomaly: 31
testMode: 2
testAnomalyID: 24
testMode: 0
testAnomalyID: 0
--- !u!4 &1964216256
Transform:
m_ObjectHideFlags: 0
Expand Down
2 changes: 1 addition & 1 deletion 302/Assets/Scripts/AnomalyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

public class AnomalyManager : AbstractStageObserver
{
private HashSet<int> ANOMALIES_NOT_YET = new HashSet<int> { 4, 5, 7, 9, 14, 25, 26 };
private HashSet<int> ANOMALIES_NOT_YET = new HashSet<int> { 4, 5, 7, 9 };

/**********
* fields *
Expand Down
69 changes: 35 additions & 34 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly14Controller.cs
Original file line number Diff line number Diff line change
@@ -1,35 +1,53 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using UnityEngine;

public class Anomaly14Controller : AbstractAnomalyComposite
public class Anomaly14Controller : AbstractAnomalyObject
{
public override string Name { get; } = "Anomaly14Controller";
/**********
* fields *
**********/

public GameObject SweaterSitGirlPrefab;
public GameObject DifferentPrefab; // 다른 종류의 프리팹
public float yRotation = 180f;
private AudioSource audioSource;

private void Start()
/**************
* properties *
**************/

public override string Name { get; } = "Anomaly14Controller";

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

protected override bool InitFields()
{
bool res = base.InitFields();

audioSource = GetComponent<AudioSource>();

return res;
}
// 이상현상을 시작하는 메서드

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

// 이상현상을 시작하는 메서드
public override bool StartAnomaly()
{
bool res = base.StartAnomaly();

if (audioSource != null)
{
if (audioSource != null) {
audioSource.Play();
}

// 기존의 floatable 태그 오브젝트들 제거
GameObject[] floatableObjects = GameObject.FindGameObjectsWithTag("floatable");
foreach (GameObject obj in floatableObjects)
{
foreach (GameObject obj in floatableObjects) {
Debug.Log($"Destroying floatable object: {obj.name}");
Destroy(obj);
}
Expand All @@ -43,24 +61,19 @@ public override bool StartAnomaly()
int totalCount = rowCount * columnCount;
int randomIndex = Random.Range(0, totalCount);

for (int row = 0; row < rowCount; row++)
{
for (int col = 0; col < columnCount; col++)
{
for (int row = 0; row < rowCount; row++) {
for (int col = 0; col < columnCount; col++) {
Vector3 position = startPosition + new Vector3(col * spacing, 0f, row * spacing);
Quaternion rotation = Quaternion.Euler(0f, yRotation, 0f);

// 현재 인덱스 계산
int currentIndex = row * columnCount + col;

// 랜덤으로 선택된 위치면 다른 프리팹을, 아니면 기본 프리팹을 생성
if (currentIndex == randomIndex)
{
if (currentIndex == randomIndex) {
Instantiate(DifferentPrefab, position, rotation);
Debug.Log($"Different prefab spawned at position: {position}");
}
else
{
} else {
Instantiate(SweaterSitGirlPrefab, position, rotation);
}
}
Expand All @@ -73,22 +86,10 @@ public override bool ResetAnomaly()
{
bool res = base.ResetAnomaly();

if (audioSource != null && audioSource.isPlaying)
{
if (audioSource != null && audioSource.isPlaying) {
audioSource.Stop();
}

return res;
}

private void OnEnable()
{
StartAnomaly();
}


private void OnDisable()
{
ResetAnomaly();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

public class Anomaly14_WallyGlasses : InteractableObject
{
private bool hasInteracted = false;

public override void OnInteract()
{
if (hasInteracted) return;
hasInteracted = true;
StartCoroutine(FadeOutAllMeshRenderers(gameObject));
base.OnInteract();

GameManager.Instance.SetStageClear();
StartCoroutine(FadeOutAllMeshRenderers(gameObject));
}

private IEnumerator FadeOutAllMeshRenderers(GameObject target)
{
// 모든 하위 MeshRenderer 컴포넌트들을 찾음
Expand All @@ -23,8 +21,7 @@ private IEnumerator FadeOutAllMeshRenderers(GameObject target)

// 시작할 때의 모든 머티리얼 저장
Material[] originalMaterials = new Material[meshRenderers.Length];
for (int i = 0; i < meshRenderers.Length; i++)
{
for (int i = 0; i < meshRenderers.Length; i++) {
// 각 MeshRenderer의 머티리얼을 복제하여 저장
originalMaterials[i] = new Material(meshRenderers[i].material);
// 투명도를 사용하기 위해 셰이더 모드 변경
Expand All @@ -45,8 +42,7 @@ private IEnumerator FadeOutAllMeshRenderers(GameObject target)
float alpha = 1f - (elapsedTime / fadeTime);

// 모든 MeshRenderer의 알파값 업데이트
foreach (MeshRenderer renderer in meshRenderers)
{
foreach (MeshRenderer renderer in meshRenderers) {
Color color = renderer.material.color;
color.a = alpha;
renderer.material.color = color;
Expand All @@ -57,6 +53,5 @@ private IEnumerator FadeOutAllMeshRenderers(GameObject target)

// 완전히 투명해지면 오브젝트 비활성화
target.SetActive(false);

}
}
132 changes: 78 additions & 54 deletions 302/Assets/Scripts/SpecificAnomalyManager/Anomaly25Controller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,94 @@
using System.Collections.Generic;
using UnityEngine;

public class Anomaly25Controller : AbstractAnomalyComposite
public class Anomaly25Controller : AbstractAnomalyObject
{
public override string Name { get; } = "Anomaly25Controller";
/**********
* fields *
**********/

public AudioSource audioSource; // Inspector에서 할당

void Start() {
StartAnomaly();
}
/**************
* properties *
**************/

public override string Name { get; } = "Anomaly25Controller";

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

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

StartCoroutine(ActivateFloatingEffect());
CreateInvisibleCeiling();
StartCoroutine(ActivateFloatingEffect());

return res;
}

IEnumerator ActivateFloatingEffect() {
yield return new WaitForSeconds(15f);

// 음악 재생
if(audioSource != null) {
audioSource.Play();
}

GameObject[] objects = GameObject.FindGameObjectsWithTag("floatable");
foreach(GameObject obj in objects) {
Rigidbody rb = obj.AddComponent<Rigidbody>();
rb.useGravity = false;
rb.mass = 10f;
StartCoroutine(StartFloating(obj));
}
}
void CreateInvisibleCeiling() {
GameObject ceiling = new GameObject("InvisibleCeiling");
ceiling.transform.position = new Vector3(0, 7.5f, 0);
ceiling.transform.localScale = new Vector3(40f, 0.1f, 40f);
BoxCollider ceilingCollider = ceiling.AddComponent<BoxCollider>();
}

IEnumerator StartFloating(GameObject obj) {
GameManager.Instance.SetStageClear();
Rigidbody rb = obj.GetComponent<Rigidbody>();
Vector3 randomDirection = new Vector3(
Random.Range(-1f, 1f),
Mathf.Abs(Random.Range(0.5f, 1f)),
Random.Range(-1f, 1f)
).normalized;

float currentSpeed = 0f;
float targetSpeed = 0.3f;
float duration = 5f;
float elapsedTime = 0f;

while (elapsedTime < duration) {
currentSpeed = Mathf.Lerp(0f, targetSpeed, elapsedTime / duration);
if(obj.transform.position.y >= 6f) {
randomDirection.y = 0f;
}
rb.velocity = randomDirection * currentSpeed;
elapsedTime += Time.deltaTime;
yield return new WaitForFixedUpdate();
}
}
}
/***************
* new methods *
***************/

void CreateInvisibleCeiling()
{
GameObject ceiling = new GameObject("InvisibleCeiling");

ceiling.transform.position = new Vector3(0, 7.5f, 0);
ceiling.transform.localScale = new Vector3(40f, 0.1f, 40f);
ceiling.AddComponent<BoxCollider>();
}

IEnumerator ActivateFloatingEffect()
{
GameObject[] objects = GameObject.FindGameObjectsWithTag("floatable");

yield return new WaitForSeconds(15.0f);

GameManager.Instance.SetStageClear();

// 음악 재생
if(audioSource != null) {
audioSource.Play();
}

foreach (GameObject obj in objects) {
Rigidbody rb = obj.AddComponent<Rigidbody>();

rb.useGravity = false;
rb.mass = 10.0f;
StartCoroutine(StartFloating(obj));
}
}

IEnumerator StartFloating(GameObject obj)
{
Rigidbody rb = obj.GetComponent<Rigidbody>();
Vector3 randomDirection;
float duration = 5.0f;
float timeStart = Time.time;
float time;
float currentSpeed = 0.0f;
float targetSpeed = 0.3f;

randomDirection = new Vector3(
Random.Range(-1.0f, 1.0f),
Random.Range(0.5f, 1.0f),
Random.Range(-1.0f, 1.0f)
).normalized;

while ((time = Time.time - timeStart) < duration) {
currentSpeed = Mathf.Lerp(0f, targetSpeed, time / duration);
if(obj.transform.position.y >= 6f) {
randomDirection.y = 0.0f;
}

rb.velocity = randomDirection * currentSpeed;

yield return new WaitForFixedUpdate();
}
}
}
Loading

0 comments on commit 676f509

Please sign in to comment.