Exemple #1
0
    private IEnumerator FadeToNext(OAThemeTracks previous)
    {
        // TODO: Fade duration, overlap in fade ...
        float time = 0f;

        while (source.volume > 0 && time < 1f)
        {
            source.volume = previous.fadeOut.Evaluate(time);
            yield return(new WaitForFixedUpdate()); // We use fixed and not normal update as there seems to be no normal update wait

            time += Time.fixedDeltaTime;
        }

        // TODO: avoid previous track if possible
        int trackIndex = Random.Range(0, selected.clips.Count);

        source.clip   = selected.clips[trackIndex];
        trackDuration = selected.clips[trackIndex].length;
        trackCursor   = 0f;
        source.Play();
        time = 0f;
        while (source.volume < 1 && time < 1f)
        {
            source.volume = selected.fadeIn.Evaluate(time);
            yield return(new WaitForFixedUpdate());

            time += (Time.fixedDeltaTime / selected.fadeDuration);
        }
    }
Exemple #2
0
    public void SetTheme(int key)
    {
        themeKey = key;
        previous = selected;
        if (!themes.TryGetValue(themeKey, out selected))
        {
#if UNITY_EDITOR
            Debug.LogError("Attempted to get a theme that does not exist");
            selected = previous;
#endif
        }

        // Incase we are already fading
        StopAllCoroutines();
        StartCoroutine(FadeToNext(previous));
    }
Exemple #3
0
    // Start is called before the first frame update
    void Awake()
    {
        themes = new Dictionary <int, OAThemeTracks>();

        selected = editorThemes[0];

        // Move all tracks to a hashset
        foreach (var track in editorThemes)
        {
            themes.Add(track.GetHashCode(), track);
        }

        // Clear the list as it is not needed anymore
        editorThemes.Clear();

        source = GetComponent <AudioSource>();
    }