public void SetEvent(FMOD.Event evt) { if (evt == null) { if (m_runtimeEvent != null) { if (m_eventSystemHandle != null && m_eventSystemHandle.getEventSystem() != null && m_eventSystemHandle.getEventSystem().wasCleaned() == false) { Stop(); CleanParameters(); m_eventSystemHandle.getEventSystem().releaseRunningInstance(this); } freeEventData(); m_runtimeEvent = null; } } else { m_runtimeEvent = evt; foreach (FmodRuntimeEventParameter param in getParameters()) { param.SetEvent(m_runtimeEvent); } setMinRange(getMinRange()); setMaxRange(getMaxRange()); if (!m_selfHandle.IsAllocated) { m_selfHandle = GCHandle.Alloc(this, GCHandleType.Normal); } ERRCHECK(evt.setCallback(FmodEventAudioSource.EventStoppedCallbackStatic, (IntPtr)m_selfHandle)); } }
public void releaseRunningInstance(FmodEventAudioSource runningSource) { if (runningSource == null || runningSource.getSource() == null) { Debug.LogError(getErrorPrefix() + "Invalid data was passed for FmodEventAudioSource"); return; } if (runningSource.getSource() != m_event) { Debug.LogError(getErrorPrefix() + "FmodEventAudioSource tried to load event '" + runningSource.getSource().getName() + "' from the bad pool."); return; } FMOD.Event instance = runningSource.getRuntimeEvent(); if (m_activeSources.Contains(runningSource)) { if (instance != null) { m_availableEvents.Add(instance); } m_activeSources.Remove(runningSource); } else { Debug.LogError("this should not happen; Ever."); } }
public void BombWickFmodSound(TimeSpan alarm, ref FMOD.Event evt, ref FMOD.EventParameter evntParam) { if (this.GameTimer.Time < alarm && !this.MecheBomb.Finished && this.GameTimer.Time > TimeSpan.FromSeconds(0.0) && this.Result == 0) { FmodFactory.Instance.start(ref evt); FmodFactory.Instance.update(this.GameTimer.Time.Seconds, ref evntParam); } }
public FMOD.RESULT getEvent(FmodEventAudioSource wantedSource) { if (wantedSource == null || wantedSource.getSource() == null) { Debug.LogError(getErrorPrefix() + "Invalid data was passed for FmodEventAudioSource"); return(FMOD.RESULT.ERR_EVENT_FAILED); } if (wantedSource.getSource() != m_event) { Debug.LogError(getErrorPrefix() + "FmodEventAudioSource tried to load event '" + wantedSource.getSource().getName() + "' from the bad pool."); return(FMOD.RESULT.ERR_EVENT_FAILED); } if (wantedSource.isRuntimeEventLoaded()) { return(FMOD.RESULT.OK); } if (m_availableEvents.Count > 0) { // below, we take back an event that was loaded and unused FMOD.Event oldestEvent = m_availableEvents[0]; m_availableEvents.RemoveAt(0); wantedSource.SetEvent(oldestEvent); if (m_activeSources.Contains(wantedSource)) { Debug.LogWarning(getErrorPrefix() + "FmodEventAudioSource '" + wantedSource.name + "' loaded an event but was already active. Are you sure this should happen ?"); } else { m_activeSources.Add(wantedSource); } } else { // here we have no event loaded, so we must load a new one. using (FmodEventSystemHandle handle = new FmodEventSystemHandle()) { FmodEventSystem system = handle.getEventSystem(); if (system != null && system.wasCleaned() == false) { FMOD.RESULT result = FMOD.RESULT.OK; result = system.loadEventFromFile(wantedSource); if (result == FMOD.RESULT.OK) { m_activeSources.Add(wantedSource); } return(result); } } } return(FMOD.RESULT.OK); }
public void Initialize(FMOD.EventGroup eventgroup, FmodEventGroup parentGroup, FmodEventAsset asset) { FMOD.EventGroup childEventgroup = null; FMOD.RESULT result = FMOD.RESULT.OK; FmodEventGroup child = null; int numChildrenGroups = 0; int numEvents = 0; FMOD.Event e = null; FmodEvent toAdd = null; hideFlags = HideFlags.HideInHierarchy; m_projectName = asset.getProjectName(); m_parent = parentGroup; _getName(eventgroup); result = eventgroup.loadEventData(); ERRCHECK(result); result = eventgroup.getNumEvents(ref numEvents); ERRCHECK(result); for (int j = 0; j < numEvents; j++) { e = null; result = eventgroup.getEventByIndex(j, FMOD.EVENT_MODE.DEFAULT | FMOD.EVENT_MODE.ERROR_ON_DISKACCESS, ref e); ERRCHECK(result); if (result != FMOD.RESULT.OK) { result = FMOD.RESULT.OK; } toAdd = FmodEvent.CreateInstance("FmodEvent") as FmodEvent; if (e != null) { toAdd.Initialize(e, this, j, asset); e.release(); } else { toAdd.Initialize(this, j, asset); } m_events.Add(toAdd); } result = eventgroup.freeEventData(false); ERRCHECK(result); result = eventgroup.getNumGroups(ref numChildrenGroups); for (int k = 0; k < numChildrenGroups; k++) { result = eventgroup.getGroupByIndex(k, false, ref childEventgroup); ERRCHECK(result); child = FmodEventGroup.CreateInstance("FmodEventGroup") as FmodEventGroup; child.Initialize(childEventgroup, this, asset); m_children.Add(child); } name = getFullName(); }
void cleanInvalidHandle() { foreach (FmodRuntimeEventParameter p in m_parameters) { p.Clean(); } // in the case of a invalid handle, we don't put the handle back in the pool, since it's invalid. The one that stole it should alreayd be in it anyway. // however, we should remove the audiosource from the list of active sources m_runtimeEvent = null; if (m_eventSystemHandle != null && m_eventSystemHandle.getEventSystem() != null && m_eventSystemHandle.getEventSystem().wasCleaned()) { m_eventSystemHandle.getEventSystem().releaseRunningInstance(this); } m_status = Status.Stopped; }
private FMOD.RESULT _loadEvent(FmodEvent evt, ref FMOD.Event fmodEvent) { string guidString = evt.getGUIDString(); FMOD.RESULT result = FMOD.RESULT.OK; if (guidString != FmodEvent.EMPTY_GUIDSTRING) { result = getEventSystem().getEventByGUIDString(guidString, FMOD.EVENT_MODE.DEFAULT | FMOD.EVENT_MODE.ERROR_ON_DISKACCESS, ref fmodEvent); } else { string fullName = evt.getFullName(); result = getEventSystem().getEvent(fullName, FMOD.EVENT_MODE.DEFAULT | FMOD.EVENT_MODE.ERROR_ON_DISKACCESS, ref fmodEvent); } return(result); }
public FMOD.RESULT loadEventFromFile(FmodEventAudioSource src) { FmodEvent evt = src.getSource(); FmodEventAsset asset = evt.getAsset(); FMOD.RESULT result = FMOD.RESULT.OK; FMOD.EVENT_LOADINFO loadInfo = new FMOD.EVENT_LOADINFO(); FMOD.EventProject project = null; FMOD.Event fmodEvent = null; _loadFile(asset.getMediaPath(), asset.getName(), ref loadInfo, ref project); _loadEventGroup(evt); result = _loadEvent(evt, ref fmodEvent); ERRCHECK(result); if (result == FMOD.RESULT.OK) { src.SetEvent(fmodEvent); } return(result); }
protected void CleanRuntimeEvent() { CleanParameters(); // replace the member handle by a tmp handle created here... or not. it could lead to another one being created. if (m_runtimeEvent != null && m_eventSystemHandle != null) { if (m_eventSystemHandle.getEventSystem().wasCleaned() == false) { FMOD.RESULT result = FMOD.RESULT.OK; result = m_runtimeEvent.stop(false); SetEvent(null); ERRCHECK(result); if (result != FMOD.RESULT.ERR_INVALID_HANDLE) { //m_runtimeEvent.release(true, false); //we should check EVENTPROPERTY_EVENTTYPE to know if it is a simple event, and only call it if the event is simple } } m_runtimeEvent = null; } }
public void SetEvent(FMOD.Event evt) { FMOD.RESULT result = FMOD.RESULT.OK; FMOD.EventParameter param = null; hideFlags = HideFlags.HideInInspector | HideFlags.HideInHierarchy; if (m_parameter != null) { result = evt.getParameter(m_parameter.getName(), ref param); ERRCHECK(result); if (result == FMOD.RESULT.OK) { m_runtimeParam = param; result = m_runtimeParam.setValue(m_value); ERRCHECK(result); } } else { Debug.Log("Error: This component should not exist now if its parameter is null"); } }
public void Initialize(FMOD.Event e, FmodEventGroup eventGroup, int indexInGroup, FmodEventAsset asset) { #if UNITY_EDITOR FMOD.EVENT_INFO info = new FMOD.EVENT_INFO(); FMOD.GUID guid = new FMOD.GUID(); FMOD.EventParameter param = null; FMOD.RESULT result = FMOD.RESULT.OK; FmodEventParameter toAdd = null; IntPtr name = new IntPtr(0); int numParameters = 0; int index = 0; Initialize(eventGroup, indexInGroup, asset); int size = System.Runtime.InteropServices.Marshal.SizeOf(typeof(FMOD.GUID)); info.guid = System.Runtime.InteropServices.Marshal.AllocHGlobal(size); result = e.getInfo(ref index, ref name, ref info); ERRCHECK(result); m_name = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(name); this.name = m_name; guid = (FMOD.GUID)System.Runtime.InteropServices.Marshal.PtrToStructure(info.guid, typeof(FMOD.GUID)); m_guidString = "{" + String.Format("{0:x8}-{1:x4}-{2:x4}-{3:x2}{4:x2}-{5:x2}{6:x2}{7:x2}{8:x2}{9:x2}{10:x2}", guid.Data1, guid.Data2, guid.Data3, guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7] ) + "}"; int mode = 0; IntPtr modePtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(int)); e.getPropertyByIndex((int)FMOD.EVENTPROPERTY.MODE, modePtr, false); mode = System.Runtime.InteropServices.Marshal.ReadInt32(modePtr); System.Runtime.InteropServices.Marshal.FreeHGlobal(modePtr); m_sourceType = (SourceType)mode; if (m_sourceType == SourceType.SOURCE_3D) { IntPtr range; float[] tmp = new float[1]; int[] tmpInt = new int[1]; range = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(int)); result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_ROLLOFF, range, false); ERRCHECK(result); System.Runtime.InteropServices.Marshal.Copy(range, tmpInt, 0, 1); if (tmpInt[0] == (int)FMOD.MODE._3D_CUSTOMROLLOFF) { m_rolloffType = RolloffType.CUSTOM; } else if (tmpInt[0] == (int)FMOD.MODE._3D_INVERSEROLLOFF) { m_rolloffType = RolloffType.INVERSE; } else if (tmpInt[0] == (int)FMOD.MODE._3D_LINEARROLLOFF) { m_rolloffType = RolloffType.LINEAR; } else if (tmpInt[0] == (int)FMOD.MODE._3D_LINEARSQUAREROLLOFF) { m_rolloffType = RolloffType.LINEARSQUARE; } else if (tmpInt[0] == (int)FMOD.MODE._3D_LOGROLLOFF) { m_rolloffType = RolloffType.LOGARITHMIC; } System.Runtime.InteropServices.Marshal.FreeHGlobal(range); range = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(float)); result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_MINDISTANCE, range, false); ERRCHECK(result); System.Runtime.InteropServices.Marshal.Copy(range, tmp, 0, 1); m_minRange = tmp[0]; System.Runtime.InteropServices.Marshal.FreeHGlobal(range); range = System.Runtime.InteropServices.Marshal.AllocHGlobal(sizeof(float)); result = e.getPropertyByIndex((int)FMOD.EVENTPROPERTY._3D_MAXDISTANCE, range, false); ERRCHECK(result); System.Runtime.InteropServices.Marshal.Copy(range, tmp, 0, 1); m_maxRange = tmp[0]; System.Runtime.InteropServices.Marshal.FreeHGlobal(range); } e.getNumParameters(ref numParameters); for (int k = 0; k < numParameters; k++) { e.getParameterByIndex(k, ref param); toAdd = FmodEventParameter.CreateInstance("FmodEventParameter") as FmodEventParameter; toAdd.Initialize(param, this); m_parameters.Add(toAdd); } m_wasLoaded = true; #endif }