Beispiel #1
0
    GameObject InstantiateChorus(ChorusScriptable c, Vector3 position)
    {
        GameObject go = (GameObject)Instantiate(audioSourcePrefab);

        go.name = c.instrumentName;

        CustomAudioSource source = go.GetComponent <CustomAudioSource>();

        source.SetSound(AudioMixer.Instance.Load(c.path));

        go.transform.SetParent(this.transform);
        go.AddComponent <Image>();
        go.GetComponent <Image>().sprite = c.instrumentImage;
        go.transform.localScale          = Vector3.one;
        go.transform.localPosition       = 10 * position;

        orchestraPrefab.AddSource(source);

        VolumeDisplay volume = Instantiate(VolumeDislayer, go.transform);

        volume.transform.localPosition = new Vector3(100, -50, 0);
        volume.Source = go.GetComponent <CustomAudioSource>();

        return(go);
    }
Beispiel #2
0
    public void DisplayAndPlayMusicInstrument()
    {
        DestroyEverything(); string folderName = DropdownMusic.options[DropdownMusic.value].text;
        string musicFolderPath = _dictionnaryMusic[folderName];
        var    score           = (GameObject)Resources.Load(folderName + "/" + folderName + "Score", typeof(GameObject));

        if (score != null)
        {
            Debug.Log(score);
            score = Instantiate(score, transform);
        }
        int i = 1;

        foreach (var track in Directory.GetFiles(musicFolderPath).Where(n => (Path.GetExtension(n) == ".mp3") || (Path.GetExtension(n) == ".wav")))
        {
            Slider slider = Instantiate(VolumeSlider);

            slider.transform.SetParent(Canvas.transform, false);
            slider.transform.Translate(new Vector3(-20, -i, 0));
            slider.onValueChanged.AddListener(delegate { ChangeVolume(slider, Path.GetFileName(track)); });


            Button goButton = Instantiate(MuteButton);
            goButton.transform.SetParent(Canvas.transform, false);
            goButton.GetComponentInChildren <Text>().text = Path.GetFileName(track);
            goButton.transform.Translate(new Vector3(i, 0, 0));
            goButton.transform.localScale = new Vector3(0.85f, 1, 1);

            goButton.onClick.AddListener(() =>
            {
                if (_sources.ContainsKey(goButton.GetComponentInChildren <Text>().text))
                {
                    if (Math.Abs(_sources[goButton.GetComponentInChildren <Text>().text].Volume) > 0.2)
                    {
                        _sources[goButton.GetComponentInChildren <Text>().text].Volume = 0;
                        slider.value = 0;
                    }
                    else
                    {
                        _sources[goButton.GetComponentInChildren <Text>().text].Volume = 1;
                        slider.value = 1;
                    }
                }
            });

            FMOD.Sound        sound  = _audioMixer.Load(track);
            CustomAudioSource source = Instantiate(SourcePrefab).GetComponent <CustomAudioSource>();
            OrchestraPrefab.AddSource(source);
            source.SetSound(sound);

            _sources.Add(Path.GetFileName(track), source);

            _sliders[slider] = source;
            Source           = source;
            i += 30;
        }
        //OrchestraPrefab.MutedSourceJustForDefaultSpeed;
        foreach (var source in _sources)
        {
            source.Value.Play();
        }
    }