Пример #1
0
        public void SetLocalParameter(AudioObjectParameter parameter)
        {
            if (initializationSuccesfull == false)
            {
                return;
            }

            for (int i = 0; i < instantiations.Count; i++)
            {
                EventInstance eventInstance = instantiations[i];

                FMOD.RESULT result = eventInstance.setParameterByName(parameter.name, parameter.value);

                if (result != FMOD.RESULT.OK)
                {
                    Debug.LogWarning("Setting a value for local parameter '" + parameter.name +
                                     "' failed for '" + gameObject.name + "'. Fmod error: " + result);
                }
            }
        }
Пример #2
0
        private void InstantiateAudioObject(Transform follow = null, List <AudioObjectParameter> parameters = null)
        {
            if (destructionInProgress || !initializationSuccesfull)
            {
                return;
            }

            if (singleton && instantiations.Count > 0)
            {
                return;
            }

            int index = 0;

            if (eventReferences.Count > 1)
            {
                index = SelectRandomIndex();
            }

            EventInstance eventInstance;

            eventInstance = RuntimeManager.CreateInstance(eventReferences[index]);

            if (!eventInstance.isValid())
            {
                Debug.LogError("Creating an event instance failed for Audio Object '" + gameObject.name + "'.");
                return;
            }

            if (parameters != null)
            {
                for (int i = 0; i < parameters.Count; i++)
                {
                    AudioObjectParameter parameter = parameters[i];

                    FMOD.RESULT result = eventInstance.setParameterByName(parameter.name, parameter.value);

                    if (result != FMOD.RESULT.OK)
                    {
                        Debug.LogWarning("Setting a value for local parameter '" + parameter.name +
                                         "' failed for '" + gameObject.name + "'. Fmod error: " + result);
                    }
                }
            }

            EventDescription eventDescription = RuntimeManager.GetEventDescription(eventReferences[index]);

            bool is3D;

            eventDescription.is3D(out is3D);

            Transform transformToFollow = null;

            if (is3D)
            {
                // Transform follow priority:
                // 1. Transform optionally provided with the event instantiation
                // 2. Transform optionally provided in the inspector
                // 3. The Transform of this Audio Object.

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

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

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

            if (spatialAudioRoomAware && SpatialAudioManager.Instance != null)
            {
                if (is3D)
                {
                    if (_usesResonanceAudioSource)
                    {
                        var delayedRegistree = new DelayedSpatialAudioRegistree();
                        delayedRegistree.transformToFollow = transformToFollow;
                        delayedRegistree.eventInstance     = eventInstance;
                        delayedSpatialAudioRegistrees.Add(delayedRegistree);

                        GCHandle registreeHandle = GCHandle.Alloc(delayedRegistree, GCHandleType.Pinned);
                        eventInstance.setUserData(GCHandle.ToIntPtr(registreeHandle));
                        eventInstance.setCallback(instanceCreatedCallback, EVENT_CALLBACK_TYPE.CREATED | EVENT_CALLBACK_TYPE.DESTROYED);
                        return;
                    }
                    else
                    {
                        float maxDistance;
                        eventDescription.getMaximumDistance(out maxDistance);
                        SpatialAudioManager.Instance.RegisterRoomAwareInstance(eventInstance, transformToFollow, maxDistance, initialRoom, false);
                    }
                }
            }

            instantiations.Add(eventInstance);
            eventInstance.start();
        }