Skip to content

Commit c3c97af

Browse files
committed
Added Pause/Unpause example to the demo scene
1 parent e500f5d commit c3c97af

File tree

9 files changed

+5939
-1485
lines changed

9 files changed

+5939
-1485
lines changed

Assets/BroAudio/Demo/Demo.unity

Lines changed: 3093 additions & 1352 deletions
Large diffs are not rendered by default.

Assets/BroAudio/Demo/Demo_URP.unity

Lines changed: 1856 additions & 106 deletions
Large diffs are not rendered by default.

Assets/BroAudio/Demo/Environment/Prefabs/LightingButton.prefab

Lines changed: 817 additions & 0 deletions
Large diffs are not rendered by default.

Assets/BroAudio/Demo/Environment/Prefabs/LightingButton.prefab.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using Ami.Extension;
2+
using UnityEngine;
3+
4+
public class FloatingAnimation : MonoBehaviour
5+
{
6+
[SerializeField] private Vector3 _maxMovement;
7+
[SerializeField] private float _speed;
8+
[SerializeField] private float _delayTime;
9+
[SerializeField] private Ease _ease;
10+
11+
private float _deltaTime;
12+
private bool _hasStarted = false;
13+
private Vector3 _startPosition;
14+
private bool _isReturning = false;
15+
16+
void Start()
17+
{
18+
_startPosition = transform.localPosition;
19+
}
20+
21+
void Update()
22+
{
23+
if (!_hasStarted)
24+
{
25+
_deltaTime += Time.deltaTime;
26+
if (_deltaTime < _delayTime)
27+
{
28+
return;
29+
}
30+
else
31+
{
32+
_hasStarted = true;
33+
_deltaTime = 0f;
34+
}
35+
}
36+
37+
_deltaTime += Time.deltaTime * _speed;
38+
float t = Mathf.Clamp01(_deltaTime);
39+
40+
Vector3 target = !_isReturning
41+
? Vector3.Lerp(_startPosition, _startPosition + _maxMovement, t.SetEase(_ease))
42+
: Vector3.Lerp(_startPosition + _maxMovement, _startPosition, t.SetEase(_ease));
43+
44+
transform.localPosition = target;
45+
46+
if (t >= 1f)
47+
{
48+
_isReturning = !_isReturning;
49+
_deltaTime = 0f;
50+
}
51+
}
52+
}

Assets/BroAudio/Demo/Scripts/FloatingAnimation.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,35 @@
11
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
42
using UnityEngine;
53

64
namespace Ami.BroAudio.Demo
75
{
8-
[RequireComponent(typeof(Collider))]
9-
public class InteractiveZone : MonoBehaviour
10-
{
11-
public event Action<bool> OnInZoneStateChanged;
6+
[RequireComponent(typeof(Collider))]
7+
public class InteractiveZone : MonoBehaviour
8+
{
9+
public event Action<bool> OnInZoneStateChanged;
1210

13-
public bool IsInZone { get; private set; } = false;
14-
public GameObject InZoneObject { get; private set; }
11+
public bool IsInZone { get; private set; } = false;
12+
public GameObject InZoneObject { get; private set; }
1513

16-
private void OnTriggerEnter(Collider other)
17-
{
18-
if (!IsInZone && other.gameObject.CompareTag("Player"))
19-
{
20-
IsInZone = true;
21-
InZoneObject = other.gameObject;
22-
OnInZoneStateChanged?.Invoke(true);
23-
}
24-
}
14+
private void OnTriggerEnter(Collider other)
15+
{
16+
if (!IsInZone && other.gameObject.CompareTag("Player"))
17+
{
18+
IsInZone = true;
19+
InZoneObject = other.gameObject;
20+
OnInZoneStateChanged?.Invoke(true);
21+
}
22+
}
2523

26-
private void OnTriggerExit(Collider other)
27-
{
28-
if (IsInZone && other.gameObject.CompareTag("Player"))
29-
{
30-
IsInZone = false;
31-
InZoneObject = null;
32-
OnInZoneStateChanged?.Invoke(false);
33-
}
34-
}
35-
}
24+
private void OnTriggerExit(Collider other)
25+
{
26+
if (IsInZone && other.gameObject.CompareTag("Player"))
27+
{
28+
IsInZone = false;
29+
InZoneObject = null;
30+
OnInZoneStateChanged?.Invoke(false);
31+
}
32+
}
33+
}
3634

3735
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using UnityEngine;
2+
3+
namespace Ami.BroAudio.Demo
4+
{
5+
public class PlaybackButtonController : InteractiveComponent
6+
{
7+
[Header("Pause Settings")]
8+
[SerializeField] private SoundID _target;
9+
[SerializeField] private float _fadeOut;
10+
11+
[Header("Other Settings")]
12+
[SerializeField] private GameObject _pauseButton;
13+
[SerializeField] private GameObject _resumeButton;
14+
[SerializeField] private bool _isPauseOnStart;
15+
[Space]
16+
[SerializeField] private SoundID _switchSound;
17+
[SerializeField, Volume] private float _switchSoundVolume;
18+
[SerializeField, Pitch] private float _switchSoundPitch;
19+
[SerializeField] private float _switchSoundDuration;
20+
[SerializeField] private int _switchSoundVelocity;
21+
22+
private bool _isPaused;
23+
24+
private void SwitchPauseState()
25+
{
26+
if (_isPaused)
27+
{
28+
BroAudio.Pause(_target, _fadeOut);
29+
}
30+
else
31+
{
32+
BroAudio.UnPause(_target);
33+
}
34+
35+
_pauseButton.SetActive(_isPaused);
36+
_resumeButton.SetActive(!_isPaused);
37+
}
38+
39+
private void Start()
40+
{
41+
_isPaused = _isPauseOnStart;
42+
SwitchPauseState();
43+
}
44+
45+
public override void OnInZoneChanged(bool isInZone)
46+
{
47+
base.OnInZoneChanged(isInZone);
48+
49+
if(isInZone)
50+
{
51+
_isPaused = !_isPaused;
52+
SwitchPauseState();
53+
PlaySwitchSound();
54+
}
55+
}
56+
57+
private void PlaySwitchSound()
58+
{
59+
BroAudio.Play(_switchSound)
60+
.SetVelocity(_switchSoundVelocity)
61+
.SetPitch(_switchSoundPitch)
62+
.SetVolume(_switchSoundVolume)
63+
.SetScheduledStartTime(AudioSettings.dspTime)
64+
.SetScheduledEndTime(AudioSettings.dspTime + _switchSoundDuration);
65+
}
66+
}
67+
}

Assets/BroAudio/Demo/Scripts/PlaybackButtonController.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)