2025-11-07 15:38:31 +00:00
|
|
|
using Core.Lifecycle;
|
|
|
|
|
using Core.SaveLoad;
|
2025-09-10 22:17:51 +02:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
2025-11-07 15:38:31 +00:00
|
|
|
public class BirdEyesBehavior : ManagedBehaviour
|
2025-09-10 22:17:51 +02:00
|
|
|
{
|
2025-11-07 15:38:31 +00: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;
|
2025-09-12 12:49:07 +02:00
|
|
|
public bool correctItemIsIn;
|
2025-10-07 13:04:14 +02:00
|
|
|
[SerializeField] private Animator bushAnimator; // Assign in Inspector
|
2025-11-07 15:38:31 +00: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-07 15:38:31 +00:00
|
|
|
_statemachine = GetComponent<AppleMachine>();
|
|
|
|
|
_animator = GetComponentInChildren<Animator>();
|
2025-09-10 22:17:51 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-11 17:03:56 +02:00
|
|
|
public void CorrectItem()
|
2025-09-10 22:17:51 +02:00
|
|
|
{
|
2025-09-12 12:49:07 +02:00
|
|
|
correctItemIsIn = true;
|
2025-11-07 15:38:31 +00:00
|
|
|
_animator.SetTrigger(RightGuess);
|
2025-10-09 16:38:27 +02:00
|
|
|
BirdReveal();
|
2025-09-10 22:17:51 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-11 17:03:56 +02:00
|
|
|
public void IncorrectItem()
|
|
|
|
|
{
|
2025-09-12 12:49:07 +02:00
|
|
|
correctItemIsIn = false;
|
2025-11-07 15:38:31 +00:00
|
|
|
_animator.SetTrigger(WrongGuess);
|
2025-09-11 17:03:56 +02:00
|
|
|
}
|
2025-11-07 15:38:31 +00:00
|
|
|
|
2025-09-11 17:03:56 +02:00
|
|
|
public void NoItem()
|
2025-09-10 22:17:51 +02:00
|
|
|
{
|
2025-11-07 15:38:31 +00:00
|
|
|
_animator.SetTrigger(NoGuess);
|
2025-09-10 22:17:51 +02:00
|
|
|
}
|
2025-11-07 15:38:31 +00:00
|
|
|
|
2025-09-11 17:03:56 +02: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-07 15:38:31 +00:00
|
|
|
bushAnimator.SetTrigger(Wolterisout);
|
|
|
|
|
_wolterisoutTriggered = true;
|
|
|
|
|
}
|
|
|
|
|
_statemachine.ChangeState("BirdSpawned");
|
|
|
|
|
}
|
|
|
|
|
|
2025-11-10 21:59:47 +01:00
|
|
|
internal override void OnSceneRestoreRequested(string serializedData)
|
2025-11-07 15:38:31 +00:00
|
|
|
{
|
|
|
|
|
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-07 15:38:31 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-10 21:59:47 +01:00
|
|
|
internal override string OnSceneSaveRequested()
|
2025-11-07 15:38:31 +00:00
|
|
|
{
|
|
|
|
|
return _wolterisoutTriggered.ToString();
|
2025-09-10 22:17:51 +02:00
|
|
|
}
|
|
|
|
|
}
|