public void ChangeBackground(ShuffleOptions toDo) { switch (toDo) { // pasa a la siguiente cancion case ShuffleOptions.Next: currentIndexSelected = Mathf.Clamp(currentIndexSelected + 1, 0, sceneBackgrounds.Count - 1); print(currentIndexSelected); print(sceneBackgrounds.Count - 1); this.sprRendBg.sprite = sceneBackgrounds[currentIndexSelected]; //animator.Play("changingBackground"); break; // arma una nueva lista con los loops case ShuffleOptions.Reset: currentIndexSelected = 0; LoadSceneBackgroundList(); break; // elige un indice actual aleatorio dentro de la lista? case ShuffleOptions.Random: Debug.Log("Random picked shuffle (idx) " + this.name); break; } }
public void ChangeLoops(ShuffleOptions toDo) { switch (toDo) { // pasa a la siguiente cancion case ShuffleOptions.Next: currentIndexSelected++; if (currentIndexSelected >= sceneLoops.Count) // termino y se sale { gameManager.OnWin(); } else { PlayBackgroundAndMusic(sceneLoops[currentIndexSelected]); } break; // arma una nueva lista con los loops case ShuffleOptions.Reset: currentIndexSelected = 0; LoadSceneLoopList(); break; // elige un indice actual aleatorio dentro de la lista? case ShuffleOptions.Random: //Debug.Log("Random picked shuffle (idx) " + this.name); break; } }
public void TestShuffle() { var clip = new Clip(4, true) { Notes = new SortedList <NoteEvent>() { new NoteEvent(60, 0, .5m, 100), new NoteEvent(62, .5m, .5m, 100), new NoteEvent(64, 1, .5m, 100), new NoteEvent(66, 1.5m, .5m, 100), new NoteEvent(68, 2, .5m, 100), new NoteEvent(70, 2.5m, .5m, 100) } }; var byClip = new Clip(4, true) { Notes = new SortedList <NoteEvent>() { new NoteEvent(40, 0, .5m, 100), new NoteEvent(41, 1, .5m, 100), new NoteEvent(42, 2, .5m, 100) } }; var options = new ShuffleOptions() { By = byClip }; var resultObj = Shuffle.Apply(options, clip); Assert.IsTrue(resultObj.Success); var result = resultObj.Result[0]; Assert.AreEqual(60, result.Notes[0].Pitch); Assert.AreEqual(64, result.Notes[1].Pitch); Assert.AreEqual(68, result.Notes[2].Pitch); Assert.AreEqual(62, result.Notes[3].Pitch); Assert.AreEqual(66, result.Notes[4].Pitch); Assert.AreEqual(70, result.Notes[5].Pitch); }
public static ProcessResult <Clip[]> Apply(ShuffleOptions options, params Clip[] clips) { if (options.By.Notes.Count == 0) { options.By = clips[0]; } if (options.By.Count == 0 && options.ShuffleValues.Length == 0) { return(new ProcessResult <Clip[]>("No -by clip or shuffle values specified.")); } ClipUtilities.Monophonize(options.By); var targetClips = new Clip[clips.Length]; int[] shuffleValues; if (options.ShuffleValues.Length == 0) { int minPitch = options.By.Notes.Min(x => x.Pitch); shuffleValues = options.By.Notes.Select(x => x.Pitch - minPitch).ToArray(); } else { shuffleValues = options.ShuffleValues.Select(x => Math.Clamp(x, 1, 100) - 1).ToArray(); } var c = 0; foreach (var clip in clips) // we only support one generated clip since these are tied to a specific clip slot. Maybe support multiple clips under the hood, but discard any additional clips when sending the output is the most flexible approach. { clip.GroupSimultaneousNotes(); targetClips[c] = new Clip(clip.Length, clip.IsLooping); var numShuffleIndexes = shuffleValues.Length; if (numShuffleIndexes < clip.Notes.Count) { numShuffleIndexes = clip.Notes.Count; } var indexes = new int[numShuffleIndexes]; for (var i = 0; i < numShuffleIndexes; i++) { // Calc shuffle indexes as long as there are notes in the source clip. If the clip to be shuffled contains more events than the source, add zero-indexes so that the rest of the sequence is produced sequentially. if (i < shuffleValues.Length) { indexes[i] = (int)Math.Floor(((float)shuffleValues[i] / clip.Notes.Count) * clip.Notes.Count); } else { indexes[i] = 0; } } // preserve original durations until next note var durationUntilNextNote = new List <decimal>(clip.Notes.Count); for (var i = 0; i < clip.Notes.Count; i++) { durationUntilNextNote.Add(clip.DurationUntilNextNote(i)); } // do shuffle var j = 0; decimal pos = 0m; while (clip.Notes.Count > 0) { int currentIx = indexes[j++] % clip.Notes.Count; targetClips[c].Notes.Add( clip.Notes[currentIx] with { Start = pos }