Exemple #1
0
        private bool PlayProtocol(string key, string dialogueName, float overrideDuration)
        {
            eventInstance = FMODUnity.RuntimeManager.CreateInstance(masterVoiceoverEvent);

            if (!eventInstance.isValid())
            {
                return(false);
            }

            GCHandle stringHandle = GCHandle.Alloc(key, GCHandleType.Pinned);

            eventInstance.setUserData(GCHandle.ToIntPtr(stringHandle));
            eventInstance.setCallback(voiceoverCallback);

            if (is3D)
            {
                Transform transformToFollow;

                if (followTransform != null)
                {
                    transformToFollow = followTransform;
                }
                else
                {
                    transformToFollow = gameObject.transform;
                }

                // If the followed game object has a rigidbody, retrieve it and pass it to FMODUnity Runtimemanager for velocity updates.
                Rigidbody rb = transformToFollow.gameObject.GetComponent <Rigidbody>();

                FMODUnity.RuntimeManager.AttachInstanceToGameObject(eventInstance, transformToFollow, rb);

                if (spatialAudioRoomAware && SpatialAudioManager.Instance != null)
                {
                    SpatialAudioManager.Instance.RegisterRoomAwareInstance(eventInstance, transformToFollow, maxDistance, initialRoom);
                }
            }

            isSpeaking      = true;
            currentDialogue = dialogueName;

            if (overrideDuration >= 0)
            {
                StartCoroutine(WaitBeforeDialogueRelease(overrideDuration));
                coroutineRunning = true;
            }

            eventInstance.start();

            return(true);
        }
Exemple #2
0
        public void StartMusic(string name, float volume)
        {
            musicEventName = name;
            musicVolume    = volume;

            musicEvent = FmodFacade.instance.CreateFmodEventInstance(FmodFacade.instance.GetFmodMusicEventFromDictionary(name));

            musicEvent.setCallback(beatCallback,
                                   FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_BEAT
                                   | FMOD.Studio.EVENT_CALLBACK_TYPE.TIMELINE_MARKER
                                   | FMOD.Studio.EVENT_CALLBACK_TYPE.STARTED
                                   );

            // Pass the object through the userdata of the instance
            musicEvent.setUserData(GCHandle.ToIntPtr(timelineHandle));

            FmodFacade.instance.PlayFmodEvent(musicEvent, volume);
            isMusicPlaying = true;
        }
Exemple #3
0
 /// <summary>
 /// Plays the passed in fmod event as a one shot event, meaning it is set to release the event automatically as soon as it stops playing.
 /// This allows for instanced fmod events without letting them infinitely build up.
 /// </summary>
 /// <param name="fmodEvent"> The name of the event we want to play as a one shot event </param>
 /// <param name="volume"> The volume of the event we want to play as a one shot event </param>
 /// <param name="paramData"> An array of param data that should be passed to our fmod event before playing it </param>
 public void PlayOneShotFmodEvent(FMOD.Studio.EventInstance fmodEvent, float volume = 1.0f, FmodParamData[] paramData = null)
 {
     if (paramData != null)
     {
         for (int i = 0; i < paramData.Length; i++)
         {
             SetFmodParameterValue(fmodEvent, paramData[i].paramName, paramData[i].paramValue);
         }
     }
     fmodEvent.setVolume(volume);
     if (debugOneShotEvents)
     {
         Debug.Log("1. START ONE SHOT EVENT");
         FMOD.Studio.EVENT_CALLBACK stoppedOneShotEventCallback;
         stoppedOneShotEventCallback = new FMOD.Studio.EVENT_CALLBACK(StoppedOneShotEventCallback);
         fmodEvent.setCallback(stoppedOneShotEventCallback, FMOD.Studio.EVENT_CALLBACK_TYPE.STOPPED);
     }
     fmodEvent.start();
     fmodEvent.release();
 }