public static void UpdateLoopingEvents(List <FMODCommon.LoopingEventInfo> loopingEvents, Animator animator, Transform transform) { bool flag = animator.IsInTransition(0); AnimatorStateInfo currentAnimatorStateInfo = animator.GetCurrentAnimatorStateInfo(0); FMOD.Studio.ATTRIBUTES_3D attributes = default(FMOD.Studio.ATTRIBUTES_3D); if (transform.hasChanged) { attributes = transform.to3DAttributes(); } int i = 0; while (i < loopingEvents.Count) { FMODCommon.LoopingEventInfo loopingEventInfo = loopingEvents[i]; if (flag || currentAnimatorStateInfo.fullPathHash != loopingEventInfo.startState) { UnityUtil.ERRCHECK(loopingEventInfo.instance.stop(STOP_MODE.ALLOWFADEOUT)); UnityUtil.ERRCHECK(loopingEventInfo.instance.release()); loopingEvents.RemoveAt(i); } else { if (transform.hasChanged) { UnityUtil.ERRCHECK(loopingEventInfo.instance.set3DAttributes(attributes)); } i++; } } }
private void OnDisable() { if (this.loopingEvents != null) { int count = this.loopingEvents.Count; for (int i = 0; i < count; i++) { FMODCommon.LoopingEventInfo loopingEventInfo = this.loopingEvents[i]; if (loopingEventInfo.instance.isValid()) { UnityUtil.ERRCHECK(loopingEventInfo.instance.stop(STOP_MODE.ALLOWFADEOUT)); UnityUtil.ERRCHECK(loopingEventInfo.instance.release()); } } this.loopingEvents.Clear(); } if (this.oneshotEvents != null) { int count2 = this.oneshotEvents.Count; for (int j = 0; j < count2; j++) { FMODCommon.OneshotEventInfo oneshotEventInfo = this.oneshotEvents[j]; if (oneshotEventInfo.instance.isValid()) { UnityUtil.ERRCHECK(oneshotEventInfo.instance.stop(STOP_MODE.ALLOWFADEOUT)); UnityUtil.ERRCHECK(oneshotEventInfo.instance.release()); } } this.oneshotEvents.Clear(); } }
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)); } }