Exemple #1
0
        public override void OnInspectorGUI()
        {
            GUILayout.Space(5);
            GUILayout.BeginVertical(GUI.skin.box);
            PYAudioManager.GlobalVolume = EditorGUILayout.Slider("Global Volume: ", PYAudioManager.GlobalVolume, 0, 1);

            AudioMixer mixer = (AudioMixer)EditorGUILayout.ObjectField("Audio Mixer: ", targetRef.Mixer, typeof(AudioMixer), false);

            // Update mixer in AudioManager and update groups
            if (mixer != targetRef.Mixer)
            {
                targetRef.Mixer = mixer;
                UpdateAudioManagerGroups();
            }
            GUILayout.EndVertical();

            GUILayout.Space(10);
            GUILayout.BeginVertical(GUI.skin.box);
            GUILayout.Label("Groups" + (targetRef.Groups.Keys.Count == 0 ? ": You need to assing a AudioMixer to show groups" : ""));
            foreach (PYGroupTag groupName in targetRef.Groups.Keys)
            {
                GUILayout.BeginHorizontal();

                PYAudioManager.AudioGroup group = targetRef.Groups[groupName];
                bool  groupMute = !EditorGUILayout.ToggleLeft(groupName.ToString(), !group.Mute);
                float volume    = EditorGUILayout.Slider(group.Volume, 0, 1);

                if (GUI.changed)
                {
                    if (groupMute != group.Mute)
                    {
                        PYAudioManager.Instance.MuteGroup(group.Group, groupMute);
                    }
                    if (volume != group.Volume)
                    {
                        PYAudioManager.Instance.SetGroupVolume(group.Group, volume);
                    }
                }

                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();

            GUILayout.Space(10);
            if (GUILayout.Button("Build Tags"))
            {
                BuildTags();
            }

            if (GUILayout.Button("Remove Obsolete Tags"))
            {
                RemoveObsoleteTags();
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(targetRef);
                EditorUtility.SetDirty(targetRef.gameObject);
            }
        }
Exemple #2
0
        public void Initialize(PYAudioTags audioTag, PYAudioManager.AudioTrack track)
        {
            AudioTag = audioTag;
            Track    = track;
            Group    = PYAudioManager.Instance.Groups[Track.GroupTag];

            if (_source == null)
            {
                _source = GetComponent <AudioSource>();
            }

            _source.playOnAwake           = false;
            _source.clip                  = Track.Clip;
            _source.loop                  = false;
            _source.mute                  = Group.Mute;
            _source.volume                = Group.Volume;
            _source.pitch                 = 1;
            _source.outputAudioMixerGroup = PYAudioManager.Instance.Mixer.FindMatchingGroups(Track.GroupTag.ToString())[0];

            if (_source.clip != null)
            {
                _duration = _source.clip.length;
            }

            _delay              = 0;
            _loop               = false;
            IsPlaying           = IsPaused = false;
            _isStoppingWithFade = false;

            OnStartPlaying = null;
            OnPlaying      = null;
            OnResume       = null;
            OnPaused       = null;
            OnCompleted    = null;
            OnStopped      = null;

            AudioTrigger.Initialize(audioTag);
        }