Holds references to all the different audio sources.
Inheritance: MonoBehaviour
Esempio n. 1
0
        public AudioSettingsViewModel(PropertyAudioViewModel property, TrackableViewModel parent) : base(property, parent)
        {
            AudioSources.AddRange(AudioHelper.GetAudioSources());


            UpdateAudioSourcesCommand = new Prism.Commands.DelegateCommand(UpdateSources);
        }
Esempio n. 2
0
    /*
     * public void Play(Color colour, float velocity = 10, float length = 1, float speed = 1)
     * {
     *      if (PianoKeyController.ShowMIDIChannelColours)
     *      {
     *              _colour = colour;
     *      }
     *
     *      this.Play(velocity, length, speed);
     * }
     */
    #endregion

    //WE NEED TO CHECK THIS IENUMERATOR BECAUSE ROTATION AFFECTS VOLUME AND WE DON'T NEED ROTATION..
    //UPDATE :: Apparently this was only for KayMode.Physical
    #region [------------	THE VOLUME DEPENDS OF THE ROTATION OF THE KEY BUT WE DONT HAVE A PIANO KEY..------------]

    /*
     * [Obsolete("We need to check this Ienumerator")]
     * IEnumerator PlayPressedAudio()
     * {
     * if (!PianoKeyController.NoMultiAudioSource && CurrentAudioSource.isPlaying)
     * {
     * bool foundReplacement = false;
     * int index = AudioSources.IndexOf(CurrentAudioSource);
     *
     * for (int i = 0; i < AudioSources.Count; i++)
     * {
     *      if (i != index && (!AudioSources[i].isPlaying || AudioSources[i].volume <= 0))
     *      {
     *              foundReplacement = true;
     *              CurrentAudioSource = AudioSources[i];
     *              _toFade.Remove(AudioSources[i]);
     *              break;
     *      }
     * }
     *
     * if (!foundReplacement)
     * {
     *      AudioSource newAudioSource = CloneAudioSource();
     *      AudioSources.Add(newAudioSource);
     *      CurrentAudioSource = newAudioSource;
     * }
     *
     * _toFade.Add(AudioSources[index]);
     * }
     *
     * _startAngle = transform.eulerAngles.x;
     *
     * yield return new WaitForFixedUpdate();
     * yield return new WaitForFixedUpdate(); // two yields in a row? mmm wtf okay..
     *
     *
     * if (Mathf.Abs(_startAngle - transform.eulerAngles.x) > 0)
     * {
     * CurrentAudioSource.volume = Mathf.Lerp(0, 1, Mathf.Clamp((Mathf.Abs(_startAngle - transform.eulerAngles.x) / 2f), 0, 1));
     * }
     *
     * CurrentAudioSource.Play();
     * }
     */

    #endregion

    void PlayVirtualAudio()
    {
        if (!PianoKeyController.NoMultiAudioSource && CurrentAudioSource.isPlaying)
        {
            bool foundReplacement = false;
            int  index            = AudioSources.IndexOf(CurrentAudioSource);

            for (int i = 0; i < AudioSources.Count; i++)
            {
                if (i != index && (!AudioSources[i].isPlaying || AudioSources[i].volume <= 0))
                {
                    foundReplacement   = true;
                    CurrentAudioSource = AudioSources[i];
                    _toFade.Remove(AudioSources[i]);
                    break;
                }
            }

            if (!foundReplacement)
            {
                AudioSource newAudioSource = CloneAudioSource();
                AudioSources.Add(newAudioSource);
                CurrentAudioSource = newAudioSource;
            }

            _toFade.Add(AudioSources[index]);
        }

        CurrentAudioSource.volume = _velocity / 127f;

        CurrentAudioSource.Play();
    }
Esempio n. 3
0
        public void UpdateSources()
        {
            AudioSources.Clear();

            AudioSources.AddRange(AudioHelper.GetAudioSources(true));

            ((PropertyAudioViewModel)this.Property).SelectedSource = AudioSources.FirstOrDefault();
        }
Esempio n. 4
0
	// Use this for initialization
	void Awake ()
	{
		if (audioSourcesInstance == null) {
			audioSourcesInstance = this;
			DontDestroyOnLoad(transform.root.gameObject);
		} else {
			Destroy (gameObject);
		}
	}
    //Remove a HDR audio source to the collection
    public void RemoveAudioSource(HDRAudioSource source)
    {
        int index = AudioSources.FindIndex(p => p.Audio == source);

        if (index != -1)
        {
            AudioSources.RemoveAt(index);
        }
    }
        /// <summary>
        /// Generate the necessary parameters
        /// </summary>
        public List <KeyValuePair <string, string> > GetParams()
        {
            var p = new List <KeyValuePair <string, string> >();

            if (FriendlyName != null)
            {
                p.Add(new KeyValuePair <string, string>("FriendlyName", FriendlyName));
            }

            if (Enabled != null)
            {
                p.Add(new KeyValuePair <string, string>("Enabled", Enabled.Value.ToString().ToLower()));
            }

            if (VideoLayout != null)
            {
                p.Add(new KeyValuePair <string, string>("VideoLayout", Serializers.JsonObject(VideoLayout)));
            }

            if (AudioSources != null)
            {
                p.AddRange(AudioSources.Select(prop => new KeyValuePair <string, string>("AudioSources", prop)));
            }

            if (AudioSourcesExcluded != null)
            {
                p.AddRange(AudioSourcesExcluded.Select(prop => new KeyValuePair <string, string>("AudioSourcesExcluded", prop)));
            }

            if (Trim != null)
            {
                p.Add(new KeyValuePair <string, string>("Trim", Trim.Value.ToString().ToLower()));
            }

            if (Format != null)
            {
                p.Add(new KeyValuePair <string, string>("Format", Format.ToString()));
            }

            if (Resolution != null)
            {
                p.Add(new KeyValuePair <string, string>("Resolution", Resolution));
            }

            if (StatusCallback != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallback", Serializers.Url(StatusCallback)));
            }

            if (StatusCallbackMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallbackMethod", StatusCallbackMethod.ToString()));
            }

            return(p);
        }
Esempio n. 7
0
        private ExtendedAudioSource CreateAudioInstance(int index = 1)
        {
            var go     = new GameObject("AudioInstance " + index, typeof(ExtendedAudioSource));
            var source = go.GetComponent <ExtendedAudioSource>();

            go.transform.SetParent(Trans);
            AudioSources.Add(source);
            go.SetActive(false);
            return(source);
        }
Esempio n. 8
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
 }
Esempio n. 9
0
 // Use this for initialization
 void Awake()
 {
     if (audioSourcesInstance == null)
     {
         audioSourcesInstance = this;
         DontDestroyOnLoad(transform.root.gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Esempio n. 10
0
        public ExtendedAudioSource GetAudioSource()
        {
            foreach (var source in AudioSources.Where(source => source.isPlaying == false))
            {
                source.gameObject.SetActive(true);
                ActiveAudioSources.Add(source);
                return(source);
            }
            var newSource = CreateAudioInstance();

            newSource.gameObject.SetActive(true);
            return(newSource);
        }
Esempio n. 11
0
 // Use this for initialization
 void Awake()
 {
     if (instance == null)
     {
         instance     = this;
         audioSources = GetComponents <AudioSource>();
         DontDestroyOnLoad(gameObject);
     }
     else
     {
         Destroy(gameObject);
     }
 }
Esempio n. 12
0
        public void Remove(SourceComponent audioSource)
        {
            SoundToolKitDebug.Assert(audioSource != null, "Source component is null");

            if (AudioSources.Contains(audioSource))
            {
                m_audioSources.Remove(audioSource);
            }
            else
            {
                SoundToolKitDebug.LogWarning("Source component wasn't registered.");
            }
        }
        /// <summary>
        /// Generate the necessary parameters
        /// </summary>
        public List <KeyValuePair <string, string> > GetParams()
        {
            var p = new List <KeyValuePair <string, string> >();

            if (AudioSources != null)
            {
                p.AddRange(AudioSources.Select(prop => new KeyValuePair <string, string>("AudioSources", prop.ToString())));
            }

            if (VideoSources != null)
            {
                p.AddRange(VideoSources.Select(prop => new KeyValuePair <string, string>("VideoSources", prop.ToString())));
            }

            if (VideoLayout != null)
            {
                p.Add(new KeyValuePair <string, string>("VideoLayout", VideoLayout.ToString()));
            }

            if (Resolution != null)
            {
                p.Add(new KeyValuePair <string, string>("Resolution", Resolution));
            }

            if (Format != null)
            {
                p.Add(new KeyValuePair <string, string>("Format", Format.ToString()));
            }

            if (DesiredBitrate != null)
            {
                p.Add(new KeyValuePair <string, string>("DesiredBitrate", DesiredBitrate.Value.ToString()));
            }

            if (DesiredMaxDuration != null)
            {
                p.Add(new KeyValuePair <string, string>("DesiredMaxDuration", DesiredMaxDuration.Value.ToString()));
            }

            if (StatusCallback != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallback", Serializers.Url(StatusCallback)));
            }

            if (StatusCallbackMethod != null)
            {
                p.Add(new KeyValuePair <string, string>("StatusCallbackMethod", StatusCallbackMethod.ToString()));
            }

            return(p);
        }
Esempio n. 14
0
        private void UpdateAudioSources()
        {
            var selectedId = GetSceneAudio(false)?.Source?.DeviceName?.DeviceId;

            ListHelper.UpdateCollection(CoreData,
                                        _sceneState.Device.AudioInputs.Values.OrderBy(s => s.Name).ToList(),
                                        AudioSources,
                                        s => s.Id,
                                        (s, id) => new AudioSourceModel(id,
                                                                        s,
                                                                        () => Select(id),
                                                                        new Property <bool>()));

            AudioSources.ToList().ForEach(s => s.IsSelected.Value = s.Id == selectedId);
        }
Esempio n. 15
0
    // Use this for initialization
    void Awake()
    {
        if (audioSourcesInstance == null)
        {
            audioSourcesInstance = this;

            //当加载一个新关卡时,所有场景中所有的物体被销毁,然后新关卡中的物体被加载进来。为了保持在加载新关卡时物体不被销毁,使用DontDestroyOnLoad保持,如果物体是一个组件或游戏物体,它的整个transform层次将不会被销毁,全部保留下来。
            //加载新场景的时候使目标物体不被自动销毁
            DontDestroyOnLoad(gameObject);
        }
        else
        {
            Destroy(gameObject);
        }
    }
Esempio n. 16
0
        public void Initialize()
        {
            var matches = Assembly.GetExecutingAssembly()
                          .GetTypes()
                          .Where(x => typeof(BaseSourceProvider).IsAssignableFrom(x) && !x.IsAbstract)
                          .ToArray();

            LogHandler <SourceHandler> .Log.Debug($"Discovered {matches.Length} SourceProviders.");

            foreach (var match in matches)
            {
                Singleton.Add(match);
            }

            _sources = Singleton.Of <Configuration>().Sources;
            _cache   = Singleton.Of <CacheHandler>();
        }
Esempio n. 17
0
    void Awake()
    {
        ambientSource = GetComponent <AudioSource>();

        shootSources    = new AudioSources(shootSoundSources, gameObject);
        pickupSources   = new AudioSources(pickupSoundSources, gameObject);
        boundarySources = new AudioSources(boundarySoundSources, gameObject);
        explosionSource = new AudioSources(1, gameObject);

        shootSources.clip    = shootSound;
        pickupSources.clip   = pickupSound;
        boundarySources.clip = boundarySound;
        explosionSource.clip = explosionSound;

        shootSources.mixerGroup    = effectsGroup;
        pickupSources.mixerGroup   = effectsGroup;
        boundarySources.mixerGroup = effectsGroup;
        explosionSource.mixerGroup = effectsGroup;
    }
Esempio n. 18
0
        public void Add(SourceComponent audioSource)
        {
            // <STK.LITE> - Why are we even here?
            if (AudioSources.Count >= StkLite.AvailableSources())
            {
                return;
            }
            // </STK.LITE>

            SoundToolKitDebug.Assert(audioSource != null, "Source component is null");

            if (!AudioSources.Contains(audioSource))
            {
                m_audioSources.Add(audioSource);
            }
            else
            {
                SoundToolKitDebug.LogWarning("Source component already registered.");
            }
        }
Esempio n. 19
0
    IEnumerator PlayPressedAudio()
    {
        if (!PianoKeyController.NoMultiAudioSource && CurrentAudioSource.isPlaying)
        {
            bool foundReplacement = false;
            int  index            = AudioSources.IndexOf(CurrentAudioSource);

            for (int i = 0; i < AudioSources.Count; i++)
            {
                if (i != index && (!AudioSources[i].isPlaying || AudioSources[i].volume <= 0))
                {
                    foundReplacement   = true;
                    CurrentAudioSource = AudioSources[i];
                    _toFade.Remove(AudioSources[i]);
                    break;
                }
            }

            if (!foundReplacement)
            {
                AudioSource newAudioSource = CloneAudioSource();
                AudioSources.Add(newAudioSource);
                CurrentAudioSource = newAudioSource;
            }

            _toFade.Add(AudioSources[index]);
        }

        _startAngle = transform.eulerAngles.x;

        yield return(new WaitForFixedUpdate());

        yield return(new WaitForFixedUpdate());

        if (Mathf.Abs(_startAngle - transform.eulerAngles.x) > 0)
        {
            CurrentAudioSource.volume = Mathf.Lerp(0, 1, Mathf.Clamp((Mathf.Abs(_startAngle - transform.eulerAngles.x) / 2f), 0, 1));
        }

        CurrentAudioSource.Play();
    }
Esempio n. 20
0
 public virtual void Start()
 {
     audioSources = GetComponent <AudioSources>();
 }
Esempio n. 21
0
 //Add a HDR audio source to the collection, don't add the same twice
 public void AddAudioSource(HDRAudioSource source)
 {
     AudioSources.Add(new HDRAudio.AudioTuple(source));
 }
Esempio n. 22
0
 void SetActiveSource(AudioSources src)
 {
     if ((int)AudioSources.SOURCE_MAX != activeSource) source[activeSource].Stop();
     activeSource = (int)src;
     source[activeSource].Play();
 }
Esempio n. 23
0
 void Awake()
 {
     if (Instance != null)
         throw new UnityException("More than one AudioSources component right now!");
     Instance = this;
 }
Esempio n. 24
0
        private async void Ws_SceneChanged(SLOBSWebsocket sender, SLOBSSceneEvent eventdata)
        {
            if (eventdata.Type == ESLOBSEventType.SceneAdded)
            {
                SOBSScene item = _translateScene(eventdata.Scene);
                Scenes.Add(item);
                if (SceneChanged != null)
                {
                    SceneChanged(this, EOBSEvent.SceneAdded, item);
                }
            }
            else if (eventdata.Type == ESLOBSEventType.SceneRemoved)
            {
                int       reindex = 0;
                SOBSScene item    = _translateScene(eventdata.Scene);
                for (int i = 0; i < Scenes.Count; i++)
                {
                    if (Scenes[i].Id == eventdata.Scene.Id)
                    {
                        Scenes.RemoveAt(i);
                    }
                    else
                    {
                        var scene = Scenes[i];
                        scene.Index = reindex;
                        Scenes[i]   = scene;
                        reindex++;
                    }
                }
                if (SceneChanged != null)
                {
                    SceneChanged(this, EOBSEvent.SceneRemoved, item);
                }
            }
            else if (eventdata.Type == ESLOBSEventType.SceneSwitched)
            {
                if (!_setActiveScene(eventdata.Scene))
                {
                    var ascenes = await ws.ListScenes();

                    Scenes.Clear();
                    Scenes = _translateScenes(ascenes);
                    _setActiveScene(eventdata.Scene);
                }

                var audio = await ws.ListAudioSources();

                AudioSources.Clear();
                AudioSources = _translateAudioSources(audio);
                if (AudioSourceChanged != null)
                {
                    AudioSourceChanged(this, EOBSEvent.SourceAdded);
                }

                if (SceneChanged != null)
                {
                    SceneChanged(this, EOBSEvent.SceneSwitched, ActiveScene);
                }
            }
            else if (eventdata.Type == ESLOBSEventType.SceneCollectionChanged)
            {
                var ascenes = await ws.ListScenes();

                Scenes.Clear();
                Scenes = _translateScenes(ascenes);
                var active_scene = await ws.GetActiveScene();

                if (active_scene != null)
                {
                    for (int i = 0; i < Scenes.Count; i++)
                    {
                        if (Scenes[i].Id == ((SLOBSScene)active_scene).Id)
                        {
                            ActiveScene = Scenes[i];
                        }
                    }
                }

                if (SceneChanged != null)
                {
                    SceneChanged(this, EOBSEvent.SceneUpdated, ActiveScene);
                }
            }
        }
Esempio n. 25
0
        private async void Ws_SourceChanged(SLOBSWebsocket sender, SLOBSSourceEvent eventdata)
        {
            if (eventdata.Type == ESLOBSEventType.SourceAdded)
            {
                var sourceItem = _translateSource(eventdata.Source, Sources.Count + 1);
                Sources.Add(sourceItem);
                if (SourceChanged != null)
                {
                    SourceChanged(this, EOBSEvent.SourceAdded, sourceItem);
                }

                //Audio item
                if (sourceItem.Audio)
                {
                    var audio = await ws.ListAudioSources();

                    AudioSources.Clear();
                    AudioSources = _translateAudioSources(audio);
                    if (AudioSourceChanged != null)
                    {
                        AudioSourceChanged(this, EOBSEvent.SourceAdded);
                    }
                }
            }
            else if (eventdata.Type == ESLOBSEventType.SourceRemoved)
            {
                var sourceItem = _translateSource(eventdata.Source, 0);
                int reindex    = 0;
                for (int i = 0; i < Sources.Count; i++)
                {
                    if (Sources[i].Id == eventdata.Source.Id)
                    {
                        Sources.RemoveAt(i);
                        sourceItem.Index = i;
                        if (SourceChanged != null)
                        {
                            SourceChanged(this, EOBSEvent.SourceRemoved, sourceItem);
                            //audio item
                            if (sourceItem.Audio)
                            {
                                for (int ia = 0; ia < AudioSources.Count; ia++)
                                {
                                    if (AudioSources[i].SourceId == sourceItem.Id)
                                    {
                                        AudioSources.RemoveAt(ia);
                                        if (AudioSourceChanged != null)
                                        {
                                            AudioSourceChanged(this, EOBSEvent.SourceUpdated);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        var source = Sources[i];
                        source.Index = reindex;
                        Sources[i]   = source;
                        reindex++;
                    }
                }
            }
            else if (eventdata.Type == ESLOBSEventType.SourceUpdated)
            {
                var sourceItem = _translateSource(eventdata.Source, 0);

                for (int i = 0; i < Sources.Count; i++)
                {
                    if (Sources[i].Id == eventdata.Source.Id)
                    {
                        sourceItem.Index = i;
                        Sources[i]       = sourceItem;
                        if (SourceChanged != null)
                        {
                            SourceChanged(this, EOBSEvent.SourceUpdated, sourceItem);
                        }

                        //audio item
                        if (sourceItem.Audio)
                        {
                            var audio = await ws.ListAudioSources();

                            AudioSources.Clear();
                            AudioSources = _translateAudioSources(audio);

                            if (AudioSourceChanged != null)
                            {
                                AudioSourceChanged(this, EOBSEvent.SourceUpdated);
                            }
                        }
                    }
                }
            }
        }