/// <summary> /// Get data for all ActiveEvents in the AudioManager /// </summary> private void CollectProfilerEvents() { List <ActiveEvent> activeEvents = AudioManager.GetActiveEvents(); ProfilerEvent[] currentEvents = new ProfilerEvent[activeEvents.Count]; for (int i = 0; i < currentEvents.Length; i++) { ActiveEvent tempActiveEvent = activeEvents[i]; ProfilerEvent tempProfilerEvent = new ProfilerEvent(); tempProfilerEvent.eventName = tempActiveEvent.rootEvent.name; tempProfilerEvent.clip = tempActiveEvent.source.clip; tempProfilerEvent.emitterObject = tempActiveEvent.source.gameObject; tempProfilerEvent.bus = tempActiveEvent.source.outputAudioMixerGroup; currentEvents[i] = tempProfilerEvent; } this.profilerFrames.Add(currentEvents); while (this.profilerFrames.Count > MaxFrames) { this.profilerFrames.RemoveAt(0); } }
/// <summary> /// Draw the nodes for the specified frame /// </summary> /// <param name="profilerEvents">The frame to show the ActiveEvents for</param> private void DrawProfilerFrame(ProfilerEvent[] profilerEvents) { this.eventY = 20; this.emitterY = 20; this.busY = 20; List <AudioMixerGroup> buses = new List <AudioMixerGroup>(); List <GameObject> emitters = new List <GameObject>(); BeginWindows(); for (int i = 0; i < profilerEvents.Length; i++) { bool addedEmitter = false; ProfilerEvent tempEvent = profilerEvents[i]; if (tempEvent == null) { continue; } GUI.Window(i, new Rect(eventX, this.eventY, WindowWidth, WindowHeight), DrawWindow, tempEvent.eventName); if (!emitters.Contains(tempEvent.emitterObject)) { emitters.Add(tempEvent.emitterObject); GUI.Window(i + 200, new Rect(emitterX, this.emitterY, WindowWidth, WindowHeight), DrawWindow, tempEvent.emitterObject.name); DrawCurve(new Vector2(eventX + WindowWidth, this.eventY), new Vector2(emitterX, this.emitterY)); addedEmitter = true; } else { //Draw a line to this emitter int emitterNum = emitters.IndexOf(tempEvent.emitterObject); DrawCurve(new Vector2(eventX + WindowWidth, this.eventY), new Vector2(emitterX, 20 + WindowYInterval * emitterNum)); } if (!buses.Contains(tempEvent.bus)) { buses.Add(tempEvent.bus); if (tempEvent.bus == null) { GUI.Window(i + 100, new Rect(busX, this.busY, WindowWidth, WindowHeight), DrawWindow, "-No Bus-"); } else { GUI.Window(i + 100, new Rect(busX, this.busY, WindowWidth, WindowHeight), DrawWindow, tempEvent.bus.name); } DrawCurve(new Vector2(emitterX + WindowWidth, this.emitterY), new Vector2(busX, this.busY)); this.busY += WindowYInterval; } else { //Draw a line to this bus int busNum = buses.IndexOf(tempEvent.bus); DrawCurve(new Vector2(emitterX + WindowWidth, this.emitterY), new Vector2(busX, 20 + WindowYInterval * busNum)); } this.eventY += WindowYInterval; if (addedEmitter) { this.emitterY += WindowYInterval; } } EndWindows(); }