예제 #1
0
 public void UnregisterUserMusicComponent(UserMusicComponent uac)
 {
     if (!UserMusicComponents.Remove(uac))
     {
         throw new IndexOutOfRangeException();
     }
 }
예제 #2
0
        //USER AUDIO COMPONENT HANDLING

        public void RegisterUserMusicComponent(UserMusicComponent uac)
        {
            Type uacType = uac.GetType();

            if (UserMusicComponents.Find(x => x.GetType() == uacType) != null)
            {
                Debug.LogError($"Can't register UserMusicComponent of type {uacType} because an instance is already registered!");
                throw new InvalidOperationException();
            }

            UserMusicComponents.Add(uac);
            Debug.Log("Registered " + uac.GetType().Name);
        }
예제 #3
0
        public void SelectUserMusicComponent(string component)
        {
            //lookup/find
            UserMusicComponent uac = null;

            if (!string.IsNullOrEmpty(component))
            {
                uac = UserMusicComponents.Find(x => x.GetType().Name.Equals(component, StringComparison.Ordinal));

                if (uac == null)
                {
                    Debug.LogError($"Can't switch to UserMusicComponent of type {component} because it doesn't exist");
                    throw new IndexOutOfRangeException();
                }
            }

            if (CurrentUserMusicComponent != null)
            {
                if (CurrentMusics.ContainsKey(MusicSlot.User))
                {
                    AudioClip clip = CurrentMusics[MusicSlot.User].Clip;
                    CurrentMusics.Remove(MusicSlot.User);

                    //HandleMusicChanged();
                    MusicPlayers[MusicSlot.User].Stop();
                    MusicPlayers[MusicSlot.User].clip = null;

                    if (clip != null)
                    {
                        CurrentUserMusicComponent.ReportClipReleased(clip);
                    }
                }

                CurrentUserMusicComponent.Enabled = false;
            }

            CurrentUserMusicComponent = uac;

            if (uac != null)
            {
                CurrentUserMusicComponent.Enabled = true;
            }
            else
            {
                HandleMusicChanged();
            }
        }