/// <summary>
        /// Start playing an AudioEvent
        /// </summary>
        /// <param name="eventToPlay">The AudioEvent to play</param>
        /// <param name="emitter">The AudioSource component to play the event on</param>
        /// <returns>The reference for the runtime event that can be modified or stopped explicitly</returns>
        public static ActiveEvent PlayEvent(AudioEvent eventToPlay, AudioSource emitter)
        {
            ValidateManager();

            if (eventToPlay.InstanceLimit > 0 && CountActiveInstances(eventToPlay) >= eventToPlay.InstanceLimit)
            {
                Debug.LogFormat("AudioManager: Instance limit reached for {0}.", eventToPlay.name);
                return(null);
            }
            if (eventToPlay.Group != 0)
            {
                StopGroupInstances(eventToPlay.Group);
            }

            ActiveEvent tempEvent = new ActiveEvent(eventToPlay, emitter);

            eventToPlay.SetActiveEventProperties(tempEvent);

            ActiveEvents.Add(tempEvent);
            if (AvailableSources.Contains(emitter))
            {
                //Debug.LogFormat("Removing available source {0}", emitter.GetInstanceID());
                AvailableSources.Remove(emitter);
            }

            return(tempEvent);
        }
Пример #2
0
        /// <summary>
        /// Select an event to display in the graph
        /// </summary>
        /// <param name="selection">The audio event to select and display in the graph</param>
        private void SelectEvent(AudioEvent selection)
        {
            this.selectedEvent = selection;
            Rect output = this.selectedEvent.Output.NodeRect;

            this.panX = -output.x + (this.position.width - output.width - 20);
            this.panY = -output.y + (this.position.height / 2);
        }
 public static void StopAll(AudioEvent eventsToStop)
 {
     for (int i = 0; i < ActiveEvents.Count; i++)
     {
         ActiveEvent tempEvent = ActiveEvents[i];
         if (tempEvent.rootEvent == eventsToStop)
         {
             tempEvent.Stop();
         }
     }
 }
Пример #4
0
 /// <summary>
 /// Constructor: Create a new ActiveEvent from an AudioEvent and play it on an AudioSource
 /// </summary>
 /// <param name="eventToPlay">The AudioEvent to play</param>
 /// <param name="source">The AudioSource use for the AudioEvent</param>
 public ActiveEvent(AudioEvent eventToPlay, AudioSource source)
 {
     this.rootEvent        = eventToPlay;
     this.source           = source;
     this.Soloed           = false;
     this.Muted            = false;
     this.activeParameters = new ActiveParameter[this.rootEvent.Parameters.Count];
     for (int i = 0; i < this.activeParameters.Length; i++)
     {
         this.activeParameters[i] = new ActiveParameter(this.rootEvent.Parameters[i]);
     }
 }
Пример #5
0
        /// <summary>
        /// EDITOR: Create a new event and add it to the array of events in the bank
        /// </summary>
        /// <param name="outputPos">The position of the Output node</param>
        /// <returns></returns>
        public AudioEvent AddEvent(Vector2 outputPos)
        {
            AudioEvent newEvent = ScriptableObject.CreateInstance <AudioEvent>();

            newEvent.name = "New Audio Event";
            AssetDatabase.AddObjectToAsset(newEvent, this);
            newEvent.InitializeEvent(outputPos);
            this.audioEvents.Add(newEvent);
            EditorUtility.SetDirty(this);
            AssetDatabase.SaveAssets();
            return(newEvent);
        }
        /// <summary>
        /// Get the number of active instances of an AudioEvent
        /// </summary>
        /// <param name="audioEvent">The event to query the number of active instances of</param>
        /// <returns>The number of active instances of the specified AudioEvent</returns>
        private static int CountActiveInstances(AudioEvent audioEvent)
        {
            int tempCount = 0;

            for (int i = 0; i < ActiveEvents.Count; i++)
            {
                if (ActiveEvents[i].rootEvent == audioEvent)
                {
                    tempCount++;
                }
            }

            return(tempCount);
        }
Пример #7
0
        /// <summary>
        /// Display the properties of the specified AudioEvent
        /// </summary>
        /// <param name="audioEvent">The event to display the properties for</param>
        private void DrawEventProperties(AudioEvent audioEvent)
        {
            GUILayout.BeginArea(this.eventPropertyRect);
            this.eventPropertiesScrollPosition = EditorGUILayout.BeginScrollView(this.eventPropertiesScrollPosition);
            audioEvent.name          = EditorGUILayout.TextField("Event Name", audioEvent.name);
            audioEvent.InstanceLimit = EditorGUILayout.IntField("Instance limit", audioEvent.InstanceLimit);
            audioEvent.FadeIn        = EditorGUILayout.FloatField("Fade In", audioEvent.FadeIn);
            audioEvent.FadeOut       = EditorGUILayout.FloatField("Fade Out", audioEvent.FadeOut);
            audioEvent.Group         = EditorGUILayout.IntField("Group", audioEvent.Group);

            audioEvent.DrawParameters();
            EditorGUILayout.EndScrollView();
            GUILayout.EndArea();
        }
Пример #8
0
        private void SetBatchProperties(AudioEvent batchEvent)
        {
            AudioOutput op = batchEvent.Output;

            if (this.batchSetBus)
            {
                op.mixerGroup = this.batchBus;
            }
            if (this.batchSetMinVol)
            {
                op.MinVolume = this.batchMinVol;
            }
            if (this.batchSetMaxVol)
            {
                op.MaxVolume = this.batchMaxVol;
            }
            if (this.batchSetMinPitch)
            {
                op.MinPitch = this.batchMinPitch;
            }
            if (this.batchSetMaxPitch)
            {
                op.MaxPitch = this.batchMaxPitch;
            }
            if (this.batchSetLoop)
            {
                op.loop = this.batchLoop;
            }
            if (this.batchSetSpatialBlend)
            {
                op.spatialBlend = this.batchSpatialBlend;
            }
            if (this.batchSetHRTF)
            {
                op.HRTF = this.batchHRTF;
            }
            if (this.batchSetMaxDistance)
            {
                op.MaxDistance = this.batchMaxDistance;
            }
            if (this.batchSetAttenuation)
            {
                op.attenuationCurve = this.batchAttenuation;
            }
            if (this.batchSetDoppler)
            {
                op.dopplerLevel = this.batchDoppler;
            }
        }
        /// <summary>
        /// Start playing an AudioEvent
        /// </summary>
        /// <param name="eventToPlay">The AudioEvent to play</param>
        /// <param name="emitterObject">The GameObject to play the event on</param>
        /// <returns>The reference for the runtime event that can be modified or stopped explicitly</returns>
        public static ActiveEvent PlayEvent(AudioEvent eventToPlay, GameObject emitterObject)
        {
            if (eventToPlay == null)
            {
                return(null);
            }

            ValidateManager();

            if (eventToPlay.InstanceLimit > 0 && CountActiveInstances(eventToPlay) >= eventToPlay.InstanceLimit)
            {
                //Debug.LogFormat("AudioManager: Instance limit reached for {0}.", eventToPlay.name);
                return(null);
            }
            if (eventToPlay.Group != 0)
            {
                StopGroupInstances(eventToPlay.Group);
            }

            AudioSource tempSource = GetUnusedSource(emitterObject);

            if (tempSource == null)
            {
                tempSource             = emitterObject.AddComponent <AudioSource>();
                tempSource.playOnAwake = false;
            }
            else
            {
                AvailableSources.Remove(tempSource);
            }

            ActiveEvent tempEvent = new ActiveEvent(eventToPlay, tempSource);

            tempEvent.Play();
            if (AvailableSources.Contains(tempSource))
            {
                AvailableSources.Remove(tempSource);
            }

            if (tempEvent.clip != null)
            {
                ActiveEvents.Add(tempEvent);
            }

            return(tempEvent);
        }
Пример #10
0
        /// <summary>
        /// Display the list of buttons to select an event
        /// </summary>
        private void DrawEventList()
        {
            this.eventListRect.height = this.position.height;
            GUILayout.BeginArea(this.eventListRect);
            this.eventListScrollPosition = EditorGUILayout.BeginScrollView(this.eventListScrollPosition);
            this.audioBank = EditorGUILayout.ObjectField(this.audioBank, typeof(AudioBank), false) as AudioBank;

            if (this.audioBank == null)
            {
                EditorGUILayout.EndScrollView();
                GUILayout.EndArea();
                return;
            }

            if (this.audioBank.EditorEvents != null)
            {
                for (int i = 0; i < this.audioBank.EditorEvents.Count; i++)
                {
                    AudioEvent tempEvent = this.audioBank.EditorEvents[i];
                    if (tempEvent == null)
                    {
                        continue;
                    }

                    if (this.selectedEvent == tempEvent)
                    {
                        GUI.color = Color.white;
                    }
                    else
                    {
                        GUI.color = this.unselectedButton;
                    }

                    if (GUILayout.Button(tempEvent.name))
                    {
                        SelectEvent(tempEvent);
                    }

                    GUI.color = Color.white;
                }
            }

            EditorGUILayout.EndScrollView();
            GUILayout.EndArea();
        }
Пример #11
0
        /// <summary>
        /// Add an AudioEvent to the bank for each clip from the list
        /// </summary>
        /// <param name="clips">The list of AudioClips to add</param>
        private void AddEvents(List <AudioClip> clips)
        {
            for (int i = 0; i < clips.Count; i++)
            {
                AudioEvent newEvent = this.audioBank.AddEvent(new Vector2(CANVAS_SIZE / 2, CANVAS_SIZE / 2));
                Vector3    position = newEvent.Output.NodeRect.position;
                position.x -= HORIZONTAL_NODE_OFFSET;
                AudioFile tempNode = ScriptableObject.CreateInstance <AudioFile>();
                AssetDatabase.AddObjectToAsset(tempNode, newEvent);
                tempNode.InitializeNode(position);
                tempNode.File = clips[i];
                newEvent.AddNode(tempNode);
                newEvent.name = clips[i].name;
                newEvent.Output.Input.AddConnection(tempNode.Output);
            }

            EditorUtility.SetDirty(this.audioBank);
        }
Пример #12
0
        /// <summary>
        /// Display the nodes for an AuidoEvent on the graph
        /// </summary>
        /// <param name="audioEvent">The audio event to display the nodes for</param>
        private void DrawEventNodes(AudioEvent audioEvent)
        {
            if (audioEvent == null)
            {
                return;
            }

            if (audioEvent.EditorNodes == null)
            {
                return;
            }

            GUI.BeginGroup(new Rect(this.panX, this.panY, CANVAS_SIZE, CANVAS_SIZE));
            BeginWindows();
            for (int i = 0; i < audioEvent.EditorNodes.Count; i++)
            {
                AudioNode currentNode = audioEvent.EditorNodes[i];
                currentNode.DrawNode(i);
            }
            EndWindows();
            GUI.EndGroup();
        }
Пример #13
0
        /// <summary>
        /// Create a new event and select it in the graph
        /// </summary>
        private void AddEvent()
        {
            AudioEvent newEvent = this.audioBank.AddEvent(new Vector2(CANVAS_SIZE / 2, CANVAS_SIZE / 2));

            SelectEvent(newEvent);
        }
Пример #14
0
 /// <summary>
 /// Destroy an event object and remove it from the array of events
 /// </summary>
 /// <param name="eventToDelete"></param>
 public void DeleteEvent(AudioEvent eventToDelete)
 {
     eventToDelete.DeleteNodes();
     this.audioEvents.Remove(eventToDelete);
     ScriptableObject.DestroyImmediate(eventToDelete, true);
 }