private void LogIfCustomEventMissing(AudioEventGroup eventGroup) { if (!logMissingEvents) { return; } if (eventGroup.isCustomEvent) { if (!eventGroup.customSoundActive || string.IsNullOrEmpty(eventGroup.customEventName)) { return; } } for (var i = 0; i < eventGroup.SoundEvents.Count; i++) { var aEvent = eventGroup.SoundEvents[i]; if (aEvent.currentSoundFunctionType != MasterAudio.EventSoundFunctionType.CustomEventControl) { continue; } string customEventName = aEvent.theCustomEventName; if (!MasterAudio.CustomEventExists(customEventName)) { MasterAudio.LogWarning("Transform '" + this.name + "' is set up to receive or fire Custom Event '" + customEventName + "', which does not exist in Master Audio."); } } }
private IEnumerator TryPlayStartSound(AudioEventGroup grp, AudioEvent aEvent) { for (var i = 0; i < 3; i++) { yield return(StartCoroutine(CoroutineHelper.WaitForRealSeconds(MasterAudio.INNER_LOOP_CHECK_INTERVAL))); var result = PerformSingleAction(grp, aEvent, EventType.OnStart, false); if (result != null && result.SoundPlayed) { break; } } }
private bool CheckForRetriggerLimit(AudioEventGroup grp) { // check for limiting restraints switch (grp.retriggerLimitMode) { case RetriggerLimMode.FrameBased: if (grp.triggeredLastFrame > 0 && Time.frameCount - grp.triggeredLastFrame < grp.limitPerXFrm) { return(false); } break; case RetriggerLimMode.TimeBased: if (grp.triggeredLastTime > 0 && Time.time - grp.triggeredLastTime < grp.limitPerXSec) { return(false); } break; } return(true); }
public void PlaySounds(AudioEventGroup eventGrp, EventType eType) { if (!CheckForRetriggerLimit(eventGrp)) { return; } // set the last triggered time or frame switch (eventGrp.retriggerLimitMode) { case RetriggerLimMode.FrameBased: eventGrp.triggeredLastFrame = Time.frameCount; break; case RetriggerLimMode.TimeBased: eventGrp.triggeredLastTime = Time.time; break; } for (var i = 0; i < eventGrp.SoundEvents.Count; i++) { PerformSingleAction(eventGrp, eventGrp.SoundEvents[i], eType); } }
private bool CheckForRetriggerLimit(AudioEventGroup grp) { // check for limiting restraints switch (grp.retriggerLimitMode) { case RetriggerLimMode.FrameBased: if (grp.triggeredLastFrame > 0 && Time.frameCount - grp.triggeredLastFrame < grp.limitPerXFrm) { return false; } break; case RetriggerLimMode.TimeBased: if (grp.triggeredLastTime > 0 && Time.time - grp.triggeredLastTime < grp.limitPerXSec) { return false; } break; } return true; }
public void PlaySounds(AudioEventGroup eventGrp, EventType eType) { if (!CheckForRetriggerLimit(eventGrp)) { return; } // set the last triggered time or frame switch (eventGrp.retriggerLimitMode) { case RetriggerLimMode.FrameBased: eventGrp.triggeredLastFrame = Time.frameCount; break; case RetriggerLimMode.TimeBased: eventGrp.triggeredLastTime = Time.time; break; } // Pre-warm event sounds! if (!MasterAudio.AppIsShuttingDown && MasterAudio.IsWarming) { var evt = new AudioEvent(); PerformSingleAction(eventGrp, evt, eType); return; } for (var i = 0; i < eventGrp.SoundEvents.Count; i++) { PerformSingleAction(eventGrp, eventGrp.SoundEvents[i], eType); } }
private IEnumerator TryPlayStartSound(AudioEventGroup grp, AudioEvent aEvent) { for (var i = 0; i < 3; i++) { if (MasterAudio.IgnoreTimeScale) { yield return StartCoroutine(CoroutineHelper.WaitForActualSeconds(MasterAudio.INNER_LOOP_CHECK_INTERVAL)); } else { yield return MasterAudio.InnerLoopDelay; } var result = PerformSingleAction(grp, aEvent, EventType.OnStart, false); if (result != null && result.SoundPlayed) { break; } } }
// returns all actions of the given AudioEventGroup that pass the group- and bus filters static IEnumerable <AudioEvent> GetAudioEvents(AudioEventGroup group) { return(group.SoundEvents.Where(IncludeAudioEvent)); }
private PlaySoundResult PerformSingleAction(AudioEventGroup grp, AudioEvent aEvent, EventType eType, bool isFirstTry = true) { if (disableSounds || MasterAudio.AppIsShuttingDown) { return(null); } float volume = aEvent.volume; string sType = aEvent.soundType; float? pitch = aEvent.pitch; if (!aEvent.useFixedPitch) { pitch = null; } PlaySoundResult soundPlayed = null; var soundSpawnModeToUse = soundSpawnMode; if (eType == EventType.OnDisable || eType == EventType.OnDespawned) { soundSpawnModeToUse = MasterAudio.SoundSpawnLocationMode.CallerLocation; } switch (aEvent.currentSoundFunctionType) { case MasterAudio.EventSoundFunctionType.PlaySound: string variationName = null; if (aEvent.variationType == VariationType.PlaySpecific) { variationName = aEvent.variationName; } if (eType == EventType.OnStart && isFirstTry && !MasterAudio.SoundGroupExists(sType)) { // don't try to play sound yet. } else { switch (soundSpawnModeToUse) { case MasterAudio.SoundSpawnLocationMode.CallerLocation: soundPlayed = MasterAudio.PlaySound3DAtTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName); break; case MasterAudio.SoundSpawnLocationMode.AttachToCaller: soundPlayed = MasterAudio.PlaySound3DFollowTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName); break; case MasterAudio.SoundSpawnLocationMode.MasterAudioLocation: soundPlayed = MasterAudio.PlaySound(sType, volume, pitch, aEvent.delaySound, variationName); break; } } if (eType == EventType.OnMouseDrag) { mouseDragResult = soundPlayed; } if (soundPlayed == null || !soundPlayed.SoundPlayed) { if (eType == EventType.OnStart && isFirstTry) { // race condition met. So try to play it a few more times. StartCoroutine(TryPlayStartSound(grp, aEvent)); } return(soundPlayed); } break; case MasterAudio.EventSoundFunctionType.PlaylistControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = true, SoundScheduled = false }; if (string.IsNullOrEmpty(aEvent.playlistControllerName)) { aEvent.playlistControllerName = MasterAudio.ONLY_PLAYLIST_CONTROLLER_NAME; } if (MasterAudio.PlaylistCommandsThatFailOnStart.Contains(aEvent.currentPlaylistCommand) && eType == EventType.OnStart && isFirstTry) { StartCoroutine(TryPlayStartSound(grp, aEvent)); } else { switch (aEvent.currentPlaylistCommand) { case MasterAudio.PlaylistCommand.None: soundPlayed.SoundPlayed = false; break; case MasterAudio.PlaylistCommand.ChangePlaylist: if (string.IsNullOrEmpty(aEvent.playlistName)) { Debug.Log("You have not specified a Playlist name for Event Sounds on '" + this.trans.name + "'."); soundPlayed.SoundPlayed = false; } else { if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.ChangePlaylistByName(aEvent.playlistControllerName, aEvent.playlistName, aEvent.startPlaylist); } } break; case MasterAudio.PlaylistCommand.FadeToVolume: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.FadeAllPlaylistsToVolume(aEvent.fadeVolume, aEvent.fadeTime); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.FadePlaylistToVolume(aEvent.playlistControllerName, aEvent.fadeVolume, aEvent.fadeTime); } break; case MasterAudio.PlaylistCommand.Mute: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.MuteAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.MutePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Unmute: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.UnmuteAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.UnmutePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.ToggleMute: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.ToggleMuteAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.ToggleMutePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.PlayClip: if (string.IsNullOrEmpty(aEvent.clipName)) { Debug.Log("You have not specified a clip name for Event Sounds on '" + this.trans.name + "'."); soundPlayed.SoundPlayed = false; } else { if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { if (!MasterAudio.TriggerPlaylistClip(aEvent.playlistControllerName, aEvent.clipName)) { soundPlayed.SoundPlayed = false; } } } break; case MasterAudio.PlaylistCommand.PlayRandomSong: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.TriggerRandomClipAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.TriggerRandomPlaylistClip(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.PlayNextSong: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.TriggerNextClipAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.TriggerNextPlaylistClip(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Pause: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.PauseAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.PausePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Stop: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.StopAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.StopPlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Resume: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.ResumeAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.ResumePlaylist(aEvent.playlistControllerName); } break; } } break; case MasterAudio.EventSoundFunctionType.GroupControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = true, SoundScheduled = false }; var soundTypesForCmd = new List <string>(); if (!aEvent.allSoundTypesForGroupCmd || MasterAudio.GroupCommandsWithNoAllGroupSelector.Contains(aEvent.currentSoundGroupCommand)) { soundTypesForCmd.Add(aEvent.soundType); } else { soundTypesForCmd.AddRange(MasterAudio.RuntimeSoundGroupNames); } for (var i = 0; i < soundTypesForCmd.Count; i++) { var soundType = soundTypesForCmd[i]; switch (aEvent.currentSoundGroupCommand) { case MasterAudio.SoundGroupCommand.None: soundPlayed.SoundPlayed = false; break; case MasterAudio.SoundGroupCommand.FadeToVolume: MasterAudio.FadeSoundGroupToVolume(soundType, aEvent.fadeVolume, aEvent.fadeTime); break; case MasterAudio.SoundGroupCommand.FadeOutAllOfSound: MasterAudio.FadeOutAllOfSound(soundType, aEvent.fadeTime); break; case MasterAudio.SoundGroupCommand.Mute: MasterAudio.MuteGroup(soundType); break; case MasterAudio.SoundGroupCommand.Pause: MasterAudio.PauseSoundGroup(soundType); break; case MasterAudio.SoundGroupCommand.Solo: MasterAudio.SoloGroup(soundType); break; case MasterAudio.SoundGroupCommand.StopAllOfSound: MasterAudio.StopAllOfSound(soundType); break; case MasterAudio.SoundGroupCommand.Unmute: MasterAudio.UnmuteGroup(soundType); break; case MasterAudio.SoundGroupCommand.Unpause: MasterAudio.UnpauseSoundGroup(soundType); break; case MasterAudio.SoundGroupCommand.Unsolo: MasterAudio.UnsoloGroup(soundType); break; case MasterAudio.SoundGroupCommand.StopAllSoundsOfTransform: MasterAudio.StopAllSoundsOfTransform(this.trans); break; case MasterAudio.SoundGroupCommand.StopSoundGroupOfTransform: MasterAudio.StopSoundGroupOfTransform(this.trans, soundType); break; case MasterAudio.SoundGroupCommand.PauseAllSoundsOfTransform: MasterAudio.PauseAllSoundsOfTransform(this.trans); break; case MasterAudio.SoundGroupCommand.PauseSoundGroupOfTransform: MasterAudio.PauseSoundGroupOfTransform(this.trans, soundType); break; case MasterAudio.SoundGroupCommand.UnpauseAllSoundsOfTransform: MasterAudio.UnpauseAllSoundsOfTransform(this.trans); break; case MasterAudio.SoundGroupCommand.UnpauseSoundGroupOfTransform: MasterAudio.UnpauseSoundGroupOfTransform(this.trans, soundType); break; case MasterAudio.SoundGroupCommand.FadeOutSoundGroupOfTransform: MasterAudio.FadeOutSoundGroupOfTransform(this.trans, soundType, aEvent.fadeTime); break; } } break; case MasterAudio.EventSoundFunctionType.BusControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = true, SoundScheduled = false }; var busesForCmd = new List <string>(); if (!aEvent.allSoundTypesForBusCmd) { busesForCmd.Add(aEvent.busName); } else { busesForCmd.AddRange(MasterAudio.RuntimeBusNames); } for (var i = 0; i < busesForCmd.Count; i++) { var busName = busesForCmd[i]; switch (aEvent.currentBusCommand) { case MasterAudio.BusCommand.None: soundPlayed.SoundPlayed = false; break; case MasterAudio.BusCommand.FadeToVolume: MasterAudio.FadeBusToVolume(busName, aEvent.fadeVolume, aEvent.fadeTime); break; case MasterAudio.BusCommand.Pause: MasterAudio.PauseBus(busName); break; case MasterAudio.BusCommand.Stop: MasterAudio.StopBus(busName); break; case MasterAudio.BusCommand.Unpause: MasterAudio.UnpauseBus(busName); break; case MasterAudio.BusCommand.Mute: MasterAudio.MuteBus(busName); break; case MasterAudio.BusCommand.Unmute: MasterAudio.UnmuteBus(busName); break; case MasterAudio.BusCommand.Solo: MasterAudio.SoloBus(busName); break; case MasterAudio.BusCommand.Unsolo: MasterAudio.UnsoloBus(busName); break; } } break; case MasterAudio.EventSoundFunctionType.CustomEventControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = false, SoundScheduled = false }; if (eType == EventType.UserDefinedEvent) { Debug.LogError("Custom Event Receivers cannot fire events. Occured in Transform '" + this.name + "'."); break; } switch (aEvent.currentCustomEventCommand) { case MasterAudio.CustomEventCommand.FireEvent: MasterAudio.FireCustomEvent(aEvent.theCustomEventName); break; } break; case MasterAudio.EventSoundFunctionType.GlobalControl: switch (aEvent.currentGlobalCommand) { case MasterAudio.GlobalCommand.PauseMixer: MasterAudio.PauseMixer(); break; case MasterAudio.GlobalCommand.UnpauseMixer: MasterAudio.UnpauseMixer(); break; case MasterAudio.GlobalCommand.StopMixer: MasterAudio.StopMixer(); break; case MasterAudio.GlobalCommand.MuteEverything: MasterAudio.MuteEverything(); break; case MasterAudio.GlobalCommand.UnmuteEverything: MasterAudio.UnmuteEverything(); break; case MasterAudio.GlobalCommand.PauseEverything: MasterAudio.PauseEverything(); break; case MasterAudio.GlobalCommand.UnpauseEverything: MasterAudio.UnpauseEverything(); break; case MasterAudio.GlobalCommand.StopEverything: MasterAudio.StopEverything(); break; } break; } if (aEvent.emitParticles && soundPlayed != null && (soundPlayed.SoundPlayed || soundPlayed.SoundScheduled)) { MasterAudio.TriggerParticleEmission(this.trans, aEvent.particleCountToEmit); } return(soundPlayed); }
private bool RenderAudioEvent(AudioEventGroup eventGrp, EventSounds.EventType eType, int? itemIndex = null) { int? indexToRemove = null; int? indexToInsert = null; int? indexToShiftUp = null; int? indexToShiftDown = null; var hideActions = false; if (sounds.disableSounds) { hideActions = true; } if (sounds.useMouseDragSound && eType == EventSounds.EventType.OnMouseUp) { var newStopDragSound = (EventSounds.PreviousSoundStopMode)EditorGUILayout.EnumPopup("Mouse Drag Sound End", eventGrp.mouseDragStopMode); if (newStopDragSound != eventGrp.mouseDragStopMode) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Mouse Drag Sound End"); eventGrp.mouseDragStopMode = newStopDragSound; } if (eventGrp.mouseDragStopMode == EventSounds.PreviousSoundStopMode.FadeOut) { EditorGUI.indentLevel = 1; var newFade = EditorGUILayout.Slider("Mouse Drag Fade Time", eventGrp.mouseDragFadeOutTime, 0f, 1f); if (newFade != eventGrp.mouseDragFadeOutTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Mouse Drag Fade Time"); eventGrp.mouseDragFadeOutTime = newFade; } } } EditorGUI.indentLevel = 0; bool showLayerTagFilter = EventSounds.layerTagFilterEvents.Contains(eType.ToString()); if (showLayerTagFilter) { var newUseLayers = EditorGUILayout.BeginToggleGroup("Layer filters", eventGrp.useLayerFilter); if (newUseLayers != eventGrp.useLayerFilter) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Layer filters"); eventGrp.useLayerFilter = newUseLayers; } if (eventGrp.useLayerFilter) { for (var i = 0; i < eventGrp.matchingLayers.Count; i++) { var newLayer = EditorGUILayout.LayerField("Layer Match " + (i + 1), eventGrp.matchingLayers[i]); if (newLayer != eventGrp.matchingLayers[i]) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Layer filter"); eventGrp.matchingLayers[i] = newLayer; } } EditorGUILayout.BeginHorizontal(); GUILayout.Space(24); GUI.contentColor = Color.green; if (GUILayout.Button(new GUIContent("Add", "Click to add a layer match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60))) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "add Layer filter"); eventGrp.matchingLayers.Add(0); } if (eventGrp.matchingLayers.Count > 1) { GUILayout.Space(10); if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last layer match"), EditorStyles.toolbarButton, GUILayout.Width(60))) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "remove Layer filter"); eventGrp.matchingLayers.RemoveAt(eventGrp.matchingLayers.Count - 1); } } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndToggleGroup(); var newTagFilter = EditorGUILayout.BeginToggleGroup("Tag filter", eventGrp.useTagFilter); if (newTagFilter != eventGrp.useTagFilter) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Tag filter"); eventGrp.useTagFilter = newTagFilter; } if (eventGrp.useTagFilter) { for (var i = 0; i < eventGrp.matchingTags.Count; i++) { var newTag = EditorGUILayout.TagField("Tag Match " + (i + 1), eventGrp.matchingTags[i]); if (newTag != eventGrp.matchingTags[i]) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Tag filter"); eventGrp.matchingTags[i] = newTag; } } EditorGUILayout.BeginHorizontal(); GUILayout.Space(24); GUI.contentColor = Color.green; if (GUILayout.Button(new GUIContent("Add", "Click to add a tag match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60))) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Add Tag filter"); eventGrp.matchingTags.Add("Untagged"); } if (eventGrp.matchingTags.Count > 1) { GUILayout.Space(10); if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last tag match"), EditorStyles.toolbarButton, GUILayout.Width(60))) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "remove Tag filter"); eventGrp.matchingTags.RemoveAt(eventGrp.matchingLayers.Count - 1); } } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndToggleGroup(); } if (eType == EventSounds.EventType.MechanimStateChanged) { GUI.color = eventGrp.mechanimEventActive ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr; EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb); var newUse = EditorGUILayout.Toggle("Mechanim State Entered " + DisabledText, eventGrp.mechanimEventActive); if (newUse != eventGrp.mechanimEventActive) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Mechanim State Entered active"); eventGrp.mechanimEventActive = newUse; } if (!eventGrp.mechanimEventActive) { hideActions = true; } var buttonPressed = DTGUIHelper.AddCustomEventDeleteIcon(false); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Remove: UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "delete Custom Event Sound"); sounds.mechanimStateChangedSounds.RemoveAt(itemIndex.Value); eventGrp.mechanimEventActive = false; break; } EditorGUILayout.EndHorizontal(); GUI.color = Color.white; if (eventGrp.mechanimEventActive && !hideActions) { var newName = EditorGUILayout.TextField("State Name", eventGrp.mechanimStateName); if (newName != eventGrp.mechanimStateName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change State Name"); eventGrp.mechanimStateName = newName; } if (!hasMechanim) { DTGUIHelper.ShowRedError("This Game Object does not have an Animator component. Add one or delete this."); } else { if (string.IsNullOrEmpty(eventGrp.mechanimStateName)) { DTGUIHelper.ShowRedError("No State Name specified. This event will do nothing."); } } } } if (eType == EventSounds.EventType.UserDefinedEvent) { GUI.color = eventGrp.customSoundActive ? MasterAudioInspector.activeClr : MasterAudioInspector.inactiveClr; EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb); var newUse = EditorGUILayout.Toggle("Custom Event " + DisabledText, eventGrp.customSoundActive); if (newUse != eventGrp.customSoundActive) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Custom Event active"); eventGrp.customSoundActive = newUse; } var buttonPressed = DTGUIHelper.AddCustomEventDeleteIcon(false); switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Remove: UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "delete Custom Event Sound"); sounds.userDefinedSounds.RemoveAt(itemIndex.Value); eventGrp.customSoundActive = false; break; } EditorGUILayout.EndHorizontal(); GUI.color = Color.white; if (!eventGrp.customSoundActive) { return true; } if (!hideActions) { if (maInScene) { var existingIndex = customEventNames.IndexOf(eventGrp.customEventName); int? customEventIndex = null; EditorGUI.indentLevel = 0; var noEvent = false; var noMatch = false; if (existingIndex >= 1) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, customEventNames.ToArray()); if (existingIndex == 1) { noEvent = true; } } else if (existingIndex == -1 && eventGrp.customEventName == MasterAudio.NO_GROUP_NAME) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, customEventNames.ToArray()); } else { // non-match noMatch = true; var newEventName = EditorGUILayout.TextField("Custom Event Name", eventGrp.customEventName); if (newEventName != eventGrp.customEventName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Custom Event Name"); eventGrp.customEventName = newEventName; } var newIndex = EditorGUILayout.Popup("All Custom Events", -1, customEventNames.ToArray()); if (newIndex >= 0) { customEventIndex = newIndex; } } if (noEvent) { DTGUIHelper.ShowRedError("No Custom Event specified. This section will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Custom Event found no match. Type in or choose one."); } if (customEventIndex.HasValue) { if (existingIndex != customEventIndex.Value) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Custom Event"); } if (customEventIndex.Value == -1) { eventGrp.customEventName = MasterAudio.NO_GROUP_NAME; } else { eventGrp.customEventName = customEventNames[customEventIndex.Value]; } } } else { var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", eventGrp.customEventName); if (newCustomEvent != eventGrp.customEventName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Custom Event Name"); eventGrp.customEventName = newCustomEvent; } } } } if (eventGrp.SoundEvents.Count == 0) { eventGrp.SoundEvents.Add(new AudioEvent()); } if (!hideActions) { for (var j = 0; j < eventGrp.SoundEvents.Count; j++) { AudioEvent aEvent = eventGrp.SoundEvents[j]; var newRetrigger = (EventSounds.RetriggerLimMode)EditorGUILayout.EnumPopup("Retrigger Limit Mode", eventGrp.retriggerLimitMode); if (newRetrigger != eventGrp.retriggerLimitMode) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Retrigger Limit Mode"); eventGrp.retriggerLimitMode = newRetrigger; } EditorGUI.indentLevel = 1; switch (eventGrp.retriggerLimitMode) { case EventSounds.RetriggerLimMode.FrameBased: var newFrm = EditorGUILayout.IntSlider("Min Frames Between", eventGrp.limitPerXFrm, 0, 10000); if (newFrm != eventGrp.limitPerXFrm) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Min Frames Between"); eventGrp.limitPerXFrm = newFrm; } break; case EventSounds.RetriggerLimMode.TimeBased: var newSec = EditorGUILayout.Slider("Min Seconds Between", eventGrp.limitPerXSec, 0f, 10000f); if (newSec != eventGrp.limitPerXSec) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Min Seconds Between"); eventGrp.limitPerXSec = newSec; } break; } EditorGUILayout.BeginHorizontal(EditorStyles.objectFieldThumb); var newExpanded = DTGUIHelper.Foldout(aEvent.isExpanded, "Action #" + (j + 1)); if (newExpanded != aEvent.isExpanded) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle expand Action"); aEvent.isExpanded = newExpanded; } var newActionName = GUILayout.TextField(aEvent.actionName, GUILayout.Width(200)); if (newActionName != aEvent.actionName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Rename action"); aEvent.actionName = newActionName; } var buttonPressed = DTGUIHelper.AddFoldOutListItemButtons(j, eventGrp.SoundEvents.Count, "Action", true, true, false); EditorGUILayout.EndHorizontal(); if (aEvent.isExpanded) { EditorGUI.indentLevel = 0; if (eType == EventSounds.EventType.OnEnable) { DTGUIHelper.ShowColorWarning("*If this prefab is in the scene at startup, use Start event instead."); } var newSoundType = (MasterAudio.EventSoundFunctionType)EditorGUILayout.EnumPopup("Action Type", aEvent.currentSoundFunctionType); if (newSoundType != aEvent.currentSoundFunctionType) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Action Type"); aEvent.currentSoundFunctionType = newSoundType; } switch (aEvent.currentSoundFunctionType) { case MasterAudio.EventSoundFunctionType.PlaySound: if (maInScene) { var existingIndex = groupNames.IndexOf(aEvent.soundType); int? groupIndex = null; EditorGUI.indentLevel = 1; var noGroup = false; var noMatch = false; if (existingIndex >= 1) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray()); if (existingIndex == 1) { noGroup = true; } } else if (existingIndex == -1 && aEvent.soundType == MasterAudio.NO_GROUP_NAME) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray()); } else { // non-match noMatch = true; var newSound = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSound != aEvent.soundType) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Sound Group"); aEvent.soundType = newSound; } var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, groupNames.ToArray()); if (newIndex >= 0) { groupIndex = newIndex; } } if (noGroup) { DTGUIHelper.ShowRedError("No Sound Group specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one."); } if (groupIndex.HasValue) { if (existingIndex != groupIndex.Value) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Sound Group"); } if (groupIndex.Value == -1) { aEvent.soundType = MasterAudio.NO_GROUP_NAME; } else { aEvent.soundType = groupNames[groupIndex.Value]; } } } else { var newSType = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSType != aEvent.soundType) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Sound Group"); aEvent.soundType = newSType; } } var newVarType = (EventSounds.VariationType)EditorGUILayout.EnumPopup("Variation Mode", aEvent.variationType); if (newVarType != aEvent.variationType) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Variation Mode"); aEvent.variationType = newVarType; } if (aEvent.variationType == EventSounds.VariationType.PlaySpecific) { var newVarName = EditorGUILayout.TextField("Variation Name", aEvent.variationName); if (newVarName != aEvent.variationName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Variation Name"); aEvent.variationName = newVarName; } if (string.IsNullOrEmpty(aEvent.variationName)) { DTGUIHelper.ShowRedError("Variation Name is empty. No sound will play."); } } var newVol = EditorGUILayout.Slider("Volume", aEvent.volume, 0f, 1f); if (newVol != aEvent.volume) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Volume"); aEvent.volume = newVol; } var newFixedPitch = EditorGUILayout.Toggle("Override pitch?", aEvent.useFixedPitch); if (newFixedPitch != aEvent.useFixedPitch) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Override pitch"); aEvent.useFixedPitch = newFixedPitch; } if (aEvent.useFixedPitch) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Pitch"); aEvent.pitch = EditorGUILayout.Slider("Pitch", aEvent.pitch, -3f, 3f); } var newDelay = EditorGUILayout.Slider("Delay Sound (sec)", aEvent.delaySound, 0f, 10f); if (newDelay != aEvent.delaySound) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Delay Sound"); aEvent.delaySound = newDelay; } break; case MasterAudio.EventSoundFunctionType.PlaylistControl: EditorGUI.indentLevel = 1; var newPlaylistCmd = (MasterAudio.PlaylistCommand)EditorGUILayout.EnumPopup("Playlist Command", aEvent.currentPlaylistCommand); if (newPlaylistCmd != aEvent.currentPlaylistCommand) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Playlist Command"); aEvent.currentPlaylistCommand = newPlaylistCmd; } if (aEvent.currentPlaylistCommand != MasterAudio.PlaylistCommand.None) { // show Playlist Controller dropdown if (EventSounds.playlistCommandsWithAll.Contains(aEvent.currentPlaylistCommand)) { var newAllControllers = EditorGUILayout.Toggle("All Playlist Controllers?", aEvent.allPlaylistControllersForGroupCmd); if (newAllControllers != aEvent.allPlaylistControllersForGroupCmd) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle All Playlist Controllers"); aEvent.allPlaylistControllersForGroupCmd = newAllControllers; } } if (!aEvent.allPlaylistControllersForGroupCmd) { if (playlistControllerNames.Count > 0) { var existingIndex = playlistControllerNames.IndexOf(aEvent.playlistControllerName); int? playlistControllerIndex = null; var noPC = false; var noMatch = false; if (existingIndex >= 1) { playlistControllerIndex = EditorGUILayout.Popup("Playlist Controller", existingIndex, playlistControllerNames.ToArray()); if (existingIndex == 1) { noPC = true; } } else if (existingIndex == -1 && aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { playlistControllerIndex = EditorGUILayout.Popup("Playlist Controller", existingIndex, playlistControllerNames.ToArray()); } else { // non-match noMatch = true; var newPlaylistController = EditorGUILayout.TextField("Playlist Controller", aEvent.playlistControllerName); if (newPlaylistController != aEvent.playlistControllerName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Playlist Controller"); aEvent.playlistControllerName = newPlaylistController; } var newIndex = EditorGUILayout.Popup("All Playlist Controllers", -1, playlistControllerNames.ToArray()); if (newIndex >= 0) { playlistControllerIndex = newIndex; } } if (noPC) { DTGUIHelper.ShowRedError("No Playlist Controller specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Playlist Controller found no match. Type in or choose one."); } if (playlistControllerIndex.HasValue) { if (existingIndex != playlistControllerIndex.Value) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Playlist Controller"); } if (playlistControllerIndex.Value == -1) { aEvent.playlistControllerName = MasterAudio.NO_GROUP_NAME; } else { aEvent.playlistControllerName = playlistControllerNames[playlistControllerIndex.Value]; } } } else { var newPlaylistControllerName = EditorGUILayout.TextField("Playlist Controller", aEvent.playlistControllerName); if (newPlaylistControllerName != aEvent.playlistControllerName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Playlist Controller"); aEvent.playlistControllerName = newPlaylistControllerName; } } } } switch (aEvent.currentPlaylistCommand) { case MasterAudio.PlaylistCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.PlaylistCommand.ChangePlaylist: // show playlist name dropdown if (maInScene) { var existingIndex = playlistNames.IndexOf(aEvent.playlistName); int? playlistIndex = null; var noPl = false; var noMatch = false; if (existingIndex >= 1) { playlistIndex = EditorGUILayout.Popup("Playlist Name", existingIndex, playlistNames.ToArray()); if (existingIndex == 1) { noPl = true; } } else if (existingIndex == -1 && aEvent.playlistName == MasterAudio.NO_GROUP_NAME) { playlistIndex = EditorGUILayout.Popup("Playlist Name", existingIndex, playlistNames.ToArray()); } else { // non-match noMatch = true; var newPlaylist = EditorGUILayout.TextField("Playlist Name", aEvent.playlistName); if (newPlaylist != aEvent.playlistName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Playlist Name"); aEvent.playlistName = newPlaylist; } var newIndex = EditorGUILayout.Popup("All Playlists", -1, playlistNames.ToArray()); if (newIndex >= 0) { playlistIndex = newIndex; } } if (noPl) { DTGUIHelper.ShowRedError("No Playlist Name specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Playlist Name found no match. Type in or choose one."); } if (playlistIndex.HasValue) { if (existingIndex != playlistIndex.Value) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Playlist Name"); } if (playlistIndex.Value == -1) { aEvent.playlistName = MasterAudio.NO_GROUP_NAME; } else { aEvent.playlistName = playlistNames[playlistIndex.Value]; } } } else { var newPlaylistName = EditorGUILayout.TextField("Playlist Name", aEvent.playlistName); if (newPlaylistName != aEvent.playlistName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Playlist Name"); aEvent.playlistName = newPlaylistName; } } var newStartPlaylist = EditorGUILayout.Toggle("Start Playlist?", aEvent.startPlaylist); if (newStartPlaylist != aEvent.startPlaylist) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Start Playlist"); aEvent.startPlaylist = newStartPlaylist; } break; case MasterAudio.PlaylistCommand.FadeToVolume: var newFadeVol = EditorGUILayout.Slider("Target Volume", aEvent.fadeVolume, 0f, 1f); if (newFadeVol != aEvent.fadeVolume) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Target Volume"); aEvent.fadeVolume = newFadeVol; } var newFadeTime = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeTime != aEvent.fadeTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Fade Time"); aEvent.fadeTime = newFadeTime; } break; case MasterAudio.PlaylistCommand.PlayClip: var newClip = EditorGUILayout.TextField("Clip Name", aEvent.clipName); if (newClip != aEvent.clipName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Clip Name"); aEvent.clipName = newClip; } if (string.IsNullOrEmpty(aEvent.clipName)) { DTGUIHelper.ShowRedError("Clip name is empty. Action will do nothing."); } break; } break; case MasterAudio.EventSoundFunctionType.GroupControl: EditorGUI.indentLevel = 1; var newGroupCmd = (MasterAudio.SoundGroupCommand)EditorGUILayout.EnumPopup("Group Command", aEvent.currentSoundGroupCommand); if (newGroupCmd != aEvent.currentSoundGroupCommand) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Group Command"); aEvent.currentSoundGroupCommand = newGroupCmd; } if (!MasterAudio.GroupCommandsWithNoGroupSelector.Contains(aEvent.currentSoundGroupCommand)) { if (!MasterAudio.GroupCommandsWithNoAllGroupSelector.Contains(aEvent.currentSoundGroupCommand)) { var newAllTypes = EditorGUILayout.Toggle("Do For Every Group?", aEvent.allSoundTypesForGroupCmd); if (newAllTypes != aEvent.allSoundTypesForGroupCmd) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Do For Every Group?"); aEvent.allSoundTypesForGroupCmd = newAllTypes; } } if (!aEvent.allSoundTypesForGroupCmd) { if (maInScene) { var existingIndex = groupNames.IndexOf(aEvent.soundType); int? groupIndex = null; var noGroup = false; var noMatch = false; if (existingIndex >= 1) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray()); if (existingIndex == 1) { noGroup = true; } } else if (existingIndex == -1 && aEvent.soundType == MasterAudio.NO_GROUP_NAME) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, groupNames.ToArray()); } else { // non-match noMatch = true; var newSType = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSType != aEvent.soundType) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Sound Group"); aEvent.soundType = newSType; } var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, groupNames.ToArray()); if (newIndex >= 0) { groupIndex = newIndex; } } if (noMatch) { DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one."); } else if (noGroup) { DTGUIHelper.ShowRedError("No Sound Group specified. Action will do nothing."); } if (groupIndex.HasValue) { if (existingIndex != groupIndex.Value) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Sound Group"); } if (groupIndex.Value == -1) { aEvent.soundType = MasterAudio.NO_GROUP_NAME; } else { aEvent.soundType = groupNames[groupIndex.Value]; } } } else { var newSoundT = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSoundT != aEvent.soundType) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Sound Group"); aEvent.soundType = newSoundT; } } } } switch (aEvent.currentSoundGroupCommand) { case MasterAudio.SoundGroupCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.SoundGroupCommand.FadeToVolume: var newFadeVol = EditorGUILayout.Slider("Target Volume", aEvent.fadeVolume, 0f, 1f); if (newFadeVol != aEvent.fadeVolume) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Target Volume"); aEvent.fadeVolume = newFadeVol; } var newFadeTime = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeTime != aEvent.fadeTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Fade Time"); aEvent.fadeTime = newFadeTime; } break; case MasterAudio.SoundGroupCommand.FadeOutAllOfSound: var newFadeT = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeT != aEvent.fadeTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Fade Time"); aEvent.fadeTime = newFadeT; } break; case MasterAudio.SoundGroupCommand.FadeOutSoundGroupOfTransform: var newFade = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFade != aEvent.fadeTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Fade Time"); aEvent.fadeTime = newFade; } break; case MasterAudio.SoundGroupCommand.Mute: break; case MasterAudio.SoundGroupCommand.Pause: break; case MasterAudio.SoundGroupCommand.Solo: break; case MasterAudio.SoundGroupCommand.Unmute: break; case MasterAudio.SoundGroupCommand.Unpause: break; case MasterAudio.SoundGroupCommand.Unsolo: break; } break; case MasterAudio.EventSoundFunctionType.BusControl: EditorGUI.indentLevel = 1; var newBusCmd = (MasterAudio.BusCommand)EditorGUILayout.EnumPopup("Bus Command", aEvent.currentBusCommand); if (newBusCmd != aEvent.currentBusCommand) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Bus Command"); aEvent.currentBusCommand = newBusCmd; } if (aEvent.currentBusCommand != MasterAudio.BusCommand.None) { var newAllTypes = EditorGUILayout.Toggle("Do For Every Bus?", aEvent.allSoundTypesForBusCmd); if (newAllTypes != aEvent.allSoundTypesForBusCmd) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Do For Every Bus?"); aEvent.allSoundTypesForBusCmd = newAllTypes; } if (!aEvent.allSoundTypesForBusCmd) { if (maInScene) { var existingIndex = busNames.IndexOf(aEvent.busName); int? busIndex = null; var noBus = false; var noMatch = false; if (existingIndex >= 1) { busIndex = EditorGUILayout.Popup("Bus Name", existingIndex, busNames.ToArray()); if (existingIndex == 1) { noBus = true; } } else if (existingIndex == -1 && aEvent.busName == MasterAudio.NO_GROUP_NAME) { busIndex = EditorGUILayout.Popup("Bus Name", existingIndex, busNames.ToArray()); } else { // non-match var newBusName = EditorGUILayout.TextField("Bus Name", aEvent.busName); if (newBusName != aEvent.busName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Bus Name"); aEvent.busName = newBusName; } var newIndex = EditorGUILayout.Popup("All Buses", -1, busNames.ToArray()); if (newIndex >= 0) { busIndex = newIndex; } noMatch = true; } if (noBus) { DTGUIHelper.ShowRedError("No Bus Name specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Bus Name found no match. Type in or choose one."); } if (busIndex.HasValue) { if (existingIndex != busIndex.Value) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Bus"); } if (busIndex.Value == -1) { aEvent.busName = MasterAudio.NO_GROUP_NAME; } else { aEvent.busName = busNames[busIndex.Value]; } } } else { var newBusName = EditorGUILayout.TextField("Bus Name", aEvent.busName); if (newBusName != aEvent.busName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Bus Name"); aEvent.busName = newBusName; } } } } switch (aEvent.currentBusCommand) { case MasterAudio.BusCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.BusCommand.FadeToVolume: var newFadeVol = EditorGUILayout.Slider("Target Volume", aEvent.fadeVolume, 0f, 1f); if (newFadeVol != aEvent.fadeVolume) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Target Volume"); aEvent.fadeVolume = newFadeVol; } var newFadeTime = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeTime != aEvent.fadeTime) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Fade Time"); aEvent.fadeTime = newFadeTime; } break; case MasterAudio.BusCommand.Pause: break; case MasterAudio.BusCommand.Unpause: break; } break; case MasterAudio.EventSoundFunctionType.CustomEventControl: if (eType == EventSounds.EventType.UserDefinedEvent) { DTGUIHelper.ShowRedError("Custom Event Receivers cannot fire events. Select another Action Type."); break; } EditorGUI.indentLevel = 1; var newEventCmd = (MasterAudio.CustomEventCommand)EditorGUILayout.EnumPopup("Custom Event Cmd", aEvent.currentCustomEventCommand); if (newEventCmd != aEvent.currentCustomEventCommand) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Custom Event Command"); aEvent.currentCustomEventCommand = newEventCmd; } switch (aEvent.currentCustomEventCommand) { case MasterAudio.CustomEventCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.CustomEventCommand.FireEvent: if (maInScene) { var existingIndex = customEventNames.IndexOf(aEvent.theCustomEventName); int? customEventIndex = null; EditorGUI.indentLevel = 1; var noEvent = false; var noMatch = false; if (existingIndex >= 1) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, customEventNames.ToArray()); if (existingIndex == 1) { noEvent = true; } } else if (existingIndex == -1 && aEvent.soundType == MasterAudio.NO_GROUP_NAME) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, customEventNames.ToArray()); } else { // non-match noMatch = true; var newEventName = EditorGUILayout.TextField("Custom Event Name", aEvent.theCustomEventName); if (newEventName != aEvent.theCustomEventName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Custom Event Name"); aEvent.theCustomEventName = newEventName; } var newIndex = EditorGUILayout.Popup("All Custom Events", -1, customEventNames.ToArray()); if (newIndex >= 0) { customEventIndex = newIndex; } } if (noEvent) { DTGUIHelper.ShowRedError("No Custom Event specified. This section will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Custom Event found no match. Type in or choose one."); } if (customEventIndex.HasValue) { if (existingIndex != customEventIndex.Value) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Custom Event"); } if (customEventIndex.Value == -1) { aEvent.theCustomEventName = MasterAudio.NO_GROUP_NAME; } else { aEvent.theCustomEventName = customEventNames[customEventIndex.Value]; } } } else { var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", aEvent.theCustomEventName); if (newCustomEvent != aEvent.theCustomEventName) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Custom Event Name"); aEvent.theCustomEventName = newCustomEvent; } } break; } break; case MasterAudio.EventSoundFunctionType.GlobalControl: EditorGUI.indentLevel = 1; var newCmd = (MasterAudio.GlobalCommand)EditorGUILayout.EnumPopup("Global Cmd", aEvent.currentGlobalCommand); if (newCmd != aEvent.currentGlobalCommand) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Global Command"); aEvent.currentGlobalCommand = newCmd; } if (aEvent.currentGlobalCommand == MasterAudio.GlobalCommand.None) { DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); } break; } EditorGUI.indentLevel = 0; var newEmit = EditorGUILayout.Toggle("Emit Particle", aEvent.emitParticles); if (newEmit != aEvent.emitParticles) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "toggle Emit Particle"); aEvent.emitParticles = newEmit; } if (aEvent.emitParticles) { var newParticleCount = EditorGUILayout.IntSlider("Particle Count", aEvent.particleCountToEmit, 1, 100); if (newParticleCount != aEvent.particleCountToEmit) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "change Particle Count"); aEvent.particleCountToEmit = newParticleCount; } } } switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Add: indexToInsert = j + 1; break; case DTGUIHelper.DTFunctionButtons.Remove: indexToRemove = j; break; case DTGUIHelper.DTFunctionButtons.ShiftUp: indexToShiftUp = j; break; case DTGUIHelper.DTFunctionButtons.ShiftDown: indexToShiftDown = j; break; } } } AudioEvent item = null; if (indexToInsert.HasValue) { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Add action"); eventGrp.SoundEvents.Insert(indexToInsert.Value, new AudioEvent()); } else if (indexToRemove.HasValue) { if (eventGrp.SoundEvents.Count <= 1) { DTGUIHelper.ShowAlert("You cannot delete the last Action. Disable this event if you don't need it."); } else { UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Delete action"); eventGrp.SoundEvents.RemoveAt(indexToRemove.Value); } } else if (indexToShiftUp.HasValue) { item = eventGrp.SoundEvents[indexToShiftUp.Value]; UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Shift up event action"); eventGrp.SoundEvents.Insert(indexToShiftUp.Value - 1, item); eventGrp.SoundEvents.RemoveAt(indexToShiftUp.Value + 1); } else if (indexToShiftDown.HasValue) { var index = indexToShiftDown.Value + 1; item = eventGrp.SoundEvents[index]; UndoHelper.RecordObjectPropertyForUndo(ref isDirty, sounds, "Shift down event action"); eventGrp.SoundEvents.Insert(index - 1, item); eventGrp.SoundEvents.RemoveAt(index + 1); } return isDirty; }
// ReSharper disable once FunctionComplexityOverflow private bool RenderAudioEvent(AudioEventGroup eventGrp, EventSounds.EventType eType) { DTGUIHelper.BeginGroupedControls(); int? indexToRemove = null; int? indexToInsert = null; int? indexToShiftUp = null; int? indexToShiftDown = null; var hideActions = _sounds.disableSounds; var isSliderChangedEvent = (eType == EventSounds.EventType.UnitySliderChanged); if (_sounds.useMouseDragSound && eType == EventSounds.EventType.OnMouseUp) { var newStopDragSound = (EventSounds.PreviousSoundStopMode)EditorGUILayout.EnumPopup("Mouse Drag Sound End", eventGrp.mouseDragStopMode); if (newStopDragSound != eventGrp.mouseDragStopMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Mouse Drag Sound End"); eventGrp.mouseDragStopMode = newStopDragSound; } if (eventGrp.mouseDragStopMode == EventSounds.PreviousSoundStopMode.FadeOut) { EditorGUI.indentLevel = 1; var newFade = EditorGUILayout.Slider("Mouse Drag Fade Time", eventGrp.mouseDragFadeOutTime, 0f, 1f); if (newFade != eventGrp.mouseDragFadeOutTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Mouse Drag Fade Time"); eventGrp.mouseDragFadeOutTime = newFade; } } } EditorGUI.indentLevel = 0; var showLayerTagFilter = EventSounds.LayerTagFilterEvents.Contains(eType.ToString()); if (showLayerTagFilter) { DTGUIHelper.StartGroupHeader(); var newUseLayers = EditorGUILayout.BeginToggleGroup(" Layer filter", eventGrp.useLayerFilter); if (newUseLayers != eventGrp.useLayerFilter) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Layer filter"); eventGrp.useLayerFilter = newUseLayers; } DTGUIHelper.EndGroupHeader(); if (eventGrp.useLayerFilter) { for (var i = 0; i < eventGrp.matchingLayers.Count; i++) { var newLayer = EditorGUILayout.LayerField("Layer Match " + (i + 1), eventGrp.matchingLayers[i]); if (newLayer == eventGrp.matchingLayers[i]) { continue; } AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Layer filter"); eventGrp.matchingLayers[i] = newLayer; } EditorGUILayout.BeginHorizontal(); GUI.contentColor = DTGUIHelper.BrightButtonColor; if (GUILayout.Button(new GUIContent("Add", "Click to add a layer match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60))) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "add Layer filter"); eventGrp.matchingLayers.Add(0); } if (eventGrp.matchingLayers.Count > 1) { GUILayout.Space(10); if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last layer match"), EditorStyles.toolbarButton, GUILayout.Width(60))) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Layer filter"); eventGrp.matchingLayers.RemoveAt(eventGrp.matchingLayers.Count - 1); } } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndToggleGroup(); DTGUIHelper.AddSpaceForNonU5(2); DTGUIHelper.StartGroupHeader(); var newTagFilter = EditorGUILayout.BeginToggleGroup(" Tag filter", eventGrp.useTagFilter); if (newTagFilter != eventGrp.useTagFilter) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Tag filter"); eventGrp.useTagFilter = newTagFilter; } DTGUIHelper.EndGroupHeader(); if (eventGrp.useTagFilter) { for (var i = 0; i < eventGrp.matchingTags.Count; i++) { var newTag = EditorGUILayout.TagField("Tag Match " + (i + 1), eventGrp.matchingTags[i]); if (newTag == eventGrp.matchingTags[i]) { continue; } AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Tag filter"); eventGrp.matchingTags[i] = newTag; } EditorGUILayout.BeginHorizontal(); GUI.contentColor = DTGUIHelper.BrightButtonColor; if (GUILayout.Button(new GUIContent("Add", "Click to add a tag match at the end"), EditorStyles.toolbarButton, GUILayout.Width(60))) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Add Tag filter"); eventGrp.matchingTags.Add("Untagged"); } if (eventGrp.matchingTags.Count > 1) { GUILayout.Space(10); if (GUILayout.Button(new GUIContent("Remove", "Click to remove the last tag match"), EditorStyles.toolbarButton, GUILayout.Width(60))) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "remove Tag filter"); eventGrp.matchingTags.RemoveAt(eventGrp.matchingLayers.Count - 1); } } GUI.contentColor = Color.white; EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndToggleGroup(); } if (eType == EventSounds.EventType.MechanimStateChanged) { if (!eventGrp.mechanimEventActive) { hideActions = true; } if (eventGrp.mechanimEventActive && !hideActions) { var newName = EditorGUILayout.TextField("State Name", eventGrp.mechanimStateName); if (newName != eventGrp.mechanimStateName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change State Name"); eventGrp.mechanimStateName = newName; } if (!_hasMechanim) { DTGUIHelper.ShowRedError("This Game Object does not have an Animator component."); } else { if (string.IsNullOrEmpty(eventGrp.mechanimStateName)) { DTGUIHelper.ShowRedError("No State Name specified. This event will do nothing."); } } } } if (eType == EventSounds.EventType.UserDefinedEvent) { if (!eventGrp.customSoundActive) { DTGUIHelper.EndGroupedControls(); return true; } if (!hideActions) { if (_maInScene) { var existingIndex = _customEventNames.IndexOf(eventGrp.customEventName); int? customEventIndex = null; EditorGUI.indentLevel = 0; var noEvent = false; var noMatch = false; if (existingIndex >= 1) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray()); if (existingIndex == 1) { noEvent = true; } } else if (existingIndex == -1 && eventGrp.customEventName == MasterAudio.NoGroupName) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray()); } else { // non-match noMatch = true; var newEventName = EditorGUILayout.TextField("Custom Event Name", eventGrp.customEventName); if (newEventName != eventGrp.customEventName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Custom Event Name"); eventGrp.customEventName = newEventName; } var newIndex = EditorGUILayout.Popup("All Custom Events", -1, _customEventNames.ToArray()); if (newIndex >= 0) { customEventIndex = newIndex; } } if (noEvent) { DTGUIHelper.ShowRedError("No Custom Event specified. This section will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Custom Event found no match. Type in or choose one."); } if (customEventIndex.HasValue) { if (existingIndex != customEventIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Custom Event"); } switch (customEventIndex.Value) { case -1: eventGrp.customEventName = MasterAudio.NoGroupName; break; default: eventGrp.customEventName = _customEventNames[customEventIndex.Value]; break; } } } else { var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", eventGrp.customEventName); if (newCustomEvent != eventGrp.customEventName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Custom Event Name"); eventGrp.customEventName = newCustomEvent; } } } } if (eventGrp.SoundEvents.Count == 0) { eventGrp.SoundEvents.Add(new AudioEvent()); } if (!hideActions) { if (showLayerTagFilter) { DTGUIHelper.AddSpaceForNonU5(2); } DTGUIHelper.StartGroupHeader(); EditorGUILayout.BeginHorizontal(); var newRetrigger = (EventSounds.RetriggerLimMode)EditorGUILayout.EnumPopup("Retrigger Limit Mode", eventGrp.retriggerLimitMode); if (newRetrigger != eventGrp.retriggerLimitMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Retrigger Limit Mode"); eventGrp.retriggerLimitMode = newRetrigger; } DTGUIHelper.AddHelpIcon("https://dl.dropboxusercontent.com/u/40293802/DarkTonic/MA_OnlineDocs/EventSounds.htm#Retrigger"); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); switch (eventGrp.retriggerLimitMode) { case EventSounds.RetriggerLimMode.FrameBased: var newFrm = EditorGUILayout.IntSlider("Min Frames Between", eventGrp.limitPerXFrm, 0, 10000); if (newFrm != eventGrp.limitPerXFrm) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Frames Between"); eventGrp.limitPerXFrm = newFrm; } break; case EventSounds.RetriggerLimMode.TimeBased: var newSec = EditorGUILayout.Slider("Min Seconds Between", eventGrp.limitPerXSec, 0f, 10000f); if (newSec != eventGrp.limitPerXSec) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Min Seconds Between"); eventGrp.limitPerXSec = newSec; } break; } EditorGUILayout.EndVertical(); AudioEvent prevEvent = null; for (var j = 0; j < eventGrp.SoundEvents.Count; j++) { DTGUIHelper.AddSpaceForNonU5(2); var showVolumeSlider = true; var aEvent = eventGrp.SoundEvents[j]; EditorGUI.indentLevel = 1; DTGUIHelper.StartGroupHeader(); EditorGUILayout.BeginHorizontal(); var newExpanded = DTGUIHelper.Foldout(aEvent.isExpanded, "Action #" + (j + 1)); if (newExpanded != aEvent.isExpanded) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle expand Action"); aEvent.isExpanded = newExpanded; } GUILayout.FlexibleSpace(); var newActionName = GUILayout.TextField(aEvent.actionName, GUILayout.Width(150)); if (newActionName != aEvent.actionName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Rename action"); aEvent.actionName = newActionName; } var buttonPressed = DTGUIHelper.AddFoldOutListItemButtonItems(j, eventGrp.SoundEvents.Count, "Action", true, false, true); GUILayout.Space(4); DTGUIHelper.AddHelpIcon("https://dl.dropboxusercontent.com/u/40293802/DarkTonic/MA_OnlineDocs/EventSounds.htm#Actions"); EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); GUI.backgroundColor = Color.white; if (prevEvent != null && prevEvent.IsFadeCommand) { DTGUIHelper.ShowLargeBarAlert("This action will start immediately after the fade action above is *started*, not finished"); } if (aEvent.isExpanded) { EditorGUI.indentLevel = 0; var newSoundType = (MasterAudio.EventSoundFunctionType)EditorGUILayout.EnumPopup("Action Type", aEvent.currentSoundFunctionType); if (newSoundType != aEvent.currentSoundFunctionType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Action Type"); aEvent.currentSoundFunctionType = newSoundType; } switch (aEvent.currentSoundFunctionType) { case MasterAudio.EventSoundFunctionType.PlaySound: if (_maInScene) { var existingIndex = _groupNames.IndexOf(aEvent.soundType); int? groupIndex = null; EditorGUI.indentLevel = 1; var noGroup = false; var noMatch = false; if (existingIndex >= 1) { EditorGUILayout.BeginHorizontal(); groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray()); if (existingIndex == 1) { noGroup = true; } var button = DTGUIHelper.AddSettingsButton("Sound Group"); switch (button) { case DTGUIHelper.DTFunctionButtons.Go: var grp = _groupNames[existingIndex]; var trs = MasterAudio.FindGroupTransform(grp); if (trs != null) { Selection.activeObject = trs; } break; } EditorGUILayout.EndHorizontal(); } else if (existingIndex == -1 && aEvent.soundType == MasterAudio.NoGroupName) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray()); } else { // non-match noMatch = true; var newSound = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSound != aEvent.soundType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); aEvent.soundType = newSound; } var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray()); if (newIndex >= 0) { groupIndex = newIndex; } } if (noGroup) { DTGUIHelper.ShowRedError("No Sound Group specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one."); } if (groupIndex.HasValue) { if (existingIndex != groupIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); } switch (groupIndex.Value) { case -1: aEvent.soundType = MasterAudio.NoGroupName; break; default: aEvent.soundType = _groupNames[groupIndex.Value]; break; } } } else { var newSType = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSType != aEvent.soundType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); aEvent.soundType = newSType; } } var newVarType = (EventSounds.VariationType)EditorGUILayout.EnumPopup("Variation Mode", aEvent.variationType); if (newVarType != aEvent.variationType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Mode"); aEvent.variationType = newVarType; } if (aEvent.variationType == EventSounds.VariationType.PlaySpecific) { var newVarName = EditorGUILayout.TextField("Variation Name", aEvent.variationName); if (newVarName != aEvent.variationName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Variation Name"); aEvent.variationName = newVarName; } if (string.IsNullOrEmpty(aEvent.variationName)) { DTGUIHelper.ShowRedError("Variation Name is empty. No sound will play."); } } if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newVol = DTGUIHelper.DisplayVolumeField(aEvent.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true); if (newVol != aEvent.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume"); aEvent.volume = newVol; } } var newFixedPitch = EditorGUILayout.Toggle("Override pitch?", aEvent.useFixedPitch); if (newFixedPitch != aEvent.useFixedPitch) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Override pitch"); aEvent.useFixedPitch = newFixedPitch; } if (aEvent.useFixedPitch) { var newPitch = DTGUIHelper.DisplayPitchField(aEvent.pitch); if (newPitch != aEvent.pitch) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Pitch"); aEvent.pitch = newPitch; } } var newDelay = EditorGUILayout.Slider("Delay Sound (sec)", aEvent.delaySound, 0f, 10f); if (newDelay != aEvent.delaySound) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Delay Sound"); aEvent.delaySound = newDelay; } break; case MasterAudio.EventSoundFunctionType.PlaylistControl: EditorGUI.indentLevel = 1; var newPlaylistCmd = (MasterAudio.PlaylistCommand)EditorGUILayout.EnumPopup("Playlist Command", aEvent.currentPlaylistCommand); if (newPlaylistCmd != aEvent.currentPlaylistCommand) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Playlist Command"); aEvent.currentPlaylistCommand = newPlaylistCmd; } if (aEvent.currentPlaylistCommand != MasterAudio.PlaylistCommand.None) { // show Playlist Controller dropdown if (EventSounds.PlaylistCommandsWithAll.Contains(aEvent.currentPlaylistCommand)) { var newAllControllers = EditorGUILayout.Toggle("All Playlist Controllers?", aEvent.allPlaylistControllersForGroupCmd); if (newAllControllers != aEvent.allPlaylistControllersForGroupCmd) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle All Playlist Controllers"); aEvent.allPlaylistControllersForGroupCmd = newAllControllers; } } if (!aEvent.allPlaylistControllersForGroupCmd) { if (_playlistControllerNames.Count > 0) { var existingIndex = _playlistControllerNames.IndexOf(aEvent.playlistControllerName); int? playlistControllerIndex = null; var noPC = false; var noMatch = false; if (existingIndex >= 1) { playlistControllerIndex = EditorGUILayout.Popup("Playlist Controller", existingIndex, _playlistControllerNames.ToArray()); if (existingIndex == 1) { noPC = true; } } else if (existingIndex == -1 && aEvent.playlistControllerName == MasterAudio.NoGroupName) { playlistControllerIndex = EditorGUILayout.Popup("Playlist Controller", existingIndex, _playlistControllerNames.ToArray()); } else { // non-match noMatch = true; var newPlaylistController = EditorGUILayout.TextField("Playlist Controller", aEvent.playlistControllerName); if (newPlaylistController != aEvent.playlistControllerName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Playlist Controller"); aEvent.playlistControllerName = newPlaylistController; } var newIndex = EditorGUILayout.Popup("All Playlist Controllers", -1, _playlistControllerNames.ToArray()); if (newIndex >= 0) { playlistControllerIndex = newIndex; } } if (noPC) { DTGUIHelper.ShowRedError("No Playlist Controller specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Playlist Controller found no match. Type in or choose one."); } if (playlistControllerIndex.HasValue) { if (existingIndex != playlistControllerIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Playlist Controller"); } switch (playlistControllerIndex.Value) { case -1: aEvent.playlistControllerName = MasterAudio.NoGroupName; break; default: aEvent.playlistControllerName = _playlistControllerNames[playlistControllerIndex.Value]; break; } } } else { var newPlaylistControllerName = EditorGUILayout.TextField("Playlist Controller", aEvent.playlistControllerName); if (newPlaylistControllerName != aEvent.playlistControllerName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Playlist Controller"); aEvent.playlistControllerName = newPlaylistControllerName; } } } } switch (aEvent.currentPlaylistCommand) { case MasterAudio.PlaylistCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.PlaylistCommand.StopLoopingCurrentSong: break; case MasterAudio.PlaylistCommand.ChangePlaylist: case MasterAudio.PlaylistCommand.Start: // show playlist name dropdown if (_maInScene) { var existingIndex = _playlistNames.IndexOf(aEvent.playlistName); int? playlistIndex = null; var noPl = false; var noMatch = false; if (existingIndex >= 1) { playlistIndex = EditorGUILayout.Popup("Playlist Name", existingIndex, _playlistNames.ToArray()); if (existingIndex == 1) { noPl = true; } } else if (existingIndex == -1 && aEvent.playlistName == MasterAudio.NoGroupName) { playlistIndex = EditorGUILayout.Popup("Playlist Name", existingIndex, _playlistNames.ToArray()); } else { // non-match noMatch = true; var newPlaylist = EditorGUILayout.TextField("Playlist Name", aEvent.playlistName); if (newPlaylist != aEvent.playlistName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Playlist Name"); aEvent.playlistName = newPlaylist; } var newIndex = EditorGUILayout.Popup("All Playlists", -1, _playlistNames.ToArray()); if (newIndex >= 0) { playlistIndex = newIndex; } } if (noPl) { DTGUIHelper.ShowRedError("No Playlist Name specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Playlist Name found no match. Type in or choose one."); } if (playlistIndex.HasValue) { if (existingIndex != playlistIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Playlist Name"); } switch (playlistIndex.Value) { case -1: aEvent.playlistName = MasterAudio.NoGroupName; break; default: aEvent.playlistName = _playlistNames[playlistIndex.Value]; break; } } } else { var newPlaylistName = EditorGUILayout.TextField("Playlist Name", aEvent.playlistName); if (newPlaylistName != aEvent.playlistName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Playlist Name"); aEvent.playlistName = newPlaylistName; } } if (aEvent.currentPlaylistCommand == MasterAudio.PlaylistCommand.ChangePlaylist) { var newStartPlaylist = EditorGUILayout.Toggle("Start Playlist?", aEvent.startPlaylist); if (newStartPlaylist != aEvent.startPlaylist) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Start Playlist"); aEvent.startPlaylist = newStartPlaylist; } } break; case MasterAudio.PlaylistCommand.FadeToVolume: if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newFadeVol = DTGUIHelper.DisplayVolumeField(aEvent.fadeVolume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Target Volume"); if (newFadeVol != aEvent.fadeVolume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Target Volume"); aEvent.fadeVolume = newFadeVol; } } var newFadeTime = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeTime != aEvent.fadeTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Fade Time"); aEvent.fadeTime = newFadeTime; } break; case MasterAudio.PlaylistCommand.PlayClip: var newClip = EditorGUILayout.TextField("Clip Name", aEvent.clipName); if (newClip != aEvent.clipName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Clip Name"); aEvent.clipName = newClip; } if (string.IsNullOrEmpty(aEvent.clipName)) { DTGUIHelper.ShowRedError("Clip name is empty. Action will do nothing."); } break; } break; case MasterAudio.EventSoundFunctionType.GroupControl: EditorGUI.indentLevel = 1; var newGroupCmd = (MasterAudio.SoundGroupCommand)EditorGUILayout.EnumPopup("Group Command", aEvent.currentSoundGroupCommand); if (newGroupCmd != aEvent.currentSoundGroupCommand) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Group Command"); aEvent.currentSoundGroupCommand = newGroupCmd; } if (!MasterAudio.GroupCommandsWithNoGroupSelector.Contains(aEvent.currentSoundGroupCommand)) { if (!MasterAudio.GroupCommandsWithNoAllGroupSelector.Contains(aEvent.currentSoundGroupCommand)) { var newAllTypes = EditorGUILayout.Toggle("Do For Every Group?", aEvent.allSoundTypesForGroupCmd); if (newAllTypes != aEvent.allSoundTypesForGroupCmd) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Do For Every Group?"); aEvent.allSoundTypesForGroupCmd = newAllTypes; } } if (!aEvent.allSoundTypesForGroupCmd) { if (_maInScene) { var existingIndex = _groupNames.IndexOf(aEvent.soundType); int? groupIndex = null; var noGroup = false; var noMatch = false; if (existingIndex >= 1) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray()); if (existingIndex == 1) { noGroup = true; } } else if (existingIndex == -1 && aEvent.soundType == MasterAudio.NoGroupName) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray()); } else { // non-match noMatch = true; var newSType = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSType != aEvent.soundType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); aEvent.soundType = newSType; } var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray()); if (newIndex >= 0) { groupIndex = newIndex; } } if (noMatch) { DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one."); } else if (noGroup) { DTGUIHelper.ShowRedError("No Sound Group specified. Action will do nothing."); } if (groupIndex.HasValue) { if (existingIndex != groupIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); } switch (groupIndex.Value) { case -1: aEvent.soundType = MasterAudio.NoGroupName; break; default: aEvent.soundType = _groupNames[groupIndex.Value]; break; } } } else { var newSoundT = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSoundT != aEvent.soundType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); aEvent.soundType = newSoundT; } } } } switch (aEvent.currentSoundGroupCommand) { case MasterAudio.SoundGroupCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.SoundGroupCommand.FadeToVolume: if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newFadeVol = DTGUIHelper.DisplayVolumeField(aEvent.fadeVolume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Target Volume"); if (newFadeVol != aEvent.fadeVolume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Target Volume"); aEvent.fadeVolume = newFadeVol; } } var newFadeTime = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeTime != aEvent.fadeTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Fade Time"); aEvent.fadeTime = newFadeTime; } break; case MasterAudio.SoundGroupCommand.FadeOutAllOfSound: var newFadeT = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeT != aEvent.fadeTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Fade Time"); aEvent.fadeTime = newFadeT; } break; case MasterAudio.SoundGroupCommand.FadeOutSoundGroupOfTransform: var newFade = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFade != aEvent.fadeTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Fade Time"); aEvent.fadeTime = newFade; } break; case MasterAudio.SoundGroupCommand.Mute: break; case MasterAudio.SoundGroupCommand.Pause: break; case MasterAudio.SoundGroupCommand.Solo: break; case MasterAudio.SoundGroupCommand.Unmute: break; case MasterAudio.SoundGroupCommand.Unpause: break; case MasterAudio.SoundGroupCommand.Unsolo: break; } break; case MasterAudio.EventSoundFunctionType.BusControl: EditorGUI.indentLevel = 1; var newBusCmd = (MasterAudio.BusCommand)EditorGUILayout.EnumPopup("Bus Command", aEvent.currentBusCommand); if (newBusCmd != aEvent.currentBusCommand) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Bus Command"); aEvent.currentBusCommand = newBusCmd; } if (aEvent.currentBusCommand != MasterAudio.BusCommand.None) { var newAllTypes = EditorGUILayout.Toggle("Do For Every Bus?", aEvent.allSoundTypesForBusCmd); if (newAllTypes != aEvent.allSoundTypesForBusCmd) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Do For Every Bus?"); aEvent.allSoundTypesForBusCmd = newAllTypes; } if (!aEvent.allSoundTypesForBusCmd) { if (_maInScene) { var existingIndex = _busNames.IndexOf(aEvent.busName); int? busIndex = null; var noBus = false; var noMatch = false; if (existingIndex >= 1) { busIndex = EditorGUILayout.Popup("Bus Name", existingIndex, _busNames.ToArray()); if (existingIndex == 1) { noBus = true; } } else if (existingIndex == -1 && aEvent.busName == MasterAudio.NoGroupName) { busIndex = EditorGUILayout.Popup("Bus Name", existingIndex, _busNames.ToArray()); } else { // non-match var newBusName = EditorGUILayout.TextField("Bus Name", aEvent.busName); if (newBusName != aEvent.busName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Bus Name"); aEvent.busName = newBusName; } var newIndex = EditorGUILayout.Popup("All Buses", -1, _busNames.ToArray()); if (newIndex >= 0) { busIndex = newIndex; } noMatch = true; } if (noBus) { DTGUIHelper.ShowRedError("No Bus Name specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Bus Name found no match. Type in or choose one."); } if (busIndex.HasValue) { if (existingIndex != busIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Bus"); } switch (busIndex.Value) { case -1: aEvent.busName = MasterAudio.NoGroupName; break; default: aEvent.busName = _busNames[busIndex.Value]; break; } } } else { var newBusName = EditorGUILayout.TextField("Bus Name", aEvent.busName); if (newBusName != aEvent.busName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Bus Name"); aEvent.busName = newBusName; } } } } switch (aEvent.currentBusCommand) { case MasterAudio.BusCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.BusCommand.ChangeBusPitch: var newPitch = DTGUIHelper.DisplayPitchField(aEvent.pitch); if (newPitch != aEvent.pitch) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Pitch"); aEvent.pitch = newPitch; } break; case MasterAudio.BusCommand.FadeToVolume: if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newFadeVol = DTGUIHelper.DisplayVolumeField(aEvent.fadeVolume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Target Volume"); if (newFadeVol != aEvent.fadeVolume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Target Volume"); aEvent.fadeVolume = newFadeVol; } } var newFadeTime = EditorGUILayout.Slider("Fade Time", aEvent.fadeTime, 0f, 10f); if (newFadeTime != aEvent.fadeTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Fade Time"); aEvent.fadeTime = newFadeTime; } break; case MasterAudio.BusCommand.Pause: break; case MasterAudio.BusCommand.Unpause: break; } break; case MasterAudio.EventSoundFunctionType.CustomEventControl: if (eType == EventSounds.EventType.UserDefinedEvent) { DTGUIHelper.ShowRedError("Custom Event Receivers cannot fire events. Select another Action Type."); break; } EditorGUI.indentLevel = 1; var newEventCmd = (MasterAudio.CustomEventCommand)EditorGUILayout.EnumPopup("Custom Event Cmd", aEvent.currentCustomEventCommand); if (newEventCmd != aEvent.currentCustomEventCommand) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Custom Event Command"); aEvent.currentCustomEventCommand = newEventCmd; } switch (aEvent.currentCustomEventCommand) { case MasterAudio.CustomEventCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.CustomEventCommand.FireEvent: if (_maInScene) { var existingIndex = _customEventNames.IndexOf(aEvent.theCustomEventName); int? customEventIndex = null; EditorGUI.indentLevel = 1; var noEvent = false; var noMatch = false; if (existingIndex >= 1) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray()); if (existingIndex == 1) { noEvent = true; } } else if (existingIndex == -1 && aEvent.soundType == MasterAudio.NoGroupName) { customEventIndex = EditorGUILayout.Popup("Custom Event Name", existingIndex, _customEventNames.ToArray()); } else { // non-match noMatch = true; var newEventName = EditorGUILayout.TextField("Custom Event Name", aEvent.theCustomEventName); if (newEventName != aEvent.theCustomEventName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Custom Event Name"); aEvent.theCustomEventName = newEventName; } var newIndex = EditorGUILayout.Popup("All Custom Events", -1, _customEventNames.ToArray()); if (newIndex >= 0) { customEventIndex = newIndex; } } if (noEvent) { DTGUIHelper.ShowRedError("No Custom Event specified. This section will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Custom Event found no match. Type in or choose one."); } if (customEventIndex.HasValue) { if (existingIndex != customEventIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Custom Event"); } switch (customEventIndex.Value) { case -1: aEvent.theCustomEventName = MasterAudio.NoGroupName; break; default: aEvent.theCustomEventName = _customEventNames[customEventIndex.Value]; break; } } } else { var newCustomEvent = EditorGUILayout.TextField("Custom Event Name", aEvent.theCustomEventName); if (newCustomEvent != aEvent.theCustomEventName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Custom Event Name"); aEvent.theCustomEventName = newCustomEvent; } } break; } break; case MasterAudio.EventSoundFunctionType.GlobalControl: EditorGUI.indentLevel = 1; var newCmd = (MasterAudio.GlobalCommand)EditorGUILayout.EnumPopup("Global Cmd", aEvent.currentGlobalCommand); if (newCmd != aEvent.currentGlobalCommand) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Global Command"); aEvent.currentGlobalCommand = newCmd; } if (aEvent.currentGlobalCommand == MasterAudio.GlobalCommand.None) { DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); } switch (aEvent.currentGlobalCommand) { case MasterAudio.GlobalCommand.SetMasterMixerVolume: if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newFadeVol = DTGUIHelper.DisplayVolumeField(aEvent.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Master Mixer Volume"); if (newFadeVol != aEvent.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Master Mixer Volume"); aEvent.volume = newFadeVol; } } break; case MasterAudio.GlobalCommand.SetMasterPlaylistVolume: if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newFadeVol = DTGUIHelper.DisplayVolumeField(aEvent.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Master Playlist Volume"); if (newFadeVol != aEvent.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Master Playlist Volume"); aEvent.volume = newFadeVol; } } break; } break; #if UNITY_5 case MasterAudio.EventSoundFunctionType.UnityMixerControl: var newMix = (MasterAudio.UnityMixerCommand)EditorGUILayout.EnumPopup("Unity Mixer Cmd", aEvent.currentMixerCommand); if (newMix != aEvent.currentMixerCommand) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Unity Mixer Cmd"); aEvent.currentMixerCommand = newMix; } EditorGUI.indentLevel = 1; switch (aEvent.currentMixerCommand) { case MasterAudio.UnityMixerCommand.TransitionToSnapshot: var newTime = EditorGUILayout.Slider("Transition Time", aEvent.snapshotTransitionTime, 0, 100); if (newTime != aEvent.snapshotTransitionTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Transition Time"); aEvent.snapshotTransitionTime = newTime; } var newSnap = (AudioMixerSnapshot)EditorGUILayout.ObjectField("Snapshot", aEvent.snapshotToTransitionTo, typeof(AudioMixerSnapshot), false); if (newSnap != aEvent.snapshotToTransitionTo) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Snapshot"); aEvent.snapshotToTransitionTo = newSnap; } if (aEvent.snapshotToTransitionTo == null) { DTGUIHelper.ShowRedError("No snapshot selected. No transition will be made."); } break; case MasterAudio.UnityMixerCommand.TransitionToSnapshotBlend: newTime = EditorGUILayout.Slider("Transition Time", aEvent.snapshotTransitionTime, 0, 100); if (newTime != aEvent.snapshotTransitionTime) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Transition Time"); aEvent.snapshotTransitionTime = newTime; } if (aEvent.snapshotsToBlend.Count == 0) { DTGUIHelper.ShowRedError("You have no snapshots to blend. This action will do nothing."); } else { EditorGUILayout.Separator(); } for (var i = 0; i < aEvent.snapshotsToBlend.Count; i++) { var aSnap = aEvent.snapshotsToBlend[i]; newSnap = (AudioMixerSnapshot)EditorGUILayout.ObjectField("Snapshot #" + (i + 1), aSnap.snapshot, typeof(AudioMixerSnapshot), false); if (newSnap != aSnap.snapshot) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Snapshot"); aSnap.snapshot = newSnap; } if (aSnap.snapshot == null) { DTGUIHelper.ShowRedError("No snapshot selected. This item will not be used for blending."); continue; } var newWeight = EditorGUILayout.Slider("Weight", aSnap.weight, 0f, 1f); if (newWeight != aSnap.weight) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Weight"); aSnap.weight = newWeight; } EditorGUILayout.Separator(); } EditorGUILayout.BeginHorizontal(); GUILayout.Space(16); GUI.contentColor = DTGUIHelper.BrightButtonColor; if (GUILayout.Button(new GUIContent("Add Snapshot", "Click to add a Snapshot"), EditorStyles.toolbarButton, GUILayout.Width(85))) { aEvent.snapshotsToBlend.Add(new AudioEvent.MA_SnapshotInfo(null, 1f)); } if (aEvent.snapshotsToBlend.Count > 0) { GUILayout.Space(6); GUI.contentColor = Color.red; if (DTGUIHelper.AddDeleteIcon("Snapshot", true)) { aEvent.snapshotsToBlend.RemoveAt(aEvent.snapshotsToBlend.Count - 1); } } EditorGUILayout.EndHorizontal(); GUI.contentColor = Color.white; break; } break; #endif case MasterAudio.EventSoundFunctionType.PersistentSettingsControl: EditorGUI.indentLevel = 1; var newPersistentCmd = (MasterAudio.PersistentSettingsCommand)EditorGUILayout.EnumPopup("Persistent Settings Command", aEvent.currentPersistentSettingsCommand); if (newPersistentCmd != aEvent.currentPersistentSettingsCommand) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Persistent Settings Command"); aEvent.currentPersistentSettingsCommand = newPersistentCmd; } switch (aEvent.currentPersistentSettingsCommand) { case MasterAudio.PersistentSettingsCommand.None: DTGUIHelper.ShowRedError("You have no command selected. Action will do nothing."); break; case MasterAudio.PersistentSettingsCommand.SetBusVolume: var newAllTypes = EditorGUILayout.Toggle("Do For Every Bus?", aEvent.allSoundTypesForBusCmd); if (newAllTypes != aEvent.allSoundTypesForBusCmd) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Do For Every Bus?"); aEvent.allSoundTypesForBusCmd = newAllTypes; } if (!aEvent.allSoundTypesForBusCmd) { if (_maInScene) { var existingIndex = _busNames.IndexOf(aEvent.busName); int? busIndex = null; var noBus = false; var noMatch = false; if (existingIndex >= 1) { busIndex = EditorGUILayout.Popup("Bus Name", existingIndex, _busNames.ToArray()); if (existingIndex == 1) { noBus = true; } } else if (existingIndex == -1 && aEvent.busName == MasterAudio.NoGroupName) { busIndex = EditorGUILayout.Popup("Bus Name", existingIndex, _busNames.ToArray()); } else { // non-match var newBusName = EditorGUILayout.TextField("Bus Name", aEvent.busName); if (newBusName != aEvent.busName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Bus Name"); aEvent.busName = newBusName; } var newIndex = EditorGUILayout.Popup("All Buses", -1, _busNames.ToArray()); if (newIndex >= 0) { busIndex = newIndex; } noMatch = true; } if (noBus) { DTGUIHelper.ShowRedError("No Bus Name specified. Action will do nothing."); } else if (noMatch) { DTGUIHelper.ShowRedError("Bus Name found no match. Type in or choose one."); } if (busIndex.HasValue) { if (existingIndex != busIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Bus"); } switch (busIndex.Value) { case -1: aEvent.busName = MasterAudio.NoGroupName; break; default: aEvent.busName = _busNames[busIndex.Value]; break; } } } else { var newBusName = EditorGUILayout.TextField("Bus Name", aEvent.busName); if (newBusName != aEvent.busName) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Bus Name"); aEvent.busName = newBusName; } } } if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newVol = DTGUIHelper.DisplayVolumeField(aEvent.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true); if (newVol != aEvent.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume"); aEvent.volume = newVol; } } break; case MasterAudio.PersistentSettingsCommand.SetGroupVolume: var newAllGrps = EditorGUILayout.Toggle("Do For Every Group?", aEvent.allSoundTypesForGroupCmd); if (newAllGrps != aEvent.allSoundTypesForGroupCmd) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "toggle Do For Every Group?"); aEvent.allSoundTypesForGroupCmd = newAllGrps; } if (!aEvent.allSoundTypesForGroupCmd) { if (_maInScene) { var existingIndex = _groupNames.IndexOf(aEvent.soundType); int? groupIndex = null; var noGroup = false; var noMatch = false; if (existingIndex >= 1) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray()); if (existingIndex == 1) { noGroup = true; } } else if (existingIndex == -1 && aEvent.soundType == MasterAudio.NoGroupName) { groupIndex = EditorGUILayout.Popup("Sound Group", existingIndex, _groupNames.ToArray()); } else { // non-match noMatch = true; var newSType = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSType != aEvent.soundType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); aEvent.soundType = newSType; } var newIndex = EditorGUILayout.Popup("All Sound Groups", -1, _groupNames.ToArray()); if (newIndex >= 0) { groupIndex = newIndex; } } if (noMatch) { DTGUIHelper.ShowRedError("Sound Group found no match. Type in or choose one."); } else if (noGroup) { DTGUIHelper.ShowRedError("No Sound Group specified. Action will do nothing."); } if (groupIndex.HasValue) { if (existingIndex != groupIndex.Value) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); } switch (groupIndex.Value) { case -1: aEvent.soundType = MasterAudio.NoGroupName; break; default: aEvent.soundType = _groupNames[groupIndex.Value]; break; } } } else { var newSoundT = EditorGUILayout.TextField("Sound Group", aEvent.soundType); if (newSoundT != aEvent.soundType) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Sound Group"); aEvent.soundType = newSoundT; } } } if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newVol = DTGUIHelper.DisplayVolumeField(aEvent.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true); if (newVol != aEvent.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume"); aEvent.volume = newVol; } } break; case MasterAudio.PersistentSettingsCommand.SetMixerVolume: if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newVol = DTGUIHelper.DisplayVolumeField(aEvent.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Mixer Volume"); if (newVol != aEvent.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Mixer Volume"); aEvent.volume = newVol; } } break; case MasterAudio.PersistentSettingsCommand.SetMusicVolume: if (isSliderChangedEvent) { var newSlider = (AudioEvent.TargetVolumeMode) EditorGUILayout.EnumPopup("Volume Mode", aEvent.targetVolMode); if (newSlider != aEvent.targetVolMode) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Volume Mode"); aEvent.targetVolMode = newSlider; } if (aEvent.targetVolMode == AudioEvent.TargetVolumeMode.UseSliderValue) { showVolumeSlider = false; } } if (showVolumeSlider) { var newVol = DTGUIHelper.DisplayVolumeField(aEvent.volume, DTGUIHelper.VolumeFieldType.None, MasterAudio.MixerWidthMode.Normal, 0f, true, "Music Volume"); if (newVol != aEvent.volume) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "change Music Volume"); aEvent.volume = newVol; } } break; } break; } EditorGUI.indentLevel = 0; } switch (buttonPressed) { case DTGUIHelper.DTFunctionButtons.Add: indexToInsert = j + 1; break; case DTGUIHelper.DTFunctionButtons.Remove: indexToRemove = j; break; case DTGUIHelper.DTFunctionButtons.ShiftUp: indexToShiftUp = j; break; case DTGUIHelper.DTFunctionButtons.ShiftDown: indexToShiftDown = j; break; } prevEvent = aEvent; EditorGUILayout.EndVertical(); } } AudioEvent item = null; if (indexToInsert.HasValue) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Add action"); eventGrp.SoundEvents.Insert(indexToInsert.Value, new AudioEvent()); } else if (indexToRemove.HasValue) { if (eventGrp.SoundEvents.Count <= 1) { DTGUIHelper.ShowAlert("You cannot delete the last Action. Delete this event trigger if you don't need it."); } else { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Delete action"); eventGrp.SoundEvents.RemoveAt(indexToRemove.Value); } } else if (indexToShiftUp.HasValue) { item = eventGrp.SoundEvents[indexToShiftUp.Value]; AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Shift up event action"); eventGrp.SoundEvents.Insert(indexToShiftUp.Value - 1, item); eventGrp.SoundEvents.RemoveAt(indexToShiftUp.Value + 1); } else if (indexToShiftDown.HasValue) { var index = indexToShiftDown.Value + 1; item = eventGrp.SoundEvents[index]; AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "Shift down event action"); eventGrp.SoundEvents.Insert(index - 1, item); eventGrp.SoundEvents.RemoveAt(index + 1); } DTGUIHelper.EndGroupedControls(); return _isDirty; }
private void CreateMechanimStateEntered(bool recordUndo) { var newEvent = new AudioEvent(); if (recordUndo) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "add Mechanim State Entered Sound"); } var newGrp = new AudioEventGroup { isMechanimStateCheckEvent = true, mechanimEventActive = true }; newGrp.SoundEvents.Add(newEvent); _sounds.mechanimStateChangedSounds.Add(newGrp); }
private void CreateCustomEvent(bool recordUndo) { var newEvent = new AudioEvent(); if (recordUndo) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "add Custom Event Sound"); } var newGrp = new AudioEventGroup { isCustomEvent = true, customSoundActive = true }; newGrp.SoundEvents.Add(newEvent); _sounds.userDefinedSounds.Add(newGrp); }
private static void AddEventIfZero(AudioEventGroup grp) { if (grp.SoundEvents.Count == 0) { grp.SoundEvents.Add(new AudioEvent()); } }
private void RenderEventWithHeader(string text, string undoText, AudioEventGroup grp, EventSounds.EventType eType, int? itemIndex = null) { EditorGUI.indentLevel = 0; var state = grp.isExpanded; // ReSharper disable once ConvertIfStatementToConditionalTernaryExpression if (!state) { GUI.backgroundColor = DTGUIHelper.InactiveHeaderColor; } else { GUI.backgroundColor = DTGUIHelper.ActiveHeaderColor; } GUILayout.BeginHorizontal(); #if UNITY_3_5_7 if (!state) { text += " (Click to expand)"; } #else text = "<b><size=11>" + text + "</size></b>"; #endif if (state) { text = "\u25BC " + text; } else { text = "\u25BA " + text; } if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) { state = !state; } GUILayout.Space(2f); switch (eType) { case EventSounds.EventType.MechanimStateChanged: if (DTGUIHelper.AddDeleteIcon(false, "Mechanim State Entered Trigger") == DTGUIHelper.DTFunctionButtons.Remove) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "delete Mechanim State Entered Sound"); // ReSharper disable once PossibleInvalidOperationException _sounds.mechanimStateChangedSounds.RemoveAt(itemIndex.Value); grp.mechanimEventActive = false; } break; case EventSounds.EventType.UserDefinedEvent: if (DTGUIHelper.AddDeleteIcon(false, "Custom Event Trigger") == DTGUIHelper.DTFunctionButtons.Remove) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, "delete Custom Event Sound"); // ReSharper disable once PossibleInvalidOperationException _sounds.userDefinedSounds.RemoveAt(itemIndex.Value); grp.customSoundActive = false; } break; default: if (DTGUIHelper.AddDeleteIcon(false, "Trigger") == DTGUIHelper.DTFunctionButtons.Remove) { switch (eType) { case EventSounds.EventType.NGUIMouseDown: _sounds.useNguiMouseDownSound = false; break; case EventSounds.EventType.NGUIMouseEnter: _sounds.useNguiMouseEnterSound = false; break; case EventSounds.EventType.NGUIMouseExit: _sounds.useNguiMouseExitSound = false; break; case EventSounds.EventType.NGUIMouseUp: _sounds.useNguiMouseUpSound = false; break; case EventSounds.EventType.NGUIOnClick: _sounds.useNguiOnClickSound = false; break; case EventSounds.EventType.OnCollision: _sounds.useCollisionSound = false; break; case EventSounds.EventType.OnCollision2D: _sounds.useCollision2dSound = false; break; case EventSounds.EventType.OnCollisionExit: _sounds.useCollisionExitSound = false; break; case EventSounds.EventType.OnCollisionExit2D: _sounds.useCollisionExit2dSound = false; break; case EventSounds.EventType.OnDespawned: _sounds.useDespawnedSound = false; break; case EventSounds.EventType.OnDisable: _sounds.useDisableSound = false; break; case EventSounds.EventType.OnEnable: _sounds.useEnableSound = false; break; case EventSounds.EventType.OnInvisible: _sounds.useInvisibleSound = false; break; case EventSounds.EventType.OnMouseClick: _sounds.useMouseClickSound = false; break; case EventSounds.EventType.OnMouseDrag: _sounds.useMouseDragSound = false; break; case EventSounds.EventType.OnMouseEnter: _sounds.useMouseEnterSound = false; break; case EventSounds.EventType.OnMouseExit: _sounds.useMouseExitSound = false; break; case EventSounds.EventType.OnMouseUp: _sounds.useMouseUpSound = false; break; case EventSounds.EventType.OnParticleCollision: _sounds.useParticleCollisionSound = false; break; case EventSounds.EventType.OnSpawned: _sounds.useSpawnedSound = false; break; case EventSounds.EventType.OnStart: _sounds.useStartSound = false; break; case EventSounds.EventType.OnTriggerEnter: _sounds.useTriggerEnterSound = false; break; case EventSounds.EventType.OnTriggerEnter2D: _sounds.useTriggerEnter2dSound = false; break; case EventSounds.EventType.OnTriggerExit: _sounds.useTriggerExitSound = false; break; case EventSounds.EventType.OnTriggerExit2D: _sounds.useTriggerExit2dSound = false; break; case EventSounds.EventType.OnVisible: _sounds.useVisibleSound = false; break; case EventSounds.EventType.UnityBeginDrag: _sounds.useUnityBeginDragSound = false; break; case EventSounds.EventType.UnityButtonClicked: _sounds.useUnityButtonClickedSound = false; break; case EventSounds.EventType.UnityCancel: _sounds.useUnityCancelSound = false; break; case EventSounds.EventType.UnityDeselect: _sounds.useUnityDeselectSound = false; break; case EventSounds.EventType.UnityDrag: _sounds.useUnityDragSound = false; break; case EventSounds.EventType.UnityDrop: _sounds.useUnityDropSound = false; break; case EventSounds.EventType.UnityEndDrag: _sounds.useUnityEndDragSound = false; break; case EventSounds.EventType.UnityInitializePotentialDrag: _sounds.useUnityInitializePotentialDragSound = false; break; case EventSounds.EventType.UnityMove: _sounds.useUnityMoveSound = false; break; case EventSounds.EventType.UnityPointerDown: _sounds.useUnityPointerDownSound = false; break; case EventSounds.EventType.UnityPointerEnter: _sounds.useUnityPointerEnterSound = false; break; case EventSounds.EventType.UnityPointerExit: _sounds.useUnityPointerExitSound = false; break; case EventSounds.EventType.UnityPointerUp: _sounds.useUnityPointerUpSound = false; break; case EventSounds.EventType.UnityScroll: _sounds.useUnityScrollSound = false; break; case EventSounds.EventType.UnitySelect: _sounds.useUnitySelectSound = false; break; case EventSounds.EventType.UnitySliderChanged: _sounds.useUnitySliderChangedSound = false; break; case EventSounds.EventType.UnitySubmit: _sounds.useUnitySubmitSound = false; break; case EventSounds.EventType.UnityUpdateSelected: _sounds.useUnityUpdateSelectedSound = false; break; case EventSounds.EventType.UnityToggle: _sounds.useUnityToggleSound = false; break; default: Debug.LogError("Add code to delete: " + eType); break; } } break; } GUILayout.Space(4f); DTGUIHelper.AddHelpIcon("https://dl.dropboxusercontent.com/u/40293802/DarkTonic/MA_OnlineDocs/EventSounds.htm#EventSettings"); GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; if (!state) { GUILayout.Space(3f); } if (state != grp.isExpanded) { AudioUndoHelper.RecordObjectPropertyForUndo(ref _isDirty, _sounds, undoText); grp.isExpanded = state; } if (grp.isExpanded && !_sounds.disableSounds) { _changedList.Add(RenderAudioEvent(grp, eType)); } DTGUIHelper.VerticalSpace(2); }
private PlaySoundResult PerformSingleAction(AudioEventGroup grp, AudioEvent aEvent, EventType eType, bool isFirstTry = true) { if (disableSounds || MasterAudio.AppIsShuttingDown) { return null; } float volume = aEvent.volume; string sType = aEvent.soundType; float? pitch = aEvent.pitch; if (!aEvent.useFixedPitch) { pitch = null; } PlaySoundResult soundPlayed = null; var soundSpawnModeToUse = soundSpawnMode; if (eType == EventType.OnDisable || eType == EventType.OnDespawned) { soundSpawnModeToUse = MasterAudio.SoundSpawnLocationMode.CallerLocation; } // these events need a PlaySoundResult, the rest do not. Save on allocation! bool needsResult = (eType == EventType.OnStart && !isFirstTry) || eType == EventType.OnMouseDrag; switch (aEvent.currentSoundFunctionType) { case MasterAudio.EventSoundFunctionType.PlaySound: string variationName = null; if (aEvent.variationType == VariationType.PlaySpecific) { variationName = aEvent.variationName; } if (eType == EventType.OnStart && isFirstTry && !MasterAudio.SoundGroupExists(sType)) { // don't try to play sound yet. } else { switch (soundSpawnModeToUse) { case MasterAudio.SoundSpawnLocationMode.CallerLocation: if (needsResult) { soundPlayed = MasterAudio.PlaySound3DAtTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName); } else { MasterAudio.PlaySound3DAtTransformAndForget(sType, this.trans, volume, pitch, aEvent.delaySound, variationName); } break; case MasterAudio.SoundSpawnLocationMode.AttachToCaller: if (needsResult) { soundPlayed = MasterAudio.PlaySound3DFollowTransform(sType, this.trans, volume, pitch, aEvent.delaySound, variationName); } else { MasterAudio.PlaySound3DFollowTransformAndForget(sType, this.trans, volume, pitch, aEvent.delaySound, variationName); } break; case MasterAudio.SoundSpawnLocationMode.MasterAudioLocation: if (needsResult) { soundPlayed = MasterAudio.PlaySound(sType, volume, pitch, aEvent.delaySound, variationName); } else { MasterAudio.PlaySoundAndForget(sType, volume, pitch, aEvent.delaySound, variationName); } break; } } if (eType == EventType.OnMouseDrag) { mouseDragResult = soundPlayed; } if (soundPlayed == null || !soundPlayed.SoundPlayed) { if (eType == EventType.OnStart && isFirstTry) { // race condition met. So try to play it a few more times. StartCoroutine(TryPlayStartSound(grp, aEvent)); } return soundPlayed; } break; case MasterAudio.EventSoundFunctionType.PlaylistControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = true, SoundScheduled = false }; if (string.IsNullOrEmpty(aEvent.playlistControllerName)) { aEvent.playlistControllerName = MasterAudio.ONLY_PLAYLIST_CONTROLLER_NAME; } if (MasterAudio.PlaylistCommandsThatFailOnStart.Contains(aEvent.currentPlaylistCommand) && eType == EventType.OnStart && isFirstTry) { StartCoroutine(TryPlayStartSound(grp, aEvent)); } else { switch (aEvent.currentPlaylistCommand) { case MasterAudio.PlaylistCommand.None: soundPlayed.SoundPlayed = false; break; case MasterAudio.PlaylistCommand.Restart: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.RestartAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.RestartPlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Start: if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME || aEvent.playlistName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.StartPlaylist(aEvent.playlistControllerName, aEvent.playlistName); } break; case MasterAudio.PlaylistCommand.ChangePlaylist: if (string.IsNullOrEmpty(aEvent.playlistName)) { Debug.Log("You have not specified a Playlist name for Event Sounds on '" + this.trans.name + "'."); soundPlayed.SoundPlayed = false; } else { if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.ChangePlaylistByName(aEvent.playlistControllerName, aEvent.playlistName, aEvent.startPlaylist); } } break; case MasterAudio.PlaylistCommand.FadeToVolume: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.FadeAllPlaylistsToVolume(aEvent.fadeVolume, aEvent.fadeTime); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.FadePlaylistToVolume(aEvent.playlistControllerName, aEvent.fadeVolume, aEvent.fadeTime); } break; case MasterAudio.PlaylistCommand.Mute: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.MuteAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.MutePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Unmute: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.UnmuteAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.UnmutePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.ToggleMute: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.ToggleMuteAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.ToggleMutePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.PlayClip: if (string.IsNullOrEmpty(aEvent.clipName)) { Debug.Log("You have not specified a clip name for Event Sounds on '" + this.trans.name + "'."); soundPlayed.SoundPlayed = false; } else { if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { if (!MasterAudio.TriggerPlaylistClip(aEvent.playlistControllerName, aEvent.clipName)) { soundPlayed.SoundPlayed = false; } } } break; case MasterAudio.PlaylistCommand.PlayRandomSong: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.TriggerRandomClipAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.TriggerRandomPlaylistClip(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.PlayNextSong: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.TriggerNextClipAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.TriggerNextPlaylistClip(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Pause: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.PauseAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.PausePlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Stop: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.StopAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.StopPlaylist(aEvent.playlistControllerName); } break; case MasterAudio.PlaylistCommand.Resume: if (aEvent.allPlaylistControllersForGroupCmd) { MasterAudio.ResumeAllPlaylists(); } else if (aEvent.playlistControllerName == MasterAudio.NO_GROUP_NAME) { // don't play } else { MasterAudio.ResumePlaylist(aEvent.playlistControllerName); } break; } } break; case MasterAudio.EventSoundFunctionType.GroupControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = true, SoundScheduled = false }; var soundTypesForCmd = new List<string>(); if (!aEvent.allSoundTypesForGroupCmd || MasterAudio.GroupCommandsWithNoAllGroupSelector.Contains(aEvent.currentSoundGroupCommand)) { soundTypesForCmd.Add(aEvent.soundType); } else { soundTypesForCmd.AddRange(MasterAudio.RuntimeSoundGroupNames); } for (var i = 0; i < soundTypesForCmd.Count; i++) { var soundType = soundTypesForCmd[i]; switch (aEvent.currentSoundGroupCommand) { case MasterAudio.SoundGroupCommand.None: soundPlayed.SoundPlayed = false; break; case MasterAudio.SoundGroupCommand.FadeToVolume: MasterAudio.FadeSoundGroupToVolume(soundType, aEvent.fadeVolume, aEvent.fadeTime); break; case MasterAudio.SoundGroupCommand.FadeOutAllOfSound: MasterAudio.FadeOutAllOfSound(soundType, aEvent.fadeTime); break; case MasterAudio.SoundGroupCommand.Mute: MasterAudio.MuteGroup(soundType); break; case MasterAudio.SoundGroupCommand.Pause: MasterAudio.PauseSoundGroup(soundType); break; case MasterAudio.SoundGroupCommand.Solo: MasterAudio.SoloGroup(soundType); break; case MasterAudio.SoundGroupCommand.StopAllOfSound: MasterAudio.StopAllOfSound(soundType); break; case MasterAudio.SoundGroupCommand.Unmute: MasterAudio.UnmuteGroup(soundType); break; case MasterAudio.SoundGroupCommand.Unpause: MasterAudio.UnpauseSoundGroup(soundType); break; case MasterAudio.SoundGroupCommand.Unsolo: MasterAudio.UnsoloGroup(soundType); break; case MasterAudio.SoundGroupCommand.StopAllSoundsOfTransform: MasterAudio.StopAllSoundsOfTransform(this.trans); break; case MasterAudio.SoundGroupCommand.StopSoundGroupOfTransform: MasterAudio.StopSoundGroupOfTransform(this.trans, soundType); break; case MasterAudio.SoundGroupCommand.PauseAllSoundsOfTransform: MasterAudio.PauseAllSoundsOfTransform(this.trans); break; case MasterAudio.SoundGroupCommand.PauseSoundGroupOfTransform: MasterAudio.PauseSoundGroupOfTransform(this.trans, soundType); break; case MasterAudio.SoundGroupCommand.UnpauseAllSoundsOfTransform: MasterAudio.UnpauseAllSoundsOfTransform(this.trans); break; case MasterAudio.SoundGroupCommand.UnpauseSoundGroupOfTransform: MasterAudio.UnpauseSoundGroupOfTransform(this.trans, soundType); break; case MasterAudio.SoundGroupCommand.FadeOutSoundGroupOfTransform: MasterAudio.FadeOutSoundGroupOfTransform(this.trans, soundType, aEvent.fadeTime); break; } } break; case MasterAudio.EventSoundFunctionType.BusControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = true, SoundScheduled = false }; var busesForCmd = new List<string>(); if (!aEvent.allSoundTypesForBusCmd) { busesForCmd.Add(aEvent.busName); } else { busesForCmd.AddRange(MasterAudio.RuntimeBusNames); } for (var i = 0; i < busesForCmd.Count; i++) { var busName = busesForCmd[i]; switch (aEvent.currentBusCommand) { case MasterAudio.BusCommand.None: soundPlayed.SoundPlayed = false; break; case MasterAudio.BusCommand.FadeToVolume: MasterAudio.FadeBusToVolume(busName, aEvent.fadeVolume, aEvent.fadeTime); break; case MasterAudio.BusCommand.Pause: MasterAudio.PauseBus(busName); break; case MasterAudio.BusCommand.Stop: MasterAudio.StopBus(busName); break; case MasterAudio.BusCommand.Unpause: MasterAudio.UnpauseBus(busName); break; case MasterAudio.BusCommand.Mute: MasterAudio.MuteBus(busName); break; case MasterAudio.BusCommand.Unmute: MasterAudio.UnmuteBus(busName); break; case MasterAudio.BusCommand.Solo: MasterAudio.SoloBus(busName); break; case MasterAudio.BusCommand.Unsolo: MasterAudio.UnsoloBus(busName); break; case MasterAudio.BusCommand.ChangeBusPitch: MasterAudio.ChangeBusPitch(busName, aEvent.pitch); break; } } break; case MasterAudio.EventSoundFunctionType.CustomEventControl: soundPlayed = new PlaySoundResult() { ActingVariation = null, SoundPlayed = false, SoundScheduled = false }; if (eType == EventType.UserDefinedEvent) { Debug.LogError("Custom Event Receivers cannot fire events. Occured in Transform '" + this.name + "'."); break; } switch (aEvent.currentCustomEventCommand) { case MasterAudio.CustomEventCommand.FireEvent: MasterAudio.FireCustomEvent(aEvent.theCustomEventName, this.trans.position); break; } break; case MasterAudio.EventSoundFunctionType.GlobalControl: switch (aEvent.currentGlobalCommand) { case MasterAudio.GlobalCommand.PauseMixer: MasterAudio.PauseMixer(); break; case MasterAudio.GlobalCommand.UnpauseMixer: MasterAudio.UnpauseMixer(); break; case MasterAudio.GlobalCommand.StopMixer: MasterAudio.StopMixer(); break; case MasterAudio.GlobalCommand.MuteEverything: MasterAudio.MuteEverything(); break; case MasterAudio.GlobalCommand.UnmuteEverything: MasterAudio.UnmuteEverything(); break; case MasterAudio.GlobalCommand.PauseEverything: MasterAudio.PauseEverything(); break; case MasterAudio.GlobalCommand.UnpauseEverything: MasterAudio.UnpauseEverything(); break; case MasterAudio.GlobalCommand.StopEverything: MasterAudio.StopEverything(); break; } break; } if (aEvent.emitParticles && soundPlayed != null && (soundPlayed.SoundPlayed || soundPlayed.SoundScheduled)) { MasterAudio.TriggerParticleEmission(this.trans, aEvent.particleCountToEmit); } return soundPlayed; }
public void PlaySounds(AudioEventGroup eventGrp, EventType eType) { for (var i = 0; i < eventGrp.SoundEvents.Count; i++) { PerformSingleAction(eventGrp, eventGrp.SoundEvents[i], eType); } }