Skip to content

Commit

Permalink
do not play scene change animation sound in some cases
Browse files Browse the repository at this point in the history
  • Loading branch information
achimmihca committed Aug 20, 2022
1 parent 56861f8 commit 97d6d34
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
6 changes: 6 additions & 0 deletions UltraStar Play/Assets/Common/Scene/ESceneUtils.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
using System.Linq;
using UnityEngine.SceneManagement;

public static class ESceneUtils
{
public static EScene GetCurrentScene()
{
return GetSceneByBuildIndex(SceneManager.GetActiveScene().buildIndex);
}

public static EScene GetSceneByBuildIndex(int buildIndex)
{
return EnumUtils.GetValuesAsList<EScene>()
Expand Down
8 changes: 6 additions & 2 deletions UltraStar Play/Assets/Common/Scene/SceneNavigator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ public void LoadScene(SceneEnumHolder holder)

public void LoadScene(EScene scene)
{
EScene currentScene = ESceneUtils.GetCurrentScene();

beforeSceneChangeEventStream.OnNext(new BeforeSceneChangeEvent(scene));

Action doChangeScene = () => SceneManager.LoadScene((int)scene);

if (settings.GraphicSettings.AnimateSceneChange)
{
sceneChangeAnimationControl.AnimateChangeToScene(
doChangeScene,
sceneChangeAnimationControl.StartSceneChangeAnimation);
(visualElement) => sceneChangeAnimationControl.StartSceneChangeAnimation(
visualElement,
currentScene,
scene));
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ public override void Start()
}
}

public void StartSceneChangeAnimation(VisualElement visualElement)
public void StartSceneChangeAnimation(VisualElement visualElement, EScene currentScene, EScene nextScene)
{
bool skipSceneChangeAnimationSound = nextScene == EScene.SingScene
|| currentScene == EScene.SingingResultsScene;
if (!skipSceneChangeAnimationSound)
{
PlaySceneChangeAnimationSound();
}

LeanTween.value(gameObject, 0, 1, 0.3f)
.setOnUpdate((float animTimePercent) =>
{
Expand All @@ -60,8 +67,11 @@ public void StartSceneChangeAnimation(VisualElement visualElement)
})
.setOnComplete(() => visualElement.RemoveFromHierarchy())
.setEaseInSine();
}

audioSource.volume = settings.AudioSettings.SceneChangeSoundVolumePercent;
private void PlaySceneChangeAnimationSound()
{
audioSource.volume = settings.AudioSettings.SceneChangeSoundVolumePercent / 100f;
audioSource.Play();
}

Expand Down

0 comments on commit 97d6d34

Please sign in to comment.