Files
AppleHillsProduction/Assets/Scripts/StateMachines/CementFactory/MrCementBehavior.cs
2025-12-18 19:53:22 +01:00

131 lines
4.2 KiB
C#

using AudioSourceEvents;
using Levels;
using MoreMountains.Feedbacks;
using System;
using System.Diagnostics.Tracing;
using UnityEditor.Animations;
using UnityEngine;
using UnityEngine.Audio;
public class MrCementBehavior : MonoBehaviour
{
private MMF_Player _feedbackPlayer;
private Animator _animator;
private AppleAudioSource _appleAudioSource;
private IAudioEventSource _eventSource;
public AudioResource wheelAudioClip;
public AudioResource cogAudioClip;
public AudioResource beltAudioClip;
public AudioResource propellerAudioClip;
public AudioResource[] partsLeftClips;
public FactoryGameStats factoryGameStats;
public GameObject glowOutline;
public GameObject levelSwitcher;
public void Start()
{
_feedbackPlayer = GetComponent<MMF_Player>();
_animator = GetComponent<Animator>();
_appleAudioSource = GetComponent<AppleAudioSource>();
}
public void PlayCementAngry()
{
_feedbackPlayer.PauseFeedbacks();
_animator.SetTrigger("isAngry");
}
public void ContinuePatrol()
{
_feedbackPlayer.ResumeFeedbacks();
}
public void PlayCementFeedback(string partName)
{
switch (partName)
{
case "cog":
_feedbackPlayer.PauseFeedbacks();
_animator.SetTrigger("isHappy");
_appleAudioSource.audioSource.resource = cogAudioClip;
_appleAudioSource.Play(0);
_eventSource = _appleAudioSource.audioSource.RequestEventHandlers();
_eventSource.AudioStopped += StoppedTalking;
factoryGameStats.PartFound();
break;
case "wheel":
_feedbackPlayer.PauseFeedbacks();
_animator.SetTrigger("isHappy");
_appleAudioSource.audioSource.resource = wheelAudioClip;
_appleAudioSource.Play(0);
_eventSource = _appleAudioSource.audioSource.RequestEventHandlers();
_eventSource.AudioStopped += StoppedTalking;
factoryGameStats.PartFound();
break;
case "belt":
_feedbackPlayer.PauseFeedbacks();
_animator.SetTrigger("isHappy");
_appleAudioSource.audioSource.resource = beltAudioClip;
_appleAudioSource.Play(0);
_eventSource = _appleAudioSource.audioSource.RequestEventHandlers();
_eventSource.AudioStopped += StoppedTalking;
factoryGameStats.PartFound();
break;
case "propeller":
_feedbackPlayer.PauseFeedbacks();
_animator.SetTrigger("isHappy");
_appleAudioSource.audioSource.resource = propellerAudioClip;
_appleAudioSource.Play(0);
_eventSource = _appleAudioSource.audioSource.RequestEventHandlers();
_eventSource.AudioStopped += StoppedTalking;
factoryGameStats.PartFound();
break;
}
}
private void StoppedTalking(object sender, EventArgs e)
{
_eventSource.AudioStopped -= StoppedTalking;
switch (factoryGameStats.partsFoundInLevel)
{
case 1:
_appleAudioSource.audioSource.resource = partsLeftClips[0];
_appleAudioSource.Play(0);
break;
case 2:
_appleAudioSource.audioSource.resource = partsLeftClips[1];
_appleAudioSource.Play(0);
break;
case 3:
_appleAudioSource.audioSource.resource = partsLeftClips[2];
_appleAudioSource.Play(0);
break;
case 4:
_appleAudioSource.audioSource.resource = partsLeftClips[3];
_appleAudioSource.Play(0);
EnableMiniGameTrigger();
break;
}
}
private void EnableMiniGameTrigger()
{
// stop feedback
_feedbackPlayer.StopFeedbacks();
// happy loop animation
_animator.SetBool("allPartsFound", true);
// enable glowoutline
glowOutline.SetActive(true);
// enable minigameswitcher
levelSwitcher.SetActive(true);
}
}