Butterfly Distraction

This commit is contained in:
DamianCorazza
2025-11-14 00:04:33 +01:00
parent c08fc4a720
commit 19be64a75f
8 changed files with 452 additions and 39 deletions

View File

@@ -5,6 +5,7 @@ public class ButterflyFreeBehaviour : MonoBehaviour
{
public GameObject butterflyRef;
private Animator butterflyAnimator;
public PicnicBehaviour picnicRef;
public void OnEnable()
{
if (butterflyRef != null)
@@ -12,6 +13,7 @@ public class ButterflyFreeBehaviour : MonoBehaviour
butterflyAnimator = butterflyRef.GetComponentInChildren<Animator>();
}
butterflyAnimator.SetTrigger("IsFree");
picnicRef.EnterDistractedState();
Debug.Log("ButterflyFreeBehaviour enabled");
}

View File

@@ -8,12 +8,6 @@ using UnityEngine.Audio;
public class PicnicBehaviour : ManagedBehaviour
{
[Header("Random Call Settings")]
public float getDistractedMin = 2f;
public float getDistractedMax = 5f;
public float getFlirtyMin = 1f;
public float getFlirtyMax = 3f;
private AppleMachine stateMachine;
private Animator animator;
@@ -32,6 +26,7 @@ public class PicnicBehaviour : ManagedBehaviour
// Runtime state tracking
private bool _fakeChocolateDestroyed;
private bool _isDistracted; // track current explicit state so it can be saved
internal override void OnManagedAwake()
{
@@ -48,28 +43,37 @@ public class PicnicBehaviour : ManagedBehaviour
}
else
{
StartCoroutine(StateCycleRoutine());
// Restore the saved state (distracted or chilling) and wait for external control to change states.
if (_isDistracted)
EnterDistractedState();
else
EnterChillingState();
}
}
private IEnumerator StateCycleRoutine()
// Manual state control methods (replaces automatic timer-based switching)
public void EnterDistractedState()
{
while (true)
{
// Distracted state
float distractedWait = UnityEngine.Random.Range(getDistractedMin, getDistractedMax);
stateMachine.ChangeState("Picnic PPL Distracted");
animator.SetBool("theyDistracted", true);
_audioSource.Stop();
yield return new WaitForSeconds(distractedWait);
if (stateMachine == null) stateMachine = GetComponent<AppleMachine>();
if (animator == null) animator = GetComponent<Animator>();
if (_audioSource == null) _audioSource = GetComponent<AppleAudioSource>();
// Chilling state
float chillingWait = UnityEngine.Random.Range(getFlirtyMin, getFlirtyMax);
stateMachine.ChangeState("Picnic PPL Chilling");
animator.SetBool("theyDistracted", false);
_audioSource.Stop();
yield return new WaitForSeconds(chillingWait);
}
_audioSource.Stop();
stateMachine.ChangeState("Picnic PPL Distracted");
animator.SetBool("theyDistracted", true);
_isDistracted = true;
}
public void EnterChillingState()
{
if (stateMachine == null) stateMachine = GetComponent<AppleMachine>();
if (animator == null) animator = GetComponent<Animator>();
if (_audioSource == null) _audioSource = GetComponent<AppleAudioSource>();
_audioSource.Stop();
stateMachine.ChangeState("Picnic PPL Chilling");
animator.SetBool("theyDistracted", false);
_isDistracted = false;
}
public void triedToStealChocolate()
@@ -122,7 +126,7 @@ public class PicnicBehaviour : ManagedBehaviour
internal override string OnSceneSaveRequested()
{
var state = new PicnicBehaviourState { fakeChocolateDestroyed = _fakeChocolateDestroyed };
var state = new PicnicBehaviourState { fakeChocolateDestroyed = _fakeChocolateDestroyed, isDistracted = _isDistracted };
return JsonUtility.ToJson(state);
}
@@ -136,6 +140,7 @@ public class PicnicBehaviour : ManagedBehaviour
if (state != null)
{
_fakeChocolateDestroyed = state.fakeChocolateDestroyed;
_isDistracted = state.isDistracted;
}
}
catch (Exception ex)
@@ -149,4 +154,5 @@ public class PicnicBehaviour : ManagedBehaviour
public class PicnicBehaviourState
{
public bool fakeChocolateDestroyed;
public bool isDistracted;
}