Skip to content

Commit

Permalink
Merge pull request #54 from 2024FALL-SWPP/feat/inspect
Browse files Browse the repository at this point in the history
Feat/Inspector Note add color when played
  • Loading branch information
silee1103 authored Dec 3, 2024
2 parents 58a9053 + 9461cc2 commit 0c7dcf5
Show file tree
Hide file tree
Showing 12 changed files with 985 additions and 422 deletions.
716 changes: 350 additions & 366 deletions Assets/01.Scenes/InspectTestScene.unity

Large diffs are not rendered by default.

136 changes: 80 additions & 56 deletions Assets/02.Scripts/Objects/DoorController.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI; // For Image components

public class DoorController : MonoBehaviour
{
public GameObject scoreUIPanel; // Reference to the score UI panel
public int[] answerNotes; // Array to store notes for this door
private List<int> playedNotes = new List<int>(); // List to store played notes
public GameObject doorWing; // Reference to the door object
public GameObject rippleEffectPrefab; // Reference to the ripple effect prefab
public GameObject[] coloredNotes; // Array to store note prefabs
public GameObject scoreUIPanel;
public int[] answerNotes; // assign note values in inspector (do, re, mi)
private List<int> playedNotes = new List<int>();
public GameObject doorWing;

public GameObject rippleEffectPrefab;
public GameObject[] coloredNotes; // assign objects (in hierarchy)

void Start()
{
scoreUIPanel.SetActive(false);

// Initialize all notes to black
foreach (var note in coloredNotes)
{
Image image = note.GetComponent<Image>();
if (image != null)
{
image.color = Color.black;
}
else
{
Debug.LogError($"Missing Image component on {note.name}");
}
}
}

public void Inspect(GameObject floatingText)
{
// if all scores are collected, the user needs to play music
if (GameManager.im.HasAllScores())
if (GameManager.im.HasAllScores())
{
// Activate the Score UI to display it
scoreUIPanel.SetActive(true);
ClearColoredNotes();

Debug.Log("Play the music to open the door");
Debug.Log("Play the music to open the door");
floatingText.SendMessage("Hide");
}
else
Expand All @@ -38,7 +48,6 @@ public void Inspect(GameObject floatingText)

void Update()
{
// Playing notes
if (scoreUIPanel.activeSelf)
{
for (int i = 1; i <= 8; i++)
Expand All @@ -49,10 +58,8 @@ void Update()

if (CheckNotes())
{
// 색 음표 생성
SpawnColoredNote(i);

// 정답이라면 잠깐의 딜레이 후 문 열기
UpdateColoredNote(i);

if (playedNotes.Count == answerNotes.Length)
{
Debug.Log("Correct notes played. Door is opening.");
Expand All @@ -65,35 +72,54 @@ void Update()
Debug.Log("Incorrect notes played. Try again.");
GameManager.sm.PlaySound("wrong-answer");
playedNotes.Clear();
ClearColoredNotes();
ResetColoredNotes();
}
}
}
}
}

private void SpawnColoredNote(int note)

private void UpdateColoredNote(int note)
{
if (playedNotes.Count - 1 < coloredNotes.Length)
{
GameObject noteObject = coloredNotes[playedNotes.Count - 1];
Image image = noteObject.GetComponent<Image>();
if (image != null)
{
image.color = GetNoteColor(note);

// Create ripple effect
GameObject ripple = Instantiate(rippleEffectPrefab, noteObject.transform.position + new Vector3(0, 0, -1), Quaternion.identity);
ripple.transform.SetParent(noteObject.transform);
ripple.transform.localScale = Vector3.one * 10;
Destroy(ripple, 1.0f);

// StartCoroutine(ScaleEffect(noteObject.transform)); // IF NOTE SHOULD SCALE WHEN PLAYED UNCOMMENT THIS
}
}
}

private Color GetNoteColor(int note)
{
// 색 음표 생성 (색 음표 배열이 있고 그게 뿅 하는 효과와 함께 나타남)
GameObject notePrefab = coloredNotes[playedNotes.Count - 1];
notePrefab.SetActive(true);

// Create the small effect at the note's position
GameObject spawnNoteEffect = Instantiate(rippleEffectPrefab, notePrefab.transform.position + new Vector3(0, 0, -1), Quaternion.identity);
spawnNoteEffect.transform.SetParent(notePrefab.transform);
spawnNoteEffect.transform.localScale = Vector3.one * 20; // Ensure the correct initial scale
// Destroy the particle effect after a certain duration
Destroy(spawnNoteEffect, 1.0f);

// Start the scaling animation for both the note and the small effect
StartCoroutine(ScaleEffect(notePrefab.transform));
switch (note)
{
case 1: return Color.red;
case 2: return new Color(1f, 0.5f, 0f); // Orange
case 3: return Color.yellow;
case 4: return Color.green;
case 5: return Color.blue;
case 6: return new Color(0.5f, 0f, 0.5f); // Purple
case 7: return new Color(1f, 0.75f, 0.8f); // Pink
default: return Color.white;
}
}
private IEnumerator ScaleEffect(Transform targetTransform, bool isEffect = false)

private IEnumerator ScaleEffect(Transform targetTransform)
{
float duration = 0.15f; // Duration of the scaling effect
Vector3 initialScale = Vector3.zero; // Start as a small dot
Vector3 finalScale = Vector3.one; // Final size
float duration = 0.15f;
Vector3 initialScale = Vector3.zero;
Vector3 finalScale = Vector3.one;

float time = 0;
while (time < duration)
Expand All @@ -105,13 +131,16 @@ private IEnumerator ScaleEffect(Transform targetTransform, bool isEffect = false

targetTransform.localScale = finalScale;
}
private void ClearColoredNotes()

private void ResetColoredNotes()
{
// 색 음표 제거
foreach (GameObject notePrefab in coloredNotes)
foreach (GameObject note in coloredNotes)
{
notePrefab.SetActive(false);
Image image = note.GetComponent<Image>();
if (image != null)
{
image.color = Color.black;
}
}
}

Expand All @@ -125,24 +154,19 @@ private bool CheckNotes()
}
}
return true;
}
private IEnumerator OpenDoor()
}

private IEnumerator OpenDoor()
{
// delay
yield return new WaitForSeconds(1.5f);

// UI off
scoreUIPanel.SetActive(false);

// opening door sound & animation
GameManager.sm.PlaySound("opening-door");
GameManager.sm.PlaySound("opening-door");
StartCoroutine(OpenDoorAnimation(doorWing));
}

private IEnumerator OpenDoorAnimation(GameObject door)
{
float duration = 1f; // animation duration
float duration = 1f;
float startRotation = door.transform.eulerAngles.y;
float endRotation = startRotation + 90;
float time = 0;
Expand Down
Binary file added Assets/04.Images/Sprites/UI/4_w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions Assets/04.Images/Sprites/UI/4_w.png.meta

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

Binary file added Assets/04.Images/Sprites/UI/4d_w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0c7dcf5

Please sign in to comment.