MiniGames/Assets/Scripts/SkyWalker/Skywalker_GameManager.cs

99 lines
2.9 KiB
C#
Raw Normal View History

2025-09-01 00:01:33 +05:00
using UnityEngine;
2025-09-06 23:30:06 +05:00
using DG.Tweening;
2025-09-01 00:01:33 +05:00
public class Skywalker_GameManager : MonoBehaviour
{
2025-09-06 23:30:06 +05:00
public static Skywalker_GameManager Instance;
2025-09-01 00:01:33 +05:00
public GameObject gameOverPanel;
2025-09-22 17:26:19 +05:00
public Skywalker_PlayerController player;
public Shared_DieZibu sharedDie;
2025-09-01 00:01:33 +05:00
2025-09-06 23:30:06 +05:00
[Header("Blueberry Glow Pulse")]
2025-09-22 17:26:19 +05:00
public Material glowMaterial;
public string glowIntensityProp = "_Glow";
2025-09-06 23:30:06 +05:00
public float glowBase = 1.75f;
public float glowPeak = 7.75f;
2025-09-22 17:26:19 +05:00
public float glowPulseDuration = 0.6f;
2025-09-06 23:30:06 +05:00
private Sequence glowSeq;
private int _ID_GlowIntensity;
private string _lastGlowPropName;
2025-09-22 17:26:19 +05:00
private bool isGameOver = false;
2025-09-06 23:30:06 +05:00
2025-09-01 00:01:33 +05:00
void Awake()
{
if (Instance == null) Instance = this;
2025-09-06 23:30:06 +05:00
else { Destroy(gameObject); return; }
if (gameOverPanel) gameOverPanel.SetActive(false);
2025-09-01 00:01:33 +05:00
2025-09-22 17:26:19 +05:00
if (!sharedDie && player)
sharedDie = player.GetComponent<Shared_DieZibu>();
2025-09-07 02:00:26 +05:00
2025-09-22 17:26:19 +05:00
if (!glowMaterial && sharedDie)
glowMaterial = sharedDie.actorMaterial;
2025-09-01 00:01:33 +05:00
2025-09-22 17:26:19 +05:00
_ID_GlowIntensity = Shader.PropertyToID(glowIntensityProp);
_lastGlowPropName = glowIntensityProp;
2025-09-06 23:30:06 +05:00
}
public void KillByLaser() => TriggerGameOver(DeathType.Laser);
public void KillNormal() => TriggerGameOver(DeathType.Normal);
public void TriggerGameOver(DeathType type)
{
2025-09-22 17:26:19 +05:00
if (isGameOver || player == null || sharedDie == null) return;
2025-09-01 00:01:33 +05:00
isGameOver = true;
2025-09-06 23:30:06 +05:00
var col = player.GetComponent<Collider>();
if (col) col.enabled = false;
2025-09-22 17:26:19 +05:00
sharedDie.TriggerDeath(type);
2025-09-01 00:01:33 +05:00
2025-09-22 17:26:19 +05:00
GameoverInvoker();
2025-09-01 00:01:33 +05:00
Debug.Log("GAME OVER!");
}
2025-09-06 23:30:06 +05:00
2025-09-22 17:26:19 +05:00
public void GameoverInvoker(int duration = 5)
2025-09-01 00:01:33 +05:00
{
2025-09-22 17:26:19 +05:00
CancelInvoke(nameof(GameoverPanelEnabler));
Invoke(nameof(GameoverPanelEnabler), duration);
}
public void GameoverPanelEnabler()
{
if (gameOverPanel) gameOverPanel.SetActive(true);
2025-09-01 00:01:33 +05:00
}
2025-09-07 02:00:26 +05:00
2025-09-06 23:30:06 +05:00
public void PulseBlueberryGlow()
{
if (!glowMaterial) return;
2025-09-07 02:00:26 +05:00
2025-09-06 23:30:06 +05:00
if (_lastGlowPropName != glowIntensityProp || _ID_GlowIntensity == 0)
{
_ID_GlowIntensity = Shader.PropertyToID(glowIntensityProp);
_lastGlowPropName = glowIntensityProp;
}
if (glowSeq != null && glowSeq.IsActive()) glowSeq.Kill();
glowMaterial.SetFloat(_ID_GlowIntensity, glowBase);
float half = Mathf.Max(0.01f, glowPulseDuration * 0.5f);
glowSeq = DOTween.Sequence().SetId("BlueberryGlow")
2025-09-07 02:00:26 +05:00
.Append(glowMaterial.DOFloat(glowPeak, _ID_GlowIntensity, half).SetEase(Ease.OutQuad).SetId("BlueberryGlow"))
.Append(glowMaterial.DOFloat(glowBase, _ID_GlowIntensity, half).SetEase(Ease.InQuad).SetId("BlueberryGlow"));
2025-09-06 23:30:06 +05:00
glowSeq.Play();
}
void OnDisable()
{
if (glowSeq != null && glowSeq.IsActive()) glowSeq.Kill();
DOTween.Kill("BlueberryGlow");
if (glowMaterial) glowMaterial.SetFloat(_ID_GlowIntensity, glowBase);
}
2025-09-01 00:01:33 +05:00
}