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