2023-03-11 04:51:22 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
using HeavenStudio.Util;
|
|
|
|
using HeavenStudio.Games;
|
2023-06-10 19:13:29 +00:00
|
|
|
using Jukebox;
|
|
|
|
using Jukebox.Legacy;
|
2023-03-11 04:51:22 +00:00
|
|
|
|
|
|
|
namespace HeavenStudio.Common
|
|
|
|
{
|
|
|
|
public class SectionMedalsManager : MonoBehaviour
|
|
|
|
{
|
|
|
|
public static SectionMedalsManager instance { get; private set; }
|
|
|
|
|
|
|
|
[SerializeField] GameObject MedalsHolder;
|
|
|
|
[SerializeField] GameObject MedalOkPrefab;
|
|
|
|
[SerializeField] GameObject MedalMissPrefab;
|
|
|
|
|
|
|
|
Conductor cond;
|
|
|
|
bool isMedalsStarted = false;
|
|
|
|
bool isMedalsEligible = true;
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
2023-05-07 20:33:15 +00:00
|
|
|
public void Awake()
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
|
|
|
instance = this;
|
2023-05-07 20:33:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
{
|
2023-03-11 04:51:22 +00:00
|
|
|
cond = Conductor.instance;
|
|
|
|
GameManager.instance.onSectionChange += OnSectionChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-05-07 20:33:15 +00:00
|
|
|
public void AnchorToOverlay(GameObject overlay)
|
|
|
|
{
|
|
|
|
transform.position = overlay.transform.position;
|
|
|
|
transform.rotation = overlay.transform.rotation;
|
|
|
|
transform.localScale = overlay.transform.localScale;
|
|
|
|
}
|
|
|
|
|
2023-03-11 04:51:22 +00:00
|
|
|
public void MakeIneligible()
|
|
|
|
{
|
|
|
|
isMedalsEligible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
{
|
|
|
|
isMedalsStarted = false;
|
|
|
|
isMedalsEligible = true;
|
2023-05-07 20:33:15 +00:00
|
|
|
foreach (Transform child in MedalsHolder?.transform)
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
|
|
|
Destroy(child.gameObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-26 05:22:51 +00:00
|
|
|
public void OnSectionChange(RiqEntity newSection, RiqEntity lastSection)
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
2023-12-26 05:22:51 +00:00
|
|
|
if (newSection == null) return;
|
2023-04-03 04:17:55 +00:00
|
|
|
if (!PersistentDataManager.gameSettings.isMedalOn) return;
|
2023-03-11 04:51:22 +00:00
|
|
|
if (PersistentDataManager.gameSettings.isMedalOn && !isMedalsStarted)
|
|
|
|
{
|
|
|
|
isMedalsStarted = true;
|
|
|
|
isMedalsEligible = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-12-26 05:22:51 +00:00
|
|
|
GameManager.instance.DoSectionCompletion(newSection.beat, isMedalsEligible, lastSection["sectionName"], 1);
|
2023-03-11 04:51:22 +00:00
|
|
|
GameObject medal = Instantiate(isMedalsEligible ? MedalOkPrefab : MedalMissPrefab, MedalsHolder.transform);
|
|
|
|
medal.SetActive(true);
|
|
|
|
isMedalsEligible = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-26 05:22:51 +00:00
|
|
|
public void OnRemixEnd(double beat, RiqEntity lastSection)
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
2023-04-03 04:17:55 +00:00
|
|
|
if (!PersistentDataManager.gameSettings.isMedalOn) return;
|
2023-12-26 05:22:51 +00:00
|
|
|
if (PersistentDataManager.gameSettings.isMedalOn && isMedalsStarted && lastSection != null)
|
2023-03-11 04:51:22 +00:00
|
|
|
{
|
2023-12-26 05:22:51 +00:00
|
|
|
GameManager.instance.DoSectionCompletion(beat, isMedalsEligible, lastSection["sectionName"], 1);
|
2023-03-11 04:51:22 +00:00
|
|
|
GameObject medal = Instantiate(isMedalsEligible ? MedalOkPrefab : MedalMissPrefab, MedalsHolder.transform);
|
|
|
|
medal.SetActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|