FMOD.RESULT LogSoundDefStart(FmodEventAudioSource src, string soundDefName, int waveIndexInSoundDef) { Debug.Log("TEST: Audiosource '" + src.name + "' event '" + src.getSource().getName() + " just started sound def '" + soundDefName + "' with sound of index '" + waveIndexInSoundDef + "'" ); return (FMOD.RESULT.OK); }
protected void CreateEventInstance(FmodEvent srcEvent, Vector3 worldPos, RaycastHit hitInfo) { FmodEventAudioSource audioSource = null; if (Event.current.alt) // if alt is on, we add the audio source as a component { GameObject dest = hitInfo.collider.gameObject; audioSource = dest.GetComponent <FmodEventAudioSource>(); if (audioSource == null || audioSource.eventClip != null) { audioSource = dest.AddComponent(typeof(FmodEventAudioSource)) as FmodEventAudioSource; } } else // else we create a GameObject to act as source { GameObject obj = GameObject.Instantiate(Resources.Load("FmodEventAudioSource"), worldPos, Quaternion.identity) as GameObject; audioSource = obj.GetComponent <FmodEventAudioSource>(); if (audioSource == null) { Debug.LogError("Prefab for FmodEventAudioSource should have component FmodEventAudioSource !"); } else { obj.name = "FmodEventSource (" + srcEvent.name + ")"; } } audioSource.SetSourceEvent(srcEvent); }
public void OnGUI() { this.title = "Active Audio Sources"; if (Application.isPlaying == false) { EditorGUILayout.HelpBox("Application not playing", MessageType.Info, true); Repaint(); return; } List <FmodEventAudioSource> sources = FmodEventAudioSource.getAllAudioSources(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Source name", GUILayout.Width(4 * this.position.width / 10)); EditorGUILayout.LabelField("Event name", GUILayout.Width(3 * this.position.width / 10)); EditorGUILayout.LabelField("Status", GUILayout.Width(2 * this.position.width / 10)); EditorGUILayout.EndHorizontal(); foreach (FmodEventAudioSource src in sources) { if (src != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(src.name, GUILayout.Width(4 * this.position.width / 10)); EditorGUILayout.LabelField((src.getSource() == null ? "(No event selected)" : src.getSource().getName()), GUILayout.Width(3 * this.position.width / 10)); EditorGUILayout.LabelField(src.getStatus(), GUILayout.Width(2 * this.position.width / 10)); EditorGUILayout.EndHorizontal(); } } Repaint(); }
FMOD.RESULT ForbidEventStolen(FmodEventAudioSource src) { if (forbidEventStealth) { Debug.Log("TEST: Audiosource '" + src.name + "' event '" + src.getSource().getName() + " won't be stolen on my watch !"); return (FMOD.RESULT.ERR_EVENT_FAILED); } return (FMOD.RESULT.OK); }
FMOD.RESULT ForbidEventStolen(FmodEventAudioSource src) { if (forbidEventStealth) { Debug.Log("TEST: Audiosource '" + src.name + "' event '" + src.getSource().getName() + " won't be stolen on my watch !"); return(FMOD.RESULT.ERR_EVENT_FAILED); } return(FMOD.RESULT.OK); }
public void loadEvent(FmodEventAudioSource src) { if (src != null && src.getSource() != null) { FmodEventPool pool = m_eventPoolManager.getEventPool(src.getSource()); ERRCHECK(pool.getEvent(src)); } }
public static void RestoreAssets() { foreach (UnityEngine.Object obj in Resources.FindObjectsOfTypeAll(typeof(FmodEventAudioSource))) { FmodEventAudioSource src = obj as FmodEventAudioSource; if (src != null) { src.RestoreAsset(); } } }
public static void UpdateRestorationData() { foreach (UnityEngine.Object obj in Resources.FindObjectsOfTypeAll(typeof(FmodEventAudioSource))) { FmodEventAudioSource src = obj as FmodEventAudioSource; if (src != null) { src.UpdateRestorationData(); } } }
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 releaseRunningInstance(FmodEventAudioSource runningSource) { if (runningSource != null && runningSource.getSource() != null) { FmodEvent evt = runningSource.getSource(); if (m_eventPoolManager.eventPoolExists(evt) == false) { Debug.LogError("CRITICAL ERROR: No pool was created for event " + evt.getName()); } else { m_eventPoolManager.getEventPool(evt).releaseRunningInstance(runningSource); } } }
public void OnSceneGUI() { FmodEventAudioSource source = target as FmodEventAudioSource; source.CheckForOldFormat(); if (source != null && source.getSource() != null && source.getSourceType() == FmodEvent.SourceType.SOURCE_3D) { float prevVal; float val; SerializedProperty minRangeProp; SerializedProperty maxRangeProp; if (m_source == null) { m_source = new SerializedObject(source.getSource()); } minRangeProp = m_source.FindProperty("m_minRange"); maxRangeProp = m_source.FindProperty("m_maxRange"); prevVal = source.getMinRange(); val = Handles.RadiusHandle(source.transform.rotation, source.transform.position, prevVal); minRangeProp.floatValue = val; if (val != prevVal) { source.setMinRange(val); } prevVal = source.getMaxRange(); val = Handles.RadiusHandle(source.transform.rotation, source.transform.position, prevVal); maxRangeProp.floatValue = val; if (val != prevVal) { source.setMaxRange(val); } if (m_source.ApplyModifiedProperties()) { source.setMinRange(source.getMinRange()); source.setMaxRange(source.getMaxRange()); } if (GUI.changed) { EditorUtility.SetDirty(target); } } }
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 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); }
public override void OnInspectorGUI() { if (target == null) { return; } FmodEventAudioSource source = target as FmodEventAudioSource; string typeString; List <FmodRuntimeEventParameter> parameters; bool shouldRepaint = false; source.CheckForOldFormat(); if (source.getSource() == null) { parameters = new List <FmodRuntimeEventParameter>(); typeString = "No event is loaded"; m_show3DSettings = false; } else { typeString = "This is a " + (source.type == FmodEvent.SourceType.SOURCE_2D ? "2D" : "3D") + " event."; m_show3DSettings = (source.type == FmodEvent.SourceType.SOURCE_2D ? false : true); parameters = source.getParameters(); if (m_parameters.Count == 0 && parameters.Count > 0) { foreach (FmodRuntimeEventParameter p in parameters) { m_parameters.Add(new SerializedObject(p)); } } if (m_event == null && source.eventClip != null) { m_event = new SerializedObject(source.eventClip.getSource()); } if (m_event != null) { m_event.Update(); } if (m_source != null && !(m_source.targetObject is FmodEventAudioSource)) { m_source = null; } if (m_source == null && source.getSource() != null) { m_source = new SerializedObject(source); } m_source.Update(); foreach (SerializedObject p in m_parameters) { p.Update(); ((FmodRuntimeEventParameter)p.targetObject).getUnderlyingValue(); } } EditorGUILayout.ObjectField("Source event", source.getSource(), typeof(FmodEvent), false); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); EditorGUILayout.LabelField(typeString, GUI.skin.textField, GUILayout.ExpandWidth(false)); EditorGUILayout.EndHorizontal(); if (source.getSource() != null) { FmodEventAudioSource.Status status = source.CurrentStatus; bool paused = source.Paused; EditorGUILayout.LabelField("Status", source.getStatus(), GUI.skin.textField); GUI.enabled = (Application.isPlaying); if (paused) { if (GUILayout.Button("Unpause")) { source.Unpause(); } } else { if (GUILayout.Button("Pause")) { source.Pause(); } } if (status == FmodEventAudioSource.Status.Stopped) { if (GUILayout.Button("Play")) { source.Play(); } } else if (status == FmodEventAudioSource.Status.Playing) { if (GUILayout.Button("Stop")) { source.Stop(); } } GUI.enabled = true; } m_showParams = EditorGUILayout.Foldout(m_showParams, "Parameters"); if (m_showParams) { EditorGUI.indentLevel += 2; if (m_parameters.Count > 0) { foreach (SerializedObject o in m_parameters) { FmodRuntimeEventParameter p = o.targetObject as FmodRuntimeEventParameter; SerializedProperty prop = o.FindProperty("m_value"); if (p.getName() == "(distance)" || p.getName() == "(listener angle)" || p.getName() == "(event angle)") { EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(p.getName()); EditorGUILayout.HelpBox("Parameters named '" + p.getName() + "' are reserved by FMOD for 3D sounds", MessageType.None); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.Slider(prop, p.MinRange, p.MaxRange, p.getName()); } if (p == null || p.m_parameter == null) { Debug.LogWarning("Error happening in gameObject " + source.gameObject); } shouldRepaint = (shouldRepaint || p.Velocity != 0); } } else { if (source.eventClip == null) { EditorGUILayout.LabelField("Load an event to see its parameters"); } else { EditorGUILayout.LabelField("This event has no parameters."); } } EditorGUI.indentLevel -= 2; } if (m_source != null && source.getSource()) { if (m_source.FindProperty("m_volume") == null) { Debug.Log("NULL volume !"); } EditorGUILayout.Slider(m_source.FindProperty("m_volume"), 0, 100, "Volume"); m_show3DSettings = EditorGUILayout.Foldout(m_show3DSettings, "3D Sound Settings"); if (m_show3DSettings) { EditorGUI.indentLevel += 2; FmodEvent.RolloffType rolloffType = ((FmodEvent)source.getSource()).Rolloff; SerializedProperty minRangeProp = m_source.FindProperty("m_minRange"); SerializedProperty maxRangeProp = m_source.FindProperty("m_maxRange"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Rolloff"); EditorGUILayout.LabelField(((FmodEvent)source.getSource()).getRolloffTypeString(), GUI.skin.textField, GUILayout.ExpandWidth(false)); EditorGUILayout.EndHorizontal(); if (rolloffType == FmodEvent.RolloffType.CUSTOM) { EditorGUILayout.HelpBox("This event has a custom rolloff : the Min Distance parameter is unused and the Max Distance parameter acts as a distance multiplier.", MessageType.Warning); } EditorGUILayout.PropertyField(minRangeProp, new GUIContent("Min Distance")); EditorGUILayout.PropertyField(maxRangeProp, new GUIContent("Max Distance")); EditorGUI.indentLevel -= 2; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Play On Awake"); source.playOnAwake = EditorGUILayout.Toggle(source.playOnAwake); EditorGUILayout.EndHorizontal(); /* * UNDERLYING VALUES */ EditorGUILayout.Separator(); m_showUnderlyingParameters = EditorGUILayout.Foldout(m_showUnderlyingParameters, "Underlying parameters value"); if (m_showUnderlyingParameters) { EditorGUI.indentLevel += 2; if (m_parameters.Count > 0) { GUI.enabled = false; foreach (SerializedObject o in m_parameters) { FmodRuntimeEventParameter p = o.targetObject as FmodRuntimeEventParameter; SerializedProperty underlyingValueProp = o.FindProperty("m_underlyingValue"); EditorGUILayout.Slider(underlyingValueProp, p.MinRange, p.MaxRange, p.getName()); } GUI.enabled = true; } else { if (source.eventClip == null) { EditorGUILayout.LabelField("Load an event to see its parameters"); } else { EditorGUILayout.LabelField("This event has no parameters."); } } EditorGUI.indentLevel -= 2; } /* * END UNDERLYING VALUES */ foreach (SerializedObject o in m_parameters) { if (o.ApplyModifiedProperties()) { FmodRuntimeEventParameter p = o.targetObject as FmodRuntimeEventParameter; p.UpdateValue(); } } if (m_source.ApplyModifiedProperties()) { FmodEvent evt = source.getSource(); if (evt.getSourceType() == FmodEvent.SourceType.SOURCE_3D) { source.setMinRange(source.getMinRange()); source.setMaxRange(source.getMaxRange()); } source.SetVolume(source.GetVolume()); } if (GUI.changed) { EditorUtility.SetDirty(target); } if (m_showUnderlyingParameters || shouldRepaint) { Repaint(); } } }
public void releaseRunningInstance(FmodEventAudioSource runningSource) { if (runningSource != null && runningSource.getSource() != null) { FmodEvent evt = runningSource.getSource(); if (m_eventPoolManager.eventPoolExists(evt) == false) { Debug.LogError("CRITICAL ERROR: No pool was created for event " + evt.getName()); } else { m_eventPoolManager.getEventPool(evt).releaseRunningInstance(runningSource); } } }
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); }
public void loadEvent(FmodEventAudioSource src) { if (src != null && src.getSource() != null) { FmodEventPool pool = m_eventPoolManager.getEventPool(src.getSource()); ERRCHECK(pool.getEvent(src)); } }
FMOD.RESULT LogEventStart(FmodEventAudioSource src) { Debug.Log("TEST: Audiosource '" + src.name + "' just started event '" + src.getSource().getName()); return (FMOD.RESULT.OK); }
FMOD.RESULT LogEventStolen(FmodEventAudioSource src) { Debug.Log("TEST: Audiosource '" + src.name + "' event '" + src.getSource().getName() + " is being stolen"); return(FMOD.RESULT.OK); }
FMOD.RESULT LogEventFinished(FmodEventAudioSource src) { Debug.Log("TEST: Audiosource '" + src.name + "' just finished event '" + src.getSource().getName()); return(FMOD.RESULT.OK); }
FMOD.RESULT LogEventStolen(FmodEventAudioSource src) { Debug.Log("TEST: Audiosource '" + src.name + "' event '" + src.getSource().getName() + " is being stolen"); return (FMOD.RESULT.OK); }
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."); } }