bounce sound avoid duplication

This commit is contained in:
fu-majime 2024-04-09 23:53:44 +09:00
parent ff44126316
commit 153459432a
2 changed files with 14 additions and 12 deletions

View file

@ -1,5 +1,3 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyBezierCurves;
@ -48,12 +46,7 @@ namespace HeavenStudio.Games.Scripts_BouncyRoad
private void Bounce()
{
var sounds = new List<MultiSound.Sound>();
for (int i = 0; i < 12 ; i++)
{
sounds.Add(new MultiSound.Sound("bouncyRoad/ballBounce", startBeat + i * lengthBeat));
}
MultiSound.Play(sounds.ToArray());
game.PlayBounceSound(startBeat, lengthBeat);
var actions = new List<BeatAction.Action>();

View file

@ -1,6 +1,4 @@
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using NaughtyBezierCurves;
@ -8,8 +6,6 @@ using NaughtyBezierCurves;
using HeavenStudio.Util;
using HeavenStudio.InputSystem;
using Jukebox;
namespace HeavenStudio.Games.Loaders
{
using static Minigames;
@ -238,6 +234,19 @@ namespace HeavenStudio.Games
});
}
List<double> bounceBeats = new();
public void PlayBounceSound(double beat, double length)
{
var sounds = new List<MultiSound.Sound>();
for (int i = 0; i < 12 ; i++)
{
var bounceBeat = beat + i * length;
if (!bounceBeats.Contains(bounceBeat)) sounds.Add(new MultiSound.Sound("bouncyRoad/ballBounce", bounceBeat));
bounceBeats.Add(bounceBeat);
}
MultiSound.Play(sounds.ToArray());
}
private Transform GenerateInitCurve(Vector3 pos1, Vector3 pos2)
{
float dist = Vector3.Distance(pos1, pos2);