Example #1
0
        private void PlaySound(string eventPath)
        {
            Camera camera = Camera.main;

            if (!camera)
            {
                Log.InGame("Camera.main not found");
                return;
            }
            Vector3 position = camera.transform.position + new Vector3(distance, 0, 0);

            if (!eventInstancesByPath.TryGetValue(eventPath, out EventInstance instance))
            {
                instance = FMODUWE.GetEvent(eventPath);
                eventInstancesByPath.Add(eventPath, instance);
            }
            else
            {
                instance.stop(FMOD.Studio.STOP_MODE.IMMEDIATE);
            }

            instance.setVolume(volume);
            instance.set3DAttributes(position.To3DAttributes());
            instance.setProperty(EVENT_PROPERTY.MINIMUM_DISTANCE, 0f);
            instance.setProperty(EVENT_PROPERTY.MAXIMUM_DISTANCE, 100f);
            instance.start();
            instance.release();
        }
        public override void Process(PlayFMODAsset packet)
        {
            EventInstance instance = FMODUWE.GetEvent(packet.AssetPath);

            instance.setProperty(EVENT_PROPERTY.MINIMUM_DISTANCE, 1f);
            instance.setProperty(EVENT_PROPERTY.MAXIMUM_DISTANCE, packet.Radius);
            instance.setVolume(packet.Volume);
            instance.set3DAttributes(packet.Position.ToUnity().To3DAttributes());
            instance.start();
            instance.release();
        }
Example #3
0
        public void PlayCustomLoopingEmitter(string path)
        {
            FMOD_CustomLoopingEmitter loopingEmitter = loopingEmitters[path].Key;
            EventInstance             eventInstance  = FMODUWE.GetEvent(path);

            eventInstance.set3DAttributes(loopingEmitter.transform.To3DAttributes());
            eventInstance.setProperty(EVENT_PROPERTY.MINIMUM_DISTANCE, 1f);
            eventInstance.setProperty(EVENT_PROPERTY.MAXIMUM_DISTANCE, loopingEmitters[path].Value);
            eventInstance.start();
            eventInstance.release();
            timeLastStopSoundField.SetValue(loopingEmitter, Time.time);
        }
Example #4
0
        public override void Process(PlayFMODAsset packet)
        {
            EventInstance instance = FMODUWE.GetEvent(packet.AssetPath);

            instance.setProperty(EVENT_PROPERTY.MINIMUM_DISTANCE, 1f);
            instance.setProperty(EVENT_PROPERTY.MAXIMUM_DISTANCE, packet.Radius);
            // Volume is a scalar, is should be limited to 0 and we don't need more than 100% volume (i.e. 1.0).
            // See docs: https://fmod.com/resources/documentation-api?version=2.00&page=studio-api-eventinstance.html#studio_eventinstance_setvolume
            instance.setVolume(Mathf.Clamp01(packet.Volume));
            instance.set3DAttributes(packet.Position.ToUnity().To3DAttributes());
            instance.start();
            instance.release();
        }
        public EventInstance?PlayOneShot(FMODAsset asset, Vector3 position, float volume = 1.0f, float duration = -1.0f)
        {
            EventInstance?result = null;

            try
            {
                EventInstance eventInstance2 = FMODUWE.GetEvent(asset);
                eventInstance2.setVolume(volume);
                eventInstance2.set3DAttributes(position.To3DAttributes());
                eventInstance2.start();
                if (duration > 0.0f)
                {
                    playingSounds.Add(new EventInstance?(eventInstance2), Time.time + duration);
                    Invoke("StopSounds", duration + 0.1f);
                }
                else
                {
                    eventInstance2.release();
                }
                result = eventInstance2;
            }
            catch { }
            return(result);
        }