public static void SetTargetVolume(InAudioBus bus, float targetVolume, InEventBusAction.VolumeSetMode setMode, float duration, FadeCurveType curveType) { //bus.Dirty = true; if (duration == 0) { bus.Fader.Activated = false; bus.RuntimeSelfVolume = targetVolume; } else { if (setMode == InEventBusAction.VolumeSetMode.Absolute) { bus.Fader.Activated = true; double currentTime = AudioSettings.dspTime; bus.Fader.Initialize(curveType, currentTime, currentTime + duration, bus.RuntimeSelfVolume, targetVolume); } else { bus.Fader.Activated = true; double currentTime = AudioSettings.dspTime; float newVolume = Mathf.Clamp(bus.RuntimeSelfVolume + targetVolume, 0.0f, 1.0f); bus.Fader.Initialize(curveType, currentTime, currentTime + duration, bus.RuntimeSelfVolume, newVolume); } } UpdateVolumes(bus); }
private void CreateAudioPrefab(int levelSize, InAudioBus bus) { GameObject go = new GameObject(); Manager.AudioTree = AudioNodeWorker.CreateTree(go, levelSize, bus); SaveAndLoad.CreateAudioNodeRootPrefab(go); }
public static bool CanBeDuckedBy(InAudioBus selectedNode, InAudioBus dragging) { var draggingBus = dragging; if (draggingBus == null) { return(false); } //Does it already exist in the collection? if (selectedNode.DuckedBy.TrueForAny(data => data.DuckedBy == dragging)) { return(false); } if (draggingBus.IsRoot) { return(false); } if (NodeWorker.IsChildOf(selectedNode, draggingBus)) { return(false); } if (NodeWorker.IsParentOf(selectedNode.GetParent, draggingBus)) { return(false); } return(true); }
public static void DeleteBus(InAudioBus bus, InAudioNode root) { UndoHelper.DoInGroup(() => { UndoHelper.RecordObjectFull(bus.Parent, "Bus deletion"); bus.Parent.Children.Remove(bus); HashSet <InAudioBus> toDelete = new HashSet <InAudioBus>(); GetBusesToDelete(toDelete, bus); var runtimePlayers = bus.RuntimePlayers; if (runtimePlayers != null) { for (int i = 0; i < runtimePlayers.Count; ++i) { runtimePlayers[i].SetNewBus(bus.Parent); } } List <InAudioNode> affectedNodes = new List <InAudioNode>(); //Get all affected nodes TreeWalker.FindAllNodes(root, node => toDelete.Contains(node.GetBus()), affectedNodes); toDelete.ToArray().ForEach(UndoHelper.Destroy); for (int i = 0; i < affectedNodes.Count; ++i) { affectedNodes[i].Bus = bus.Parent; } }); }
public void Load(bool forceReload = false) { if (AudioRoot == null || BankLinkRoot == null || BusRoot == null || EventRoot == null || forceReload) { Component[] audioData; Component[] eventData; Component[] busData; Component[] bankLinkData; SaveAndLoad.LoadManagerData(out audioData, out eventData, out busData, out bankLinkData); BusRoot = CheckData <InAudioBus>(busData); AudioRoot = CheckData <InAudioNode>(audioData); EventRoot = CheckData <InAudioEventNode>(eventData); BankLinkTree = CheckData <InAudioBankLink>(bankLinkData); /*if (BusRoot != null) * BusRootGO = BusRoot.gameObject; * if (AudioRoot != null) * AudioRootGO = AudioRoot.gameObject; * if (EventRoot != null) * EventRootGO = EventRoot.gameObject; * if (BankLinkTree != null) * BankLinkRootGO = BankLinkTree.gameObject;*/ } }
/// <summary> /// Get the runtime volume of this bus /// </summary> /// <param name="bus"></param> /// <returns>The volume. Will return -1.0f if the bus is invalid</returns> public static float BusVolume(InAudioBus bus) { if (bus != null) { return(bus.RuntimeSelfVolume); } return(-1.0f); }
private static void GetBusesToDelete(HashSet <InAudioBus> toDelete, InAudioBus bus) { toDelete.Add(bus); for (int i = 0; i < bus.Children.Count; ++i) { GetBusesToDelete(toDelete, bus.Children[i]); } }
public static void InitVolumes(InAudioBus bus) { bus.RuntimeSelfVolume = bus.SelfVolume; for (int i = 0; i < bus.Children.Count; ++i) { InitVolumes(bus.Children[i]); } }
/// <summary> /// Set the runtime volume of the specified bus /// </summary> /// <param name="bus">The bus to set the volume</param> /// <param name="newVolume">The volume to set</param> /// <returns>The new volume. -1.0f if the bus is null</returns> public static float SetBusVolume(InAudioBus bus, float newVolume) { if (bus != null) { bus.Dirty = true; return(bus.RuntimeSelfVolume = newVolume); } return(-1.0f); }
public static InAudioBus CreateChild(InAudioBus parent) { var child = CreateBus(parent.gameObject, parent, GUIDCreator.Create()); child.FoldedOut = true; child.Name = parent.Name + " Child"; return(child); }
private static InAudioBus CreateBus(GameObject go, InAudioBus parent, int guid) { var node = go.AddComponentUndo <InAudioBus>(); node.GUID = guid; node.name = parent.Name + " Child"; node.AssignParent(parent); return(node); }
public static InAudioNode CreateTree(GameObject go, int numberOfChildren, InAudioBus bus) { var Tree = CreateRoot(go, GUIDCreator.Create()); Tree.Bus = bus; for (int i = 0; i < numberOfChildren; ++i) { var newNode = CreateNode(go, Tree, GUIDCreator.Create(), AudioNodeType.Folder); AddDataClass(newNode); } return(Tree); }
public static void MuteAction(InAudioBus audioBus, InEventBusMuteAction.MuteAction muteAction) { if (muteAction == InEventBusMuteAction.MuteAction.Mute) { audioBus.RuntimeMute = true; } else { audioBus.RuntimeMute = false; } audioBus.Dirty = true; }
/// <summary> /// Check if a bus is muted /// </summary> /// <param name="bus">The bus</param> /// <param name="mute">to mute or unmute</param> public static void IsBusMuted(InAudioBus bus, bool mute) { if (bus != null) { bus.Dirty = true; bus.RuntimeMute = mute; } else { InDebug.LogWarning("Bus instance not set to an instance in mute"); } }
//TODO Move this to another class private static void StopAllNodeInBus(InAudioBus bus) { var players = bus.RuntimePlayers; for (int i = 0; i < players.Count; i++) { players[i].Stop(); } for (int i = 0; i < bus.Children.Count; i++) { StopAllNodeInBus(bus.Children[i]); } }
private static float Ducking(InAudioBus bus) { //The maximum amount of volume it is being ducked float minDucking = 0; int duckedByCount = bus.DuckedBy.Count; for (int i = 0; i < duckedByCount; i++) { DuckingData ducking = bus.DuckedBy[i]; float ducked = 0; if (!ducking.IsBeingDucked) //Release time { //Release time if (ducking.LastDuckedVolume < 0) { ducked = ducking.LastDuckedVolume; ducked -= Mathf.Lerp(ducking.VolumeDucking, 0, ducked) * Time.deltaTime / ducking.ReleaseTime; ducked = Mathf.Clamp(ducked, ducking.VolumeDucking, 0); minDucking = Mathf.Min(minDucking, ducked); minDucking = (1.0f - Curves.CumulativeDistribution(Fader.GetT(ducking.VolumeDucking, 0, minDucking))) * ducking.VolumeDucking; minDucking = Mathf.Clamp(minDucking, ducking.VolumeDucking, 0); } //else //Do nothing as then the amount ducked is zero } else if (ducking.AttackTime > 0 && ducking.LastDuckedVolume > ducking.VolumeDucking) //Attack time { ducked = ducking.LastDuckedVolume; ducked += ducking.VolumeDucking * Time.deltaTime / ducking.AttackTime; ducked = Mathf.Clamp(ducked, ducking.VolumeDucking, 0); minDucking = Mathf.Min(minDucking, ducked); } else { minDucking = Mathf.Min(minDucking, ducking.VolumeDucking); ducked = ducking.VolumeDucking; } ducking.LastDuckedVolume = ducked; //Util.Debug.Graph("Ducked volume", minDucking); } bus.LastDuckedVolume = minDucking; return(minDucking); }
public static void Update(InAudioBus nodeBus, InAudioNode node) { if (nodeBus == null) { return; } var players = nodeBus.RuntimePlayers; int count = players.Count; for (int i = 0; i < count; i++) { var player = players[i]; if (player != null && player.NodePlaying == node) { player.internalDateUpdate(node); } } }
private static int UpdateIsActive(InAudioBus bus) { int soundsInChildren = bus.RuntimePlayers.Count + bus.ExternalSources.Count; for (int i = 0; i < bus.Children.Count; i++) { soundsInChildren += UpdateIsActive(bus.Children[i]); } if (soundsInChildren > 0) { bus.IsActive = true; } else { bus.IsActive = false; } return(soundsInChildren); }
private static void UpdateIfDucking(InAudioBus bus) { for (int i = 0; i < bus.DuckedBy.Count; i++) { DuckingData currentBus = bus.DuckedBy[i]; if (currentBus.DuckedBy.IsActive) { if (!currentBus.IsBeingDucked) { currentBus.IsBeingDucked = true; } } else { currentBus.IsBeingDucked = false; } } for (int i = 0; i < bus.Children.Count; i++) { UpdateIfDucking(bus.Children[i]); } }
public static void Draw(InAudioBus bus) { EditorGUILayout.BeginVertical(); UndoHelper.GUIUndo(bus, "Name Change", ref bus.Name, () => EditorGUILayout.TextField("Name", bus.Name)); EditorGUIHelper.DrawID(bus.GUID); EditorGUILayout.Separator(); if (!Application.isPlaying) { UndoHelper.GUIUndo(bus, "Mute Bus", ref bus.Mute, () => EditorGUILayout.Toggle("Initial Mute", bus.Mute)); } else { UndoHelper.GUIUndo(bus, "Mute Bus (Runtime)", ref bus.RuntimeMute, () => EditorGUILayout.Toggle("Mute (Runtime)", bus.RuntimeMute)); } EditorGUILayout.Separator(); UndoHelper.GUIUndo(bus, "Volume Change", ref bus.Volume, () => EditorGUILayout.Slider("Master Volume", bus.Volume, 0.0f, 1.0f)); if (!Application.isPlaying) { UndoHelper.GUIUndo(bus, "Runtime Volume Change", ref bus.SelfVolume, () => EditorGUILayout.Slider("Initial Runtime Volume", bus.SelfVolume, 0.0f, 1.0f)); } else { UndoHelper.GUIUndo(bus, "Runtime Volume Change", ref bus.RuntimeSelfVolume, () => EditorGUILayout.Slider("Runtime Volume", bus.RuntimeSelfVolume, 0.0f, 1.0f)); } EditorGUILayout.Separator(); GUI.enabled = false; if (Application.isPlaying) { EditorGUILayout.Slider("Ducking", bus.LastDuckedVolume, -1.0f, 0.0f); EditorGUILayout.Separator(); EditorGUILayout.Slider("Final Hierarchy Volume", Mathf.Clamp(bus.FinalVolume, 0, 1), 0, 1.0f); } else { float volume = bus.CombinedVolume; if (bus.RuntimeMute) { volume = 0; } EditorGUILayout.Slider("Final Hierarchy Volume", volume, 0, 1.0f); } GUI.enabled = true; EditorGUILayout.Separator(); EditorGUILayout.Separator(); //Not implemented yet #region Ducking EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Hold Control down and drag a bus here."); EditorGUILayout.LabelField("Cannot add parents or children."); GUILayout.Button("Drag bus here", GUILayout.Width(200)); var dragging = DragAndDrop.objectReferences; OnDragging.OnDraggingObject <InAudioBus>(dragging, GUILayoutUtility.GetLastRect(), buses => AudioBusWorker.CanBeDuckedBy(bus, buses[0]), buses => { UndoHelper.RecordObject(bus, "Add"); for (int i = 0; i < buses.Length; i++) { DuckingData data = new DuckingData(); data.DuckedBy = buses[i]; bus.DuckedBy.Add(data); } } ); EditorGUILayout.LabelField(""); Rect labelArea = GUILayoutUtility.GetLastRect(); labelArea.width = labelArea.width / 4.0f - 5; Rect workArea = labelArea; for (int i = 0; i < bus.DuckedBy.Count; i++) { workArea.width = labelArea.width; workArea.y += workArea.height + 4; workArea.x = labelArea.x; DuckingData data = bus.DuckedBy[i]; EditorGUI.SelectableLabel(workArea, data.DuckedBy.Name); Rect area1 = workArea; workArea.x += workArea.width; UndoHelper.GUIUndo(bus, "Duck Amount Change", () => EditorGUI.Slider(workArea, data.VolumeDucking, -1.0f, 0.0f), v => data.VolumeDucking = v); Rect area2 = workArea; workArea.x += workArea.width; UndoHelper.GUIUndo(bus, "Attack Time", () => EditorGUI.Slider(workArea, data.AttackTime, 0.0f, 10.0f), v => data.AttackTime = v); Rect area3 = workArea; workArea.x += workArea.width; UndoHelper.GUIUndo(bus, "Release Time", () => EditorGUI.Slider(workArea, data.ReleaseTime, 0.0f, 10.0f), v => data.ReleaseTime = v); Rect area4 = workArea; workArea.x += workArea.width; workArea.width = 20; if (GUI.Button(workArea, "X")) { UndoHelper.RecordObjectFull(bus, "X"); bus.DuckedBy.RemoveAt(i); i--; } if (i == 0) //Workaround to avoid a gui layout mismatch { area1.y -= 20; area2.y -= 20; area3.y -= 20; area4.y -= 20; EditorGUI.LabelField(area1, "Ducked By"); EditorGUI.LabelField(area2, "Volume Duck Amount"); EditorGUI.LabelField(area3, "Attack Time"); EditorGUI.LabelField(area4, "Release Time"); } } #endregion /* GUILayout.Label("Nodes Playing In This Specific Bus"); * * lastArea.x += 20; * lastArea.y = lastArea.y + lastArea.height + 2; * lastArea.height = 17; * List<RuntimePlayer> players = node.GetRuntimePlayers(); * for (int i = 0; i < players.Count; i++) * { * GUI.Label(lastArea, players[i].NodePlaying.Name); * * lastArea.y += 20; * } */ EditorGUILayout.EndVertical(); }
public void FindBus(InAudioBus bus) { selectedToolbar = 0; busGUI.Find(bus); }
public static bool Draw(InAudioBus node, bool isSelected) { if (noMargain == null) { noMargain = new GUIStyle(); noMargain.margin = new RectOffset(0, 0, 0, 0); } Rect area = EditorGUILayout.BeginHorizontal(); if (isSelected) { GUI.DrawTexture(area, EditorResources.Background); } GUILayout.Space(EditorGUI.indentLevel * 16); bool folded = node.FoldedOut; Texture picture; if (folded || node.Children.Count == 0) { picture = EditorResources.Minus; } else { picture = EditorResources.Plus; } GUILayout.Label(picture, noMargain, GUILayout.Height(EditorResources.Minus.height), GUILayout.Width(EditorResources.Minus.width)); Rect foldRect = GUILayoutUtility.GetLastRect(); if (Event.current.ClickedWithin(foldRect)) { folded = !folded; Event.current.Use(); } EditorGUILayout.EndHorizontal(); Rect labelArea = GUILayoutUtility.GetLastRect(); Rect buttonArea = labelArea; Rect sliderArea = buttonArea; buttonArea.x = buttonArea.x + 45 + EditorGUI.indentLevel * 16; if (!node.IsRoot) { //buttonArea.x = buttonArea.x + 45 + EditorGUI.indentLevel * 16; buttonArea.width = 20; buttonArea.height = 14; GUI.Label(buttonArea, EditorResources.Up, noMargain); if (Event.current.ClickedWithin(buttonArea)) { NodeWorker.MoveNodeOneUp(node); Event.current.Use(); } buttonArea.y += 15; GUI.Label(buttonArea, EditorResources.Down, noMargain); if (Event.current.ClickedWithin(buttonArea)) { NodeWorker.MoveNodeOneDown(node); Event.current.Use(); } labelArea.x += 25; } else { buttonArea.y += 15; } buttonArea.height = 36; buttonArea.width = 36; buttonArea.y -= 18; buttonArea.x -= 26; GUI.Label(buttonArea, EditorResources.Bus, noMargain); labelArea.y += 6; labelArea.x += 50; EditorGUI.LabelField(labelArea, node.Name); GUI.enabled = false; sliderArea.y += 6; sliderArea.x = labelArea.x + 100; sliderArea.height = 16; sliderArea.width = 180; if (!Application.isPlaying) { float parentVolume = 1.0f; if (node.Parent != null) { parentVolume = node.Parent.CombinedVolume; if (node.Parent.Mute) { parentVolume = 0; } } node.CombinedVolume = node.Volume * node.SelfVolume * parentVolume; float volume = node.CombinedVolume; if (node.Mute) { volume = 0; } EditorGUI.Slider(sliderArea, volume, 0.0f, 1.0f); } else { EditorGUI.Slider(sliderArea, node.FinalVolume, 0.0f, 1.0f); } GUI.enabled = true; return(folded); }
public void SetNewBus(InAudioBus bus) { attachedToBus = bus; }
public static void UpdateVolumes(InAudioBus bus) { Fader fader = bus.Fader; if (fader.Activated) { double currentTime = AudioSettings.dspTime; bus.RuntimeSelfVolume = (float)fader.Lerp(AudioSettings.dspTime); bus.Dirty = true; if (/*bus.RuntimeSelfVolume == fader.EndValue ||*/ currentTime >= fader.EndTime) { fader.Activated = false; } } float parentVolume; if (bus.Parent != null) { var busParent = bus.Parent; parentVolume = busParent.FinalVolume; } else { parentVolume = 1.0f; } if (bus.Parent != null) { bus.Dirty |= bus.Parent.Dirty; } float oldVolume = bus.FinalVolume; bus.FinalVolume = bus.Volume * bus.RuntimeSelfVolume * parentVolume; float duckingVolume = Ducking(bus); bus.FinalVolume += duckingVolume; if (bus.RuntimeMute) { bus.FinalVolume = 0; } if (bus.FinalVolume != oldVolume) { bus.Dirty = true; } bool noListener = false; Vector3 pos = Vector3.zero; if (InAudio.ActiveListener == null) { noListener = true; } else { pos = InAudio.ActiveListener.transform.position; } var players = bus.RuntimePlayers; for (int i = 0; i < players.Count; ++i) { var player = players[i]; if (player != null) { if (!noListener) { player.internalUpdateFalloff(pos); } if (bus.Dirty) { player.UpdateBusVolume(bus.FinalVolume); } } else { players.RemoveAt(i); --i; } } if (bus.Dirty) { for (int i = 0; i < bus.ExternalSources.Count; i++) { bus.ExternalSources[i].UpdateBusVolume(bus.FinalVolume); } } for (int i = 0; i < bus.Children.Count; ++i) { bus.Children[i].Dirty |= bus.Dirty; UpdateVolumes(bus.Children[i]); } bus.Dirty = false; }
public static void UpdateDucking(InAudioBus inAudioBus) { UpdateIsActive(inAudioBus); UpdateIfDucking(inAudioBus); }
public static void SearchFor(InAudioBus bus) { EditorWindow.GetWindow <AuxWindow>().FindBus(bus); }