예제 #1
0
 private IEnumerator PostDelayedActions(GameObject controllingObject, AudioEventAction eventData, Vector3 postAt)
 {
     yield return new WaitForSeconds(eventData.Delay);
     HandleEventAction(controllingObject, eventData, null, postAt);
 }
예제 #2
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;
        InEventSnapshotAction snapshotData;
        InEventMixerValueAction mixerData;
        InEventMusicControl musicControl;
        InEventMusicFade musicFade;
        InEventSoloMuteMusic musicSoloMute;

        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.PlayConnectedTo(controllingObject, audioNode, attachedTo, null, audioPlayData.Fadetime, audioPlayData.TweenType);
                    else
                        _inAudioEventWorker.PlayAtPosition(controllingObject, audioNode, playAt, null, 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.SetSnapshot:
                snapshotData = ((InEventSnapshotAction)eventData);
                snapshotData.Snapshot.TransitionTo(snapshotData.TransitionTime);
                break;
            case EventActionTypes.MixerValue:
                mixerData = ((InEventMixerValueAction)eventData);
                var mixer = mixerData.Mixer;
                var parameter = mixerData.Parameter;
                if (mixerData.TransitionTime > 0)
                {
                    float v;
                    if (mixer.GetFloat(parameter, out v))
                    {
                        var tween = LeanTween.value(gameObject, f => mixer.SetFloat(parameter, f), v, mixerData.Value,
                            mixerData.TransitionTime);
                        tween.onUpdateParam = this;
                        tween.tweenType = mixerData.TransitionType;
                    }
                    else
                    {
                        Debug.LogError("InAudio: Could not find parameter \"" + parameter + "\" on \"" + mixer + "\"");
                    }
                }
                else
                    mixerData.Mixer.SetFloat(mixerData.Parameter, mixerData.Value);
                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.CrossfadeMusic:
                musicFade = eventData as InEventMusicFade;
                InAudio.Music.SwapCrossfadeVolume(musicFade.From, musicFade.To, musicFade.Duration, musicFade.TweenType);
                break;
            case EventActionTypes.FadeMusic:
                musicFade = eventData as InEventMusicFade;
                if (musicFade.Target != null)
                {
                    switch (musicFade.DoAtEndTo)
                    {
                        case MusicState.Playing:
                        case MusicState.Nothing:
                            InAudio.Music.FadeVolume(musicFade.To, musicFade.ToVolumeTarget, musicFade.Duration,
                                musicFade.TweenType);
                            break;
                        case MusicState.Paused:
                            InAudio.Music.FadeAndPause(musicFade.To, musicFade.ToVolumeTarget, musicFade.Duration,
                                musicFade.TweenType);
                            break;
                        case MusicState.Stopped:
                            InAudio.Music.FadeAndStop(musicFade.To, musicFade.ToVolumeTarget, musicFade.Duration,
                                musicFade.TweenType);
                            break;
                        default:
                            Debug.LogError("InAudio: Unsuported action at end of fade");
                            break;
                    }
                }
                else
                {
                    InDebug.MissingActionTarget(controllingObject, eventData);
                }
                break;
            case EventActionTypes.PlayMusic:
                musicControl = eventData as InEventMusicControl;
                if (musicControl.Target != null)
                {
                    if (!musicControl.Fade)
                    {
                        if (musicControl.ChangeVolume)
                        {
                            InAudio.Music.SetVolume(musicControl.MusicGroup, musicControl.VolumeTarget);
                        }
                        InAudio.Music.Play(musicControl.MusicGroup);
                    }
                    else
                    {
                        if (musicControl.ChangeVolume)
                            InAudio.Music.PlayWithFadeIn(musicControl.MusicGroup, musicControl.VolumeTarget,
                                musicControl.Duration, musicControl.TweenType);
                        else
                            InAudio.Music.PlayWithFadeIn(musicControl.MusicGroup, musicControl.Duration,
                                musicControl.TweenType);
                    }
                }
                else
                {
                    InDebug.MissingActionTarget(controllingObject, eventData);
                }
                break;
            case EventActionTypes.StopMusic:
                musicControl = eventData as InEventMusicControl;
                if (musicControl.Target != null)
                {
                    if (!musicControl.Fade)
                    {
                        if (musicControl.ChangeVolume)
                        {
                            InAudio.Music.SetVolume(musicControl.MusicGroup, musicControl.VolumeTarget);
                        }
                        InAudio.Music.Stop(musicControl.MusicGroup);
                    }
                    else
                    {
                        if (musicControl.ChangeVolume)
                            InAudio.Music.FadeAndStop(musicControl.MusicGroup, musicControl.VolumeTarget,
                                musicControl.Duration, musicControl.TweenType);
                        else
                            InAudio.Music.FadeAndStop(musicControl.MusicGroup, musicControl.Duration,
                                musicControl.TweenType);
                    }
                }
                else
                {
                    InDebug.MissingActionTarget(controllingObject, eventData);
                }
                break;
            case EventActionTypes.PauseMusic:
                musicControl = eventData as InEventMusicControl;
                if (musicControl.Target != null)
                {
                    if (!musicControl.Fade)
                    {
                        if (musicControl.ChangeVolume)
                        {
                            InAudio.Music.SetVolume(musicControl.MusicGroup, musicControl.VolumeTarget);
                        }
                        InAudio.Music.Pause(musicControl.MusicGroup);
                    }
                    else
                    {
                        if (musicControl.ChangeVolume)
                            InAudio.Music.FadeAndPause(musicControl.MusicGroup, musicControl.VolumeTarget,
                                musicControl.Duration, musicControl.TweenType);
                        else
                            InAudio.Music.FadeAndPause(musicControl.MusicGroup, musicControl.Duration,
                                musicControl.TweenType);
                    }
                }
                else
                {
                    InDebug.MissingActionTarget(controllingObject, eventData);
                }
                break;
            case EventActionTypes.SoloMuteMusic:
                {
                    musicSoloMute = eventData as InEventSoloMuteMusic;
                    if (musicSoloMute.Target != null)
                    {
                        if (musicSoloMute.SetSolo)
                            Music.Solo(musicSoloMute.MusicGroup, musicSoloMute.SoloTarget);
                        if (musicSoloMute.SetMute)
                            Music.Solo(musicSoloMute.MusicGroup, musicSoloMute.MuteTarget);
                    }
                    else
                    {
                        InDebug.MissingActionTarget(controllingObject, eventData);
                    }
                    break;
                }
            case EventActionTypes.StopAllMusic:
                musicFade = eventData as InEventMusicFade;
                if (musicFade.Target != null)
                {
                    if (musicFade.Duration > 0)
                    {
                        InAudio.Music.StopAll(musicFade.Duration, musicFade.TweenType);
                    }
                    else
                    {
                        InAudio.Music.StopAll();
                    }
                }
                else
                {
                    InDebug.MissingActionTarget(controllingObject, eventData);
                }
                break;
            default:
                InDebug.UnusedActionType(gameObject, eventData);
                break;
        }

    }
예제 #3
0
 private IEnumerator PostDelayedActions(GameObject controllingObject, AudioEventAction eventData, GameObject attachedToOther)
 {
     yield return new WaitForSeconds(eventData.Delay);
     HandleEventAction(controllingObject, eventData, attachedToOther);
 }