MayHeCome/Assets/Scripts/TopBarUI.cs
2024-12-18 17:55:34 +08:00

167 lines
5.7 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using DG.Tweening;
using TMPro;
using UI;
using UnityEngine;
using UnityEngine.UI;
public class TopBarUI : MonoBehaviour
{
[Header("日夜主题颜色")]
public Color DayColor = Color.white;
public Color DayColorFont = Color.black;
public Color NightColor = Color.black;
public Color NightColorFont = Color.white;
public TextMeshProUGUI FaithCountTMP;
// public TextMeshProUGUI DayCountTMP;
//
// public TextMeshProUGUI DifficultyTMP;
public TextMeshProUGUI WoodTMP;
public TextMeshProUGUI StoneTMP;
public ParticleSystem FaithParticleSystem;
public ParticleSystem FaithTenParticleSystem;
public ParticleSystem FaithHundParticleSystem;
private float FaithIncreaseHeat = 1;
public float FaithMaxHeat = 10;
public float FaithCooldownTime = 1f;
public float FaithCurrentCooldownTime = 0;
// Start is called before the first frame update
void OnTMPCountChange(TextMeshProUGUI targetTMP, int valueCount)
{
targetTMP.text = valueCount.ToString();
}
void Start()
{
FaithCountTMP.text = Singleton<GameProcedureManager>.Instance.FaithCount.ToString();
WoodTMP.text = Singleton<GameProcedureManager>.Instance.WoodCount.ToString();
StoneTMP.text = $"{Singleton<BlobManager>.Instance.AvailableBlobs.Count}/{Singleton<BlobManager>.Instance.Blobs.Count}";
//Debug.Log($"{Singleton<BlobManager>.Instance.AvailableBlobs.Count}/{Singleton<BlobManager>.Instance.Blobs.Count}");
Singleton<GameProcedureManager>.Instance.onFaithCountChange += i => {
OnTMPCountChange(FaithCountTMP, i);
FaithIncreaseHeat = Math.Min(FaithIncreaseHeat + 1, FaithMaxHeat);
AudioManager.Instance.PlayFaithGainSFX(1 + FaithIncreaseHeat / 5f);
FaithCurrentCooldownTime = FaithCooldownTime;
};
Singleton<GameProcedureManager>.Instance.onWoodCountChange += i => { OnTMPCountChange(WoodTMP, i); };
GameProcedureManager.Instance.OnDay += ChangeDayTheme;
GameProcedureManager.Instance.OnNight += ChangeNightTheme;
SceneTransitionManager.Instance.OnTransition.AddListener(CheckShenPu);
}
private void Update()
{
FaithCountTMP.rectTransform.localScale = Vector2.one + Vector2.one * FaithIncreaseHeat / 10;
if (FaithCurrentCooldownTime > 0)
{
FaithCurrentCooldownTime -= Time.deltaTime;
return;
}
StoneTMP.text = $"{Singleton<BlobManager>.Instance.AvailableBlobs.Count}/{Singleton<BlobManager>.Instance.Blobs.Count}";
FaithIncreaseHeat = 0.8f * FaithIncreaseHeat + 0.2f * 1;
}
public void CheckShenPu(int index)
{
if (index == 3)
{
ChangeNightTheme();
}
else if(GameProcedureManager.Instance.isDay)
{
ChangeDayTheme();
}
}
public void ChangeDayTheme()
{
// GetComponentsInChildren<Image>().ToList().ForEach(i=>i.DOColor(DayColor, 0.5f));
GetComponentsInChildren<IChangeTheme>().ToList().ForEach(i=>i.ToLightMode());
GetComponentsInChildren<TextMeshProUGUI>().ToList().ForEach(i=>i.DOColor(DayColorFont, 0.5f));
}
public void ChangeNightTheme()
{
// GetComponentsInChildren<Image>().ToList().ForEach(i=>i.DOColor(NightColor, 0.5f));
GetComponentsInChildren<IChangeTheme>().ToList().ForEach(i=>i.ToDarkMode());
GetComponentsInChildren<TextMeshProUGUI>().ToList().ForEach(i=>i.DOColor(NightColorFont, 0.5f));
}
public void OnFaithAttractorArrive(int count)
{
GameProcedureManager.Instance.FaithCount+=count;
}
public void EmitFaith(int count, Vector3 worldPosition)
{
var screenPoint = Camera.main.WorldToScreenPoint(worldPosition);
FaithParticleSystem.transform.parent.GetComponent<RectTransform>().anchoredPosition =
transform.InverseTransformPoint(screenPoint);
if (FaithParticleSystem)
{
FaithParticleSystem.Emit(count);
}
}
public void EmitFaith(int count)
{
FaithParticleSystem.transform.parent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
if (FaithParticleSystem)
{
FaithParticleSystem.Emit(count);
}
}
public void EmitHundFaith(int count, Vector3 worldPosition)
{
var screenPoint = Camera.main.WorldToScreenPoint(worldPosition);
FaithParticleSystem.transform.parent.GetComponent<RectTransform>().anchoredPosition =
transform.InverseTransformPoint(screenPoint);
if (FaithTenParticleSystem)
{
FaithTenParticleSystem.Emit(count);
}
}
public void EmitHundFaith(int count)
{
FaithTenParticleSystem.transform.parent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
if (FaithTenParticleSystem)
{
FaithTenParticleSystem.Emit(count);
}
}
public void EmitTenthFaith(int count, Vector3 worldPosition)
{
var screenPoint = Camera.main.WorldToScreenPoint(worldPosition);
FaithParticleSystem.transform.parent.GetComponent<RectTransform>().anchoredPosition =
transform.InverseTransformPoint(screenPoint);
if (FaithHundParticleSystem)
{
FaithHundParticleSystem.Emit(count);
}
}
public void EmitTenthFaith(int count)
{
FaithTenParticleSystem.transform.parent.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
if (FaithHundParticleSystem)
{
FaithHundParticleSystem.Emit(count);
}
}
}