Files
AppleHillsProduction/Assets/Scripts/Animation/BirdEyesBehavior.cs

83 lines
2.3 KiB
C#
Raw Normal View History

2025-11-05 17:34:26 +01:00
using Core.Lifecycle;
2025-11-05 13:48:25 +01:00
using Core.SaveLoad;
2025-09-10 22:17:51 +02:00
using UnityEngine;
2025-11-05 17:34:26 +01:00
public class BirdEyesBehavior : ManagedBehaviour
2025-09-10 22:17:51 +02:00
{
2025-11-05 17:34:26 +01:00
// Animator Hashes
private static readonly int RightGuess = Animator.StringToHash("RightGuess");
private static readonly int WrongGuess = Animator.StringToHash("WrongGuess");
private static readonly int NoGuess = Animator.StringToHash("NoGuess");
private static readonly int Wolterisout = Animator.StringToHash("wolterisout");
private AppleMachine _statemachine;
private Animator _animator;
public bool correctItemIsIn;
[SerializeField] private Animator bushAnimator; // Assign in Inspector
2025-11-05 17:34:26 +01:00
// Save state
private bool _wolterisoutTriggered;
// Enable save/load participation
public override bool AutoRegisterForSave => true;
2025-09-10 22:17:51 +02:00
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
2025-11-05 17:34:26 +01:00
_statemachine = GetComponent<AppleMachine>();
_animator = GetComponentInChildren<Animator>();
2025-09-10 22:17:51 +02:00
}
public void CorrectItem()
2025-09-10 22:17:51 +02:00
{
correctItemIsIn = true;
2025-11-05 17:34:26 +01:00
_animator.SetTrigger(RightGuess);
2025-10-09 16:38:27 +02:00
BirdReveal();
2025-09-10 22:17:51 +02:00
}
public void IncorrectItem()
{
correctItemIsIn = false;
2025-11-05 17:34:26 +01:00
_animator.SetTrigger(WrongGuess);
}
2025-11-05 17:34:26 +01:00
public void NoItem()
2025-09-10 22:17:51 +02:00
{
2025-11-05 17:34:26 +01:00
_animator.SetTrigger(NoGuess);
2025-09-10 22:17:51 +02:00
}
2025-11-05 17:34:26 +01:00
public void BirdReveal()
2025-09-10 22:17:51 +02:00
{
2025-10-08 17:15:20 +02:00
if (bushAnimator != null)
{
2025-11-05 17:34:26 +01:00
bushAnimator.SetTrigger(Wolterisout);
_wolterisoutTriggered = true;
}
_statemachine.ChangeState("BirdSpawned");
}
protected override void OnSceneRestoreRequested(string serializedData)
{
base.OnSceneRestoreRequested(serializedData);
if (!string.IsNullOrEmpty(serializedData))
{
if (bool.TryParse(serializedData, out bool wasTriggered))
{
_wolterisoutTriggered = wasTriggered;
// If it was triggered before, set it again on restore
if (_wolterisoutTriggered && bushAnimator != null)
{
bushAnimator.SetTrigger(Wolterisout);
}
}
2025-10-08 17:15:20 +02:00
}
2025-11-05 17:34:26 +01:00
}
protected override string OnSceneSaveRequested()
{
return _wolterisoutTriggered.ToString();
2025-09-10 22:17:51 +02:00
}
}