129 lines
3.2 KiB
C#
129 lines
3.2 KiB
C#
// ClawGameBinder.cs
|
||
using UnityEngine;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using TMPro;
|
||
|
||
public class ClawGameBinder : MonoBehaviour
|
||
{
|
||
[Header("Scene References")]
|
||
public ClawController claw;
|
||
public PlatformSpinController platform;
|
||
public RoundTimer timer;
|
||
|
||
[Header("UI (optional)")]
|
||
public TextMeshProUGUI eventsText;
|
||
public int maxLines = 8;
|
||
public bool includeTimestamps = true;
|
||
|
||
// cached manager instance
|
||
private ClawScoreManager sm;
|
||
|
||
// rolling log
|
||
private readonly Queue<string> lines = new Queue<string>();
|
||
|
||
void OnEnable()
|
||
{
|
||
TryBind();
|
||
}
|
||
|
||
void OnDisable()
|
||
{
|
||
TryUnbind();
|
||
}
|
||
|
||
private void TryBind()
|
||
{
|
||
sm = ClawScoreManager.Instance ?? FindObjectOfType<ClawScoreManager>();
|
||
if (sm == null)
|
||
{
|
||
Debug.LogWarning("[ClawGameBinder] ClawScoreManager not found; events won’t be wired.");
|
||
return;
|
||
}
|
||
|
||
sm.OnClawDisabled += HandleClawDisabled;
|
||
sm.OnClawJam += HandleClawJammed;
|
||
sm.OnPlatformTurbo += HandleTurbo;
|
||
sm.OnPlatformSlow += HandleSlow;
|
||
sm.OnPlatformFreeze += HandleFreeze;
|
||
sm.OnTimeAdded += HandleTimeAdded;
|
||
|
||
// If you exposed this event in your ScoreManager:
|
||
sm.OnComboAchieved += HandleCombo; // comment out if not present
|
||
}
|
||
|
||
private void TryUnbind()
|
||
{
|
||
if (sm == null) return;
|
||
|
||
sm.OnClawDisabled -= HandleClawDisabled;
|
||
sm.OnClawJam -= HandleClawJammed;
|
||
sm.OnPlatformTurbo -= HandleTurbo;
|
||
sm.OnPlatformSlow -= HandleSlow;
|
||
sm.OnPlatformFreeze -= HandleFreeze;
|
||
sm.OnTimeAdded -= HandleTimeAdded;
|
||
|
||
// If you exposed this event:
|
||
sm.OnComboAchieved -= HandleCombo; // comment out if not present
|
||
|
||
sm = null;
|
||
}
|
||
|
||
// ---------- Event Handlers ----------
|
||
|
||
private void HandleClawDisabled(float seconds)
|
||
{
|
||
Log($"Claw Disabled {seconds:0.##}s");
|
||
if (claw) claw.ApplyDisable(seconds);
|
||
}
|
||
|
||
private void HandleClawJammed(float seconds)
|
||
{
|
||
Log($"Claw Jam {seconds:0.##}s");
|
||
if (claw) claw.ApplyJam(seconds);
|
||
}
|
||
|
||
private void HandleTurbo(float seconds)
|
||
{
|
||
Log($"Turbo +speed {seconds:0.##}s");
|
||
if (platform) platform.ApplyTurbo(seconds);
|
||
}
|
||
|
||
private void HandleSlow(float seconds)
|
||
{
|
||
Log($"Slow -speed {seconds:0.##}s");
|
||
if (platform) platform.ApplySlow(seconds);
|
||
}
|
||
|
||
private void HandleFreeze(float seconds)
|
||
{
|
||
Log($"Freeze {seconds:0.##}s");
|
||
if (platform) platform.ApplyFreeze(seconds);
|
||
}
|
||
|
||
private void HandleTimeAdded(float seconds)
|
||
{
|
||
Log($"Time added: +{seconds:0.##}s");
|
||
if (timer) timer.AddTime(seconds);
|
||
}
|
||
|
||
// If your ScoreManager exposes combos:
|
||
private void HandleCombo(ClawBubbleType[] combo)
|
||
{
|
||
Log($" Combo: {string.Join(", ", combo)}");
|
||
}
|
||
|
||
// ---------- UI Log ----------
|
||
|
||
private void Log(string msg)
|
||
{
|
||
if (!eventsText) return;
|
||
|
||
string line = includeTimestamps ? $"[{Time.time:0.0}s] {msg}" : msg;
|
||
//lines.Enqueue(line);
|
||
//while (lines.Count > maxLines) lines.Dequeue();
|
||
|
||
eventsText.text = line;
|
||
}
|
||
}
|