Skip to content

Instantly share code, notes, and snippets.

@beardordie
Created November 7, 2019 08:54
Show Gist options
  • Save beardordie/9d216da211e5e20b29d2fdee53f4513c to your computer and use it in GitHub Desktop.
Save beardordie/9d216da211e5e20b29d2fdee53f4513c to your computer and use it in GitHub Desktop.
Corgi Engine custom Feedbacks type, same as "Corgi Engine Sound" but allows you to specify an AudioSource. Useful if you want to share an audiosource for a Start and Stop sound, such as for Jetpack ability, so the looping jetpacking sound is replaced by the one-time jetpack-stopped sound.
using UnityEngine;
using System.Collections;
using MoreMountains.Tools;
using System;
using System.Collections.Generic;
using MoreMountains.Feedbacks;
using UnityEngine.Audio;
namespace MoreMountains.CorgiEngine
{
[AddComponentMenu("")]
[FeedbackPath("Sounds/Corgi Engine Sound Extended")]
[FeedbackHelp("This feedback lets you play a sound through the Corgi Engine's SoundManager with a specified AudioSource")]
public class CorgiEngineSoundExtendedFeedback : MMFeedback
{
[Header("Corgi Engine Sound Extended")]
public AudioClip SoundFX;
public bool Loop = false;
public AudioSource _audioSource;
protected override void CustomPlayFeedback(Vector3 position, float attenuation = 1.0f)
{
if (Active)
{
if (SoundFX != null)
{
_audioSource.clip = SoundFX;
_audioSource.loop = Loop;
_audioSource.Play();
}
}
}
/// <summary>
/// This method describes what happens when the feedback gets stopped
/// </summary>
/// <param name="position"></param>
/// <param name="attenuation"></param>
protected override void CustomStopFeedback(Vector3 position, float attenuation = 1.0f)
{
if (Loop)
{
_audioSource.Stop();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment