Exemple #1
0
 /// <summary>
 /// Post all actions in this event in accordance to the data specified in the inspector, but overrides another place to fire the sound from
 /// </summary>
 /// <param name="controllingObject">The controlling game object and the future parent of the audio files</param>
 /// <param name="eventList">All the events to post as added in the inspector</param>
 /// <param name="postAt">The new position to play at</param>
 public static void PostEventAtPosition(GameObject controllingObject, InAudioEvent eventList, Vector3 postAt)
 {
     if (instance != null && controllingObject != null && eventList != null && eventList.Events != null)
     {
         int count = eventList.Events.Count;
         for (int i = 0; i < count; i++)
         {
             EventHookListData eventData = eventList.Events[i];
             if (eventData != null && eventData.Event != null)
             {
                 instance.OnPostEvent(controllingObject, eventData.Event, postAt);
             }
         }
     }
     else
     {
         if (instance == null)
         {
             InDebug.InAudioInstanceMissing(controllingObject);
         }
         else if (controllingObject == null)
         {
             InDebug.MissingControllingObject();
         }
         else if (eventList == null || eventList.Events == null)
         {
             InDebug.MissingEventList(controllingObject);
         }
     }
 }
Exemple #2
0
 /// <summary>
 /// This will clean up any unused runtime memory and release objects back to their pools
 /// Does not release audio clips.
 /// Best called in loading screens
 /// </summary>
 public static void Cleanup()
 {
     if (instance != null && instance._inAudioEventWorker != null)
     {
         instance._inAudioEventWorker.Cleanup();
     }
     else
     {
         InDebug.CleanupInstance();
     }
 }
Exemple #3
0
 /// <summary>
 /// Unload all audio clips in this banks. Also calls Resources.UnloadUnusedAssets(). Clips will autoreimport if any audio source still referencs this clip
 /// </summary>
 /// <param name="bank">The reference to the bank to unload</param>
 public static void UnloadBank(InAudioBankLink bank)
 {
     if (bank != null)
     {
         BankLoader.Unload(bank);
     }
     else
     {
         InDebug.BankUnloadMissing();
     }
 }
Exemple #4
0
 /// <summary>
 /// Finds an audio node based on the ID specified
 /// </summary>
 /// <param name="id">The id to search for</param>
 /// <returns>The found bus, null if not found</returns>
 public static InAudioNode FindAudioNodeById(int id)
 {
     if (instance != null)
     {
         return(TreeWalker.FindById(InAudioInstanceFinder.DataManager.AudioTree, id));
     }
     else
     {
         InDebug.LogWarning("InAudio: Could not bus with id " + id);
     }
     return(null);
 }
Exemple #5
0
 /// <summary>
 /// Check if a bus is muted
 /// </summary>
 /// <param name="bus">The bus</param>
 /// <param name="mute">to mute or unmute</param>
 public static void IsBusMuted(InAudioBus bus, bool mute)
 {
     if (bus != null)
     {
         bus.Dirty       = true;
         bus.RuntimeMute = mute;
     }
     else
     {
         InDebug.LogWarning("Bus instance not set to an instance in mute");
     }
 }
Exemple #6
0
    /// <summary>
    /// Find an Audio Event by id so it can be posted directly
    /// </summary>
    /// <param name="id">The ID of the event to post. The ID is found in the InAudio Event window</param>
    /// <returns>The found audio event. Returns null if not found</returns>
    public static InAudioEventNode FindEventByID(int id)
    {
        InAudioEventNode postEvent = null;

        if (instance != null)
        {
            instance.runtimeData.Events.TryGetValue(id, out postEvent);
        }
        else
        {
            InDebug.LogWarning("InAudio: Could not try to find event with id " + id + " as no InAudio instance was found");
        }
        return(postEvent);
    }
Exemple #7
0
 /// <summary>
 /// Post all actions in this event at this position with this game object as the controller
 /// </summary>
 /// <param name="controllingObject">The controlling object of the played audio files</param>
 /// <param name="postEvent">The event to post the actions of</param>
 /// <param name="position">The position in world space of the sound</param>
 public static void PostEventAtPosition(GameObject controllingObject, InAudioEventNode postEvent, Vector3 position)
 {
     if (instance != null && controllingObject != null && postEvent != null)
     {
         instance.OnPostEventAtPosition(controllingObject, postEvent, position);
     }
     else
     {
         if (instance == null)
         {
             InDebug.InAudioInstanceMissing(controllingObject);
         }
         else if (controllingObject == null)
         {
             InDebug.MissingControllingObject();
         }
         else if (postEvent == null)
         {
             InDebug.MissingEvent(controllingObject);
         }
     }
 }
Exemple #8
0
 /// <summary>
 /// Post all actions in this event attached to this another game object than the one controlling it
 /// </summary>
 /// <param name="controllingObject">The controlling object of the played sources</param>
 /// <param name="postEvent">The event to post the actions of</param>
 /// <param name="attachedToOther">The audio source to attach any audio sources to</param>
 public static void PostEventAttachedTo(GameObject controllingObject, InAudioEventNode postEvent, GameObject attachedToOther)
 {
     if (instance != null && controllingObject != null && postEvent != null)
     {
         instance.OnPostEvent(controllingObject, postEvent, attachedToOther);
     }
     else
     {
         if (instance == null)
         {
             InDebug.InAudioInstanceMissing(controllingObject);
         }
         else if (controllingObject == null)
         {
             InDebug.MissingControllingObject();
         }
         else if (postEvent == null)
         {
             InDebug.MissingEvent(controllingObject);
         }
     }
 }
Exemple #9
0
 /// <summary>
 /// Post all actions in this event in accordance to the data specified in the inspector, but overrides which object is it attached to.
 /// </summary>
 /// <param name="controllingObject">The controlling game object and the future parent of the audio files</param>
 /// <param name="eventList">All the events to post as added in the inspector</param>
 /// <param name="attachedToOther">The object to attach the events to</param>
 public static void PostEventAttachedTo(GameObject controllingObject, InAudioEvent eventList, GameObject attachedToOther)
 {
     if (instance != null && controllingObject != null && eventList != null && eventList.Events != null)
     {
         int     count    = eventList.Events.Count;
         Vector3 position = controllingObject.transform.position;
         for (int i = 0; i < count; i++)
         {
             EventHookListData eventData = eventList.Events[i];
             if (eventData != null && eventData.Event != null)
             {
                 if (eventData.PostAt == EventHookListData.PostEventAt.AttachedTo)
                 {
                     instance.OnPostEvent(controllingObject, eventData.Event, attachedToOther);
                 }
                 else //if post at position
                 {
                     instance.OnPostEvent(controllingObject, eventData.Event, position);
                 }
             }
         }
     }
     else
     {
         if (instance == null)
         {
             InDebug.InAudioInstanceMissing(controllingObject);
         }
         else if (controllingObject == null)
         {
             InDebug.MissingControllingObject();
         }
         else if (eventList == null || eventList.Events == null)
         {
             InDebug.MissingEventList(controllingObject);
         }
     }
 }
Exemple #10
0
    /*Internal systems*/
    #region Internal system

    private void HandleEventAction(GameObject controllingObject, AudioEventAction eventData, GameObject attachedTo, Vector3 playAt = new Vector3())
    {
        InAudioNode audioNode; //Because we can't create variables in the scope of the switch with the same name
        InEventBankLoadingAction bankLoadingData;

        if (eventData.Target == null && eventData.EventActionType != EventActionTypes.StopAll)
        {
            InDebug.MissingActionTarget(controllingObject, eventData);
            return;
        }

        switch (eventData.EventActionType)
        {
        case EventActionTypes.Play:
            var audioPlayData = ((InEventAudioAction)eventData);
            audioNode = audioPlayData.Node;
            if (audioNode != null)
            {
                if (attachedTo != null)
                {
                    _inAudioEventWorker.PlayAttachedTo(controllingObject, audioNode, attachedTo, audioPlayData.Fadetime, audioPlayData.TweenType);
                }
                else
                {
                    _inAudioEventWorker.PlayAtPosition(controllingObject, audioNode, playAt, audioPlayData.Fadetime, audioPlayData.TweenType);
                }
            }
            break;

        case EventActionTypes.Stop:
            var data = ((InEventAudioAction)eventData);
            audioNode = data.Node;
            _inAudioEventWorker.StopByNode(controllingObject, audioNode, data.Fadetime, data.TweenType);
            break;

        case EventActionTypes.StopAll:
            var stopAlLData = ((InEventAudioAction)eventData);
            _inAudioEventWorker.StopAll(controllingObject, stopAlLData.Fadetime, stopAlLData.TweenType);
            break;

        case EventActionTypes.Break:
            audioNode = ((InEventAudioAction)eventData).Node;
            _inAudioEventWorker.Break(controllingObject, audioNode);
            break;

        case EventActionTypes.SetBusVolume:
            var busData = eventData as InEventBusAction;
            if (busData != null && busData.Bus != null)
            {
                AudioBusVolumeHelper.SetTargetVolume(busData.Bus, busData.Volume, busData.VolumeMode, busData.Duration, busData.FadeCurve);
            }
            break;

        case EventActionTypes.BankLoading:
            bankLoadingData = eventData as InEventBankLoadingAction;
            if (bankLoadingData != null)
            {
                if (bankLoadingData.LoadingAction == BankHookActionType.Load)
                {
                    BankLoader.Load(bankLoadingData.BankLink);
                }
                else
                {
                    BankLoader.Unload(bankLoadingData.BankLink);
                }
            }
            break;

        case EventActionTypes.StopAllInBus:
            busData = eventData as InEventBusAction;
            if (busData != null && busData.Bus != null)
            {
                StopAllNodeInBus(busData.Bus);
            }
            break;

        case EventActionTypes.SetBusMute:
            var busMuteData = eventData as InEventBusMuteAction;
            if (busMuteData != null && busMuteData.Bus != null)
            {
                AudioBusVolumeHelper.MuteAction(busMuteData.Bus, busMuteData.Action);
            }
            break;

        default:
            InDebug.UnusedActionType(gameObject, eventData);
            break;
        }
    }