/// <summary>
        /// Play an audio file inside an FMOD Event. Will play once without taking in 3D position
        /// </summary>
        /// <param name="audioFile">Audio file.</param>
        /// <param name="eventName">Event name.</param>
        public static void PlayOneShotProgrammerSound(string audioFile, string eventName)
        {
            audioFile = ExtensionsUtils.FindFile(audioFile);

            // Create the callback that will handle creating and destroying the programmer sound
            EVENT_CALLBACK callback = new EVENT_CALLBACK(ProgrammerEventCallback);

            // Create our one time event
            EventDescription eventDescription = RuntimeManager.GetEventDescription(eventName);
            EventInstance    eventInstance;

            eventDescription.createInstance(out eventInstance);

            // Set callback
            eventInstance.setCallback(callback);

            // Create our user data that we'll user later when playing the event
            ProgrammerSoundContext context = new ProgrammerSoundContext
            {
                file = audioFile,
                mode = MODE.CREATESAMPLE | MODE.LOOP_NORMAL | MODE.NONBLOCKING
            };

            // Create our pointer. It is unpinned when we get this data later
            GCHandle handle = GCHandle.Alloc(context, GCHandleType.Pinned);

            eventInstance.setUserData(GCHandle.ToIntPtr(handle));

            eventInstance.start();
            eventInstance.release();
        }
        /// <summary>
        /// Play an audio file inside an FMOD event. Will play once at a given position
        /// </summary>
        /// <param name="audioFile">Audio file.</param>
        /// <param name="eventName">Event name.</param>
        /// <param name="position">Position.</param>
        public static void PlayOneShotProgrammerSound(string audioFile, string eventName, Vector3 position)
        {
            audioFile = ExtensionsUtils.FindFile(audioFile);

            EVENT_CALLBACK callback = new EVENT_CALLBACK(ProgrammerEventCallback);

            EventDescription eventDescription = RuntimeManager.GetEventDescription(eventName);
            EventInstance    eventInstance;

            eventDescription.createInstance(out eventInstance);

            eventInstance.set3DAttributes(RuntimeUtils.To3DAttributes(position));

            eventInstance.setCallback(callback);

            ProgrammerSoundContext context = new ProgrammerSoundContext();

            context.file = audioFile;
            context.mode = MODE.CREATESAMPLE | MODE._3D_LINEARSQUAREROLLOFF | MODE.LOOP_NORMAL | MODE.NONBLOCKING;

            GCHandle handle = GCHandle.Alloc(context, GCHandleType.Pinned);

            eventInstance.setUserData(GCHandle.ToIntPtr(handle));

            eventInstance.start();
            eventInstance.release();
        }
Esempio n. 3
0
    public EventInstance GetEvent(string path)
    {
        EventInstance eventInstance = null;

        if (string.IsNullOrEmpty(path))
        {
            UnityUtil.LogError("Empty event path!");
            return(null);
        }
        if (this.eventDescriptions.ContainsKey(path))
        {
            FMOD_StudioSystem.ERRCHECK(this.eventDescriptions[path].createInstance(out eventInstance));
        }
        else
        {
            EventDescription eventDescription = null;
            FMOD_StudioSystem.ERRCHECK(this.system.getEvent(path, out eventDescription));
            if (eventDescription != null && eventDescription.isValid())
            {
                this.eventDescriptions.Add(path, eventDescription);
                FMOD_StudioSystem.ERRCHECK(eventDescription.createInstance(out eventInstance));
            }
        }
        if (eventInstance == null)
        {
            UnityUtil.Log("GetEvent FAILED: \"" + path + "\"");
        }
        return(eventInstance);
    }
Esempio n. 4
0
 public void Attach_Wind_Emitter()
 {
     event_Description.createInstance(out event_Instance);
     RuntimeManager.AttachInstanceToGameObject(event_Instance, transform, GetComponent <Rigidbody>());
     event_Instance.start();
     event_Instance.release();
     _isPlaying = true;
 }
 private void StartFeederEvent()
 {
     if (!feederEventInstance.isValid() && feederEventDescription.isValid())
     {
         feederEventDescription.createInstance(out feederEventInstance);
         feederEventInstance.start();
     }
 }
Esempio n. 6
0
 public void Play()
 {
     if ((!TriggerOnce || !hasTriggered) && !string.IsNullOrEmpty(Event))
     {
         if (!eventDescription.isValid())
         {
             Lookup();
         }
         bool oneshot = false;
         if (!Event.StartsWith("snapshot", StringComparison.CurrentCultureIgnoreCase))
         {
             eventDescription.isOneshot(out oneshot);
         }
         eventDescription.is3D(out bool is3D);
         if (!instance.isValid())
         {
             instance.clearHandle();
         }
         if (oneshot && instance.isValid())
         {
             instance.release();
             instance.clearHandle();
         }
         if (!instance.isValid())
         {
             eventDescription.createInstance(out instance);
             if (is3D)
             {
                 Rigidbody   component  = GetComponent <Rigidbody>();
                 Rigidbody2D component2 = GetComponent <Rigidbody2D>();
                 Transform   component3 = GetComponent <Transform>();
                 if ((bool)component)
                 {
                     instance.set3DAttributes(RuntimeUtils.To3DAttributes(base.gameObject, component));
                     RuntimeManager.AttachInstanceToGameObject(instance, component3, component);
                 }
                 else
                 {
                     instance.set3DAttributes(RuntimeUtils.To3DAttributes(base.gameObject, component2));
                     RuntimeManager.AttachInstanceToGameObject(instance, component3, component2);
                 }
             }
         }
         ParamRef[] @params = Params;
         foreach (ParamRef paramRef in @params)
         {
             instance.setParameterValue(paramRef.Name, paramRef.Value);
         }
         if (is3D && OverrideAttenuation)
         {
             instance.setProperty(EVENT_PROPERTY.MINIMUM_DISTANCE, OverrideMinDistance);
             instance.setProperty(EVENT_PROPERTY.MAXIMUM_DISTANCE, OverrideMaxDistance);
         }
         instance.start();
         hasTriggered = true;
     }
 }
Esempio n. 7
0
 public void Start(EventDescription eventDescription, int gradientParameterIndex, int wetnessParameterIndex, WaterOnTerrainSFX.IntVector localPosition, Vector3 eventPosition, float gradient)
 {
     this.localPosition          = localPosition;
     this.eventPosition          = eventPosition;
     this.gradientParameterIndex = gradientParameterIndex;
     this.wetnessParameterIndex  = wetnessParameterIndex;
     UnityUtil.ERRCHECK(eventDescription.createInstance(out this.eventInstance));
     UnityUtil.ERRCHECK(this.eventInstance.set3DAttributes(eventPosition.to3DAttributes()));
     this.SetGradient(gradient);
     UnityUtil.ERRCHECK(this.eventInstance.start());
 }
Esempio n. 8
0
 static EventInstance GetEventInstance(string path, out EventDescription eventDescription)
 {
     try
     {
         EventInstance result;
         if (EventCache.TryGetValue(path, out result))
         {
             EventDescriptionCache.TryGetValue(path, out eventDescription); return(result);
         }
         eventDescription = GetEventDescription(path);
         FmodErrorCheck(eventDescription.createInstance(out result));
         result.set3DAttributes(default);
Esempio n. 9
0
        private void ActivateSnapshot()
        {
            FMOD.RESULT result = eventDescription.createInstance(out eventInstance);

            if (result != FMOD.RESULT.OK)
            {
                Debug.LogError("Activation of pause menu snapshot failed. Fmod error: " + result);
                return;
            }

            eventInstance.start();
        }
    private void playFMODEvent(string path, bool enableTimeout)
    {
        if (!base.isActiveAndEnabled)
        {
            return;
        }
        if (!FMOD_StudioSystem.instance || FMOD_StudioSystem.instance.ShouldBeCulled(path, this.eventTransform.position))
        {
            return;
        }
        EventDescription eventDescription = FMOD_StudioSystem.instance.GetEventDescription(path, true);

        if (eventDescription == null)
        {
            Debug.LogWarning("Couldn't get event '" + path + "'");
            return;
        }
        bool flag;

        UnityUtil.ERRCHECK(eventDescription.isOneshot(out flag));
        int num = 0;

        if (this.animator != null)
        {
            num = this.animator.GetCurrentAnimatorStateInfo(0).fullPathHash;
        }
        if (!flag)
        {
            for (int i = 0; i < this.loopingEvents.Count; i++)
            {
                FMODCommon.LoopingEventInfo loopingEventInfo = this.loopingEvents[i];
                if (loopingEventInfo.startState == num && loopingEventInfo.path == path)
                {
                    return;
                }
            }
        }
        EventInstance eventInstance;

        UnityUtil.ERRCHECK(eventDescription.createInstance(out eventInstance));
        UnityUtil.ERRCHECK(eventInstance.set3DAttributes(this.eventTransform.to3DAttributes()));
        UnityUtil.ERRCHECK(eventInstance.start());
        if (flag)
        {
            this.oneshotEvents.Add(new FMODCommon.OneshotEventInfo(eventInstance, enableTimeout));
        }
        else
        {
            this.loopingEvents.Add(new FMODCommon.LoopingEventInfo(path, eventInstance, num));
        }
    }
Esempio n. 11
0
    public void Init_Event(string event_Ref)
    {
        event_Description = RuntimeManager.GetEventDescription(event_Ref);
        event_Description.loadSampleData();
        event_Description.createInstance(out event_Instance);
        event_Description.getMaximumDistance(out _maxDistance);
        event_Description.is3D(out _is3D);
        event_Description.getParameterDescriptionCount(out int _parameterCount);
        if (_parameterCount > 0)
        {
            EventDescription isShyEventDescription;
            event_Instance.getDescription(out isShyEventDescription);
            PARAMETER_DESCRIPTION isShyParameterDescription;
            isShyEventDescription.getParameterDescriptionByName("is_shy", out isShyParameterDescription);
            _isShyParameterId = isShyParameterDescription.id;

            _isShy = true;
        }
    }
Esempio n. 12
0
    public EventInstance GetEvent(string path)
    {
        EventInstance eventInstance = null;

        if (string.IsNullOrEmpty(path))
        {
            UnityUtil.LogError("Empty event path!");
            return(null);
        }
        if (this.eventDescriptions.ContainsKey(path) && this.eventDescriptions[path].isValid())
        {
            FMOD_StudioSystem.ERRCHECK(this.eventDescriptions[path].createInstance(out eventInstance));
        }
        else
        {
            Guid guid = default(Guid);
            if (path.StartsWith("{"))
            {
                FMOD_StudioSystem.ERRCHECK(Util.ParseID(path, out guid));
            }
            else if (path.StartsWith("event:") || path.StartsWith("snapshot:"))
            {
                FMOD_StudioSystem.ERRCHECK(this.system.lookupID(path, out guid));
            }
            else
            {
                UnityUtil.LogError("Expected event path to start with 'event:/' or 'snapshot:/'");
            }
            EventDescription eventDescription = null;
            FMOD_StudioSystem.ERRCHECK(this.system.getEventByID(guid, out eventDescription));
            if (eventDescription != null && eventDescription.isValid())
            {
                this.eventDescriptions[path] = eventDescription;
                FMOD_StudioSystem.ERRCHECK(eventDescription.createInstance(out eventInstance));
            }
        }
        if (eventInstance == null)
        {
            UnityUtil.Log("GetEvent FAILED: \"" + path + "\"");
        }
        return(eventInstance);
    }
        private void StartSound(Vector3 closestPoint = default)
        {
            outputEventDescription.createInstance(out outputEventInstance);

            if (outputEventInstance.isValid())
            {
                if (listenerIsInside)
                {
                    UpdateEventPosition(playerAudioActorTag.transform.position);
                }
                else
                {
                    UpdateEventPosition(closestPoint);
                }

                outputEventInstance.start();

                if (feeder != null)
                {
                    feeder.ReportOutputStart(this);
                }
            }
        }
Esempio n. 14
0
    public void Attach_Local_Emitter(Transform transform, Rigidbody rigidbody)
    {
        if (!_is3D)
        {
            return;
        }

        event_Description.createInstance(out event_Instance);
        RuntimeManager.AttachInstanceToGameObject(event_Instance, transform, rigidbody);
        event_Instance.start();
        _isPlaying = true;

        event_Description.getParameterDescriptionCount(out int _parameterCount);
        if (_parameterCount > 0)
        {
            EventDescription isShyEventDescription;
            event_Instance.getDescription(out isShyEventDescription);
            PARAMETER_DESCRIPTION isShyParameterDescription;
            isShyEventDescription.getParameterDescriptionByName("is_shy", out isShyParameterDescription);
            _isShyParameterId = isShyParameterDescription.id;
            _isShy            = true;
        }
    }
Esempio n. 15
0
 private void OnEnable()
 {
     underwater_Description.createInstance(out underwater_Instance);
     underwater_Instance.start();
 }
Esempio n. 16
0
 public void Attach_Rain_Emitter()
 {
     event_Description.createInstance(out event_Instance);
 }