2025-09-30 15:52:37 +02:00
|
|
|
using UnityEngine;
|
2025-11-11 08:48:29 +00:00
|
|
|
using System;
|
2025-09-30 15:52:37 +02:00
|
|
|
using System.Collections;
|
2025-10-14 15:53:58 +02:00
|
|
|
using Core;
|
2025-11-11 08:48:29 +00:00
|
|
|
using Core.Lifecycle;
|
2025-11-07 15:38:31 +00:00
|
|
|
using Core.SaveLoad;
|
2025-10-20 21:01:10 +02:00
|
|
|
using UnityEngine.Audio;
|
2025-09-30 15:52:37 +02:00
|
|
|
|
2025-11-11 08:48:29 +00:00
|
|
|
public class PicnicBehaviour : ManagedBehaviour
|
2025-09-30 15:52:37 +02:00
|
|
|
{
|
|
|
|
|
[Header("Random Call Settings")]
|
|
|
|
|
public float getDistractedMin = 2f;
|
|
|
|
|
public float getDistractedMax = 5f;
|
|
|
|
|
public float getFlirtyMin = 1f;
|
|
|
|
|
public float getFlirtyMax = 3f;
|
|
|
|
|
|
2025-11-07 15:38:31 +00:00
|
|
|
private AppleMachine stateMachine;
|
2025-09-30 15:52:37 +02:00
|
|
|
private Animator animator;
|
|
|
|
|
|
|
|
|
|
[Header("The FakeChocolate to destroy!")]
|
2025-11-11 08:48:29 +00:00
|
|
|
[SerializeField] private GameObject fakeChocolate;
|
|
|
|
|
[SerializeField] private GameObject realChocolate;
|
2025-09-30 15:52:37 +02:00
|
|
|
|
2025-10-30 16:31:01 +01:00
|
|
|
private AppleAudioSource _audioSource;
|
2025-10-20 21:01:10 +02:00
|
|
|
public AudioResource distractedAudioClips;
|
|
|
|
|
public AudioResource angryAudioClips;
|
|
|
|
|
public AudioResource feederClips;
|
|
|
|
|
public AudioResource moanerClips;
|
|
|
|
|
|
2025-11-11 08:48:29 +00:00
|
|
|
// Save system configuration
|
|
|
|
|
public override bool AutoRegisterForSave => true;
|
2025-09-30 15:52:37 +02:00
|
|
|
|
2025-11-11 08:48:29 +00:00
|
|
|
// Runtime state tracking
|
|
|
|
|
private bool _fakeChocolateDestroyed;
|
|
|
|
|
|
|
|
|
|
internal override void OnManagedAwake()
|
2025-09-30 15:52:37 +02:00
|
|
|
{
|
2025-11-07 15:38:31 +00:00
|
|
|
stateMachine = GetComponent<AppleMachine>();
|
2025-10-20 21:01:10 +02:00
|
|
|
animator = GetComponent<Animator>();
|
2025-10-30 16:31:01 +01:00
|
|
|
_audioSource = GetComponent<AppleAudioSource>();
|
2025-09-30 15:52:37 +02:00
|
|
|
}
|
|
|
|
|
|
2025-11-11 08:48:29 +00:00
|
|
|
internal override void OnSceneRestoreCompleted()
|
|
|
|
|
{
|
|
|
|
|
if (_fakeChocolateDestroyed)
|
|
|
|
|
{
|
|
|
|
|
DestroyChocolateObjects();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(StateCycleRoutine());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-07 13:04:14 +02:00
|
|
|
private IEnumerator StateCycleRoutine()
|
2025-09-30 15:52:37 +02:00
|
|
|
{
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
2025-10-07 13:04:14 +02:00
|
|
|
// Distracted state
|
2025-11-11 08:48:29 +00:00
|
|
|
float distractedWait = UnityEngine.Random.Range(getDistractedMin, getDistractedMax);
|
2025-10-07 13:04:14 +02:00
|
|
|
stateMachine.ChangeState("Picnic PPL Distracted");
|
|
|
|
|
animator.SetBool("theyDistracted", true);
|
2025-10-20 21:01:10 +02:00
|
|
|
_audioSource.Stop();
|
2025-10-07 13:04:14 +02:00
|
|
|
yield return new WaitForSeconds(distractedWait);
|
2025-09-30 15:52:37 +02:00
|
|
|
|
2025-10-07 13:04:14 +02:00
|
|
|
// Chilling state
|
2025-11-11 08:48:29 +00:00
|
|
|
float chillingWait = UnityEngine.Random.Range(getFlirtyMin, getFlirtyMax);
|
2025-10-07 13:04:14 +02:00
|
|
|
stateMachine.ChangeState("Picnic PPL Chilling");
|
|
|
|
|
animator.SetBool("theyDistracted", false);
|
2025-10-20 21:01:10 +02:00
|
|
|
_audioSource.Stop();
|
2025-10-07 13:04:14 +02:00
|
|
|
yield return new WaitForSeconds(chillingWait);
|
|
|
|
|
}
|
2025-09-30 15:52:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void triedToStealChocolate()
|
|
|
|
|
{
|
2025-10-20 21:01:10 +02:00
|
|
|
_audioSource.Stop();
|
2025-09-30 15:52:37 +02:00
|
|
|
animator.SetTrigger("theyAngry");
|
2025-10-14 15:53:58 +02:00
|
|
|
Logging.Debug("Hey! Don't steal my chocolate!");
|
2025-10-30 16:31:01 +01:00
|
|
|
_audioSource.audioSource.resource = angryAudioClips;
|
|
|
|
|
_audioSource.Play(0);
|
2025-09-30 15:52:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void destroyFakeChocolate()
|
2025-11-11 08:48:29 +00:00
|
|
|
{
|
|
|
|
|
_fakeChocolateDestroyed = true;
|
|
|
|
|
Destroy(fakeChocolate);
|
|
|
|
|
Destroy(realChocolate);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DestroyChocolateObjects()
|
2025-09-30 15:52:37 +02:00
|
|
|
{
|
|
|
|
|
if (fakeChocolate != null)
|
|
|
|
|
{
|
|
|
|
|
Destroy(fakeChocolate);
|
2025-11-11 08:48:29 +00:00
|
|
|
fakeChocolate = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (realChocolate != null)
|
|
|
|
|
{
|
|
|
|
|
realChocolate.SetActive(true);
|
2025-09-30 15:52:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-20 21:01:10 +02:00
|
|
|
public void PlayFeederAudio()
|
|
|
|
|
{
|
2025-10-30 16:31:01 +01:00
|
|
|
_audioSource.audioSource.resource = feederClips;
|
|
|
|
|
_audioSource.Play(0);
|
2025-10-20 21:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayMoanerAudio()
|
|
|
|
|
{
|
2025-10-30 16:31:01 +01:00
|
|
|
_audioSource.audioSource.resource = moanerClips;
|
|
|
|
|
_audioSource.Play(0);
|
2025-10-20 21:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void PlayDistractedAudio()
|
|
|
|
|
{
|
2025-10-30 16:31:01 +01:00
|
|
|
_audioSource.audioSource.resource = distractedAudioClips;
|
|
|
|
|
_audioSource.Play(0);
|
2025-10-20 21:01:10 +02:00
|
|
|
}
|
|
|
|
|
|
2025-11-11 08:48:29 +00:00
|
|
|
internal override string OnSceneSaveRequested()
|
|
|
|
|
{
|
|
|
|
|
var state = new PicnicBehaviourState { fakeChocolateDestroyed = _fakeChocolateDestroyed };
|
|
|
|
|
return JsonUtility.ToJson(state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal override void OnSceneRestoreRequested(string serializedData)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(serializedData)) return;
|
2025-10-20 21:01:10 +02:00
|
|
|
|
2025-11-11 08:48:29 +00:00
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var state = JsonUtility.FromJson<PicnicBehaviourState>(serializedData);
|
|
|
|
|
if (state != null)
|
|
|
|
|
{
|
|
|
|
|
_fakeChocolateDestroyed = state.fakeChocolateDestroyed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogWarning($"[PicnicBehaviour] Failed to restore state: {ex.Message}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable]
|
|
|
|
|
public class PicnicBehaviourState
|
|
|
|
|
{
|
|
|
|
|
public bool fakeChocolateDestroyed;
|
2025-09-30 15:52:37 +02:00
|
|
|
}
|