private IEnumerator GenerateMelody(int seed) { if (seed == 0) { seed = System.DateTime.Now.Ticks.GetHashCode(); } curplaying = seed; Random.seed = seed; MelodyGenerator generator = Utils.Utility.RandomElement(generators); Debug.Log(generator + "," + seed); GenericMelody melody = musicCache.ContainsKey(seed)?musicCache[seed]:generator.GenerateMelody(); if (musicCache.ContainsKey(seed) == false) { musicCache[seed] = melody; } // melody.StripToLength(5); StopCoroutine("PlayMelody"); StartCoroutine("PlayMelody", melody); yield break; }
public static void CacheMelody(int seed) { Random.seed = seed; MelodyGenerator generator = Utils.Utility.RandomElement(generators); musicCache[seed] = generator.GenerateMelody(); }