FiE-Game/Assets/Scripts/Fie/Footstep/FieFootstepPlayer.cs

55 lines
1.2 KiB
C#
Raw Normal View History

2018-11-20 20:10:49 +01:00
using ParticlePlayground;
using UnityEngine;
using UnityEngine.SceneManagement;
2018-11-21 21:16:20 +01:00
namespace Fie.Footstep {
/// <summary>
/// An audio player for playing audio clips under a player.
/// </summary>
public class FieFootstepPlayer : MonoBehaviour {
2018-11-20 20:10:49 +01:00
[SerializeField]
private AudioSource _audioSource;
[SerializeField]
private PlaygroundParticlesC _particle;
[SerializeField]
private float _pitchOffset = 1f;
private float _particleDuration;
public AudioSource audioSource => _audioSource;
public float pitchOffset => _pitchOffset;
2018-11-21 21:16:20 +01:00
public void EmitFootstepParticle(float duration) {
2018-11-20 20:10:49 +01:00
_particleDuration = duration;
}
2018-11-21 21:16:20 +01:00
public void SetMaterial(Material material) {
2018-11-20 20:10:49 +01:00
_particle.particleSystemRenderer.material = material;
}
2018-11-21 21:16:20 +01:00
private void Update() {
bool flag = _particleDuration > 0;
2018-11-20 20:10:49 +01:00
_particle.emit = flag;
2018-11-21 21:16:20 +01:00
if (flag) {
2018-11-20 20:10:49 +01:00
_particleDuration -= Time.deltaTime;
}
}
2018-11-21 21:16:20 +01:00
private void Awake() {
2018-11-20 20:10:49 +01:00
SceneManager.sceneLoaded += SceneManager_sceneLoaded;
}
2018-11-21 21:16:20 +01:00
/// <summary>
/// Called when the scene is loaded.
/// </summary>
private void SceneManager_sceneLoaded(UnityEngine.SceneManagement.Scene scene, LoadSceneMode mode) {
if ((bool)_particle) {
2018-11-20 20:10:49 +01:00
_particle.Start();
}
}
}
}