Ejemplo n.º 1
0
        public void GetProfilerWindowHandle()
        {
            Profiler.BeginSample("GetProfilerWindowHandle");
#if UNITY_2021_1_OR_NEWER
            if (m_CpuProfilerModule != null)
            {
                m_CpuProfilerModule.selectionChanged -= OnSelectionChangedInCpuProfilerModule;
                m_CpuProfilerModule = null;
            }

            var windows = Resources.FindObjectsOfTypeAll <ProfilerWindow>();
            if (windows != null && windows.Length > 0)
            {
                m_ProfilerWindow = windows[0];
            }
            if (m_ProfilerWindow != null)
            {
                m_CpuProfilerModule =
                    m_ProfilerWindow.GetFrameTimeViewSampleSelectionController(ProfilerWindow.cpuModuleName);
                m_CpuProfilerModule.selectionChanged -= OnSelectionChangedInCpuProfilerModule;
                m_CpuProfilerModule.selectionChanged += OnSelectionChangedInCpuProfilerModule;

                m_ProfilerWindow.Repaint();
                m_ProfilerWindowInitialized = false;
                // wait a frame for the Profiler to get Repainted
                EditorApplication.delayCall += () => m_ProfilerWindowInitialized = true;
            }
#else
            UnityEngine.Object[] windows = Resources.FindObjectsOfTypeAll(m_ProfilerWindowType);
            if (windows != null && windows.Length > 0)
            {
                m_ProfilerWindow = (EditorWindow)windows[0];
            }
            m_ProfilerWindowInitialized = true;
#endif
            Profiler.EndSample();
        }
Ejemplo n.º 2
0
        public override void DrawDetailsView(Rect position)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar);
            ProfilerAudioView newShowDetailedAudioPane = m_ShowDetailedAudioPane;

            if (AudioDeepProfileToggle())
            {
                if (GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.Channels, "Channels", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.Channels;
                }
                if (GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.Groups, "Groups", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.Groups;
                }
                if (GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.ChannelsAndGroups, "Channels and groups", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.ChannelsAndGroups;
                }
                if (Unsupported.IsDeveloperMode() && GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.DSPGraph, "DSP Graph", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.DSPGraph;
                }
                if (Unsupported.IsDeveloperMode() && GUILayout.Toggle(newShowDetailedAudioPane == ProfilerAudioView.Clips, "Clips", EditorStyles.toolbarButton))
                {
                    newShowDetailedAudioPane = ProfilerAudioView.Clips;
                }
                if (newShowDetailedAudioPane != m_ShowDetailedAudioPane)
                {
                    m_ShowDetailedAudioPane  = newShowDetailedAudioPane;
                    m_LastAudioProfilerFrame = -1; // force update
                }
                if (m_ShowDetailedAudioPane == ProfilerAudioView.DSPGraph)
                {
                    m_ShowInactiveDSPChains = GUILayout.Toggle(m_ShowInactiveDSPChains, "Show inactive", EditorStyles.toolbarButton);
                    if (m_ShowInactiveDSPChains)
                    {
                        m_HighlightAudibleDSPChains = GUILayout.Toggle(m_HighlightAudibleDSPChains, "Highlight audible", EditorStyles.toolbarButton);
                    }
                    m_DSPGraphHorizontalLayout = GUILayout.Toggle(m_DSPGraphHorizontalLayout, "Horizontal Layout", EditorStyles.toolbarButton);
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    var graphRect = DrawAudioStatsPane(ref m_PaneScroll_AudioDSPLeft);

                    m_PaneScroll_AudioDSPRight_ScrollPos = GUI.BeginScrollView(graphRect, m_PaneScroll_AudioDSPRight_ScrollPos, new Rect(0, 0, m_PaneScroll_AudioDSPRight_Size.x, m_PaneScroll_AudioDSPRight_Size.y));

                    var clippingRect = new Rect(m_PaneScroll_AudioDSPRight_ScrollPos.x, m_PaneScroll_AudioDSPRight_ScrollPos.y, graphRect.width, graphRect.height);

                    if (m_AudioProfilerDSPView == null)
                    {
                        m_AudioProfilerDSPView = new AudioProfilerDSPView();
                    }

                    ProfilerProperty property = ProfilerWindow.CreateProperty();
                    if (property != null &&
                        property.frameDataReady)
                    {
                        using (property)
                        {
                            m_AudioProfilerDSPView.OnGUI(clippingRect, property, m_ShowInactiveDSPChains, m_HighlightAudibleDSPChains, m_DSPGraphHorizontalLayout, ref m_DSPGraphZoomFactor, ref m_PaneScroll_AudioDSPRight_ScrollPos, ref m_PaneScroll_AudioDSPRight_Size);
                        }
                    }

                    GUI.EndScrollView();
                }
                else if (m_ShowDetailedAudioPane == ProfilerAudioView.Clips)
                {
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    var treeRect = DrawAudioStatsPane(ref m_PaneScroll_AudioClips);

                    // TREE
                    if (m_AudioProfilerClipTreeViewState == null)
                    {
                        m_AudioProfilerClipTreeViewState = new AudioProfilerClipTreeViewState();
                    }

                    if (m_AudioProfilerClipViewBackend == null)
                    {
                        m_AudioProfilerClipViewBackend = new AudioProfilerClipViewBackend(m_AudioProfilerClipTreeViewState);
                    }

                    ProfilerProperty property = ProfilerWindow.CreateProperty();
                    if (property == null)
                    {
                        return;
                    }
                    if (!property.frameDataReady)
                    {
                        return;
                    }

                    using (property)
                    {
                        var currentFrame = ProfilerWindow.GetActiveVisibleFrameIndex();
                        if (currentFrame == -1 || m_LastAudioProfilerFrame != currentFrame)
                        {
                            m_LastAudioProfilerFrame = currentFrame;
                            var sourceItems = property.GetAudioProfilerClipInfo();
                            if (sourceItems != null && sourceItems.Length > 0)
                            {
                                var items = new List <AudioProfilerClipInfoWrapper>();
                                foreach (var s in sourceItems)
                                {
                                    items.Add(new AudioProfilerClipInfoWrapper(s, property.GetAudioProfilerNameByOffset(s.assetNameOffset)));
                                }
                                m_AudioProfilerClipViewBackend.SetData(items);
                                if (m_AudioProfilerClipView == null)
                                {
                                    m_AudioProfilerClipView = new AudioProfilerClipView(ProfilerWindow as EditorWindow, m_AudioProfilerClipTreeViewState);
                                    m_AudioProfilerClipView.Init(treeRect, m_AudioProfilerClipViewBackend);
                                }
                            }
                        }
                        if (m_AudioProfilerClipView != null)
                        {
                            m_AudioProfilerClipView.OnGUI(treeRect);
                        }
                    }
                }
                else
                {
                    bool resetAllAudioClipPlayCountsOnPlay = GUILayout.Toggle(AudioUtil.resetAllAudioClipPlayCountsOnPlay, "Reset play count on play", EditorStyles.toolbarButton);
                    if (resetAllAudioClipPlayCountsOnPlay != AudioUtil.resetAllAudioClipPlayCountsOnPlay)
                    {
                        AudioUtil.resetAllAudioClipPlayCountsOnPlay = resetAllAudioClipPlayCountsOnPlay;
                    }
                    if (Unsupported.IsDeveloperMode())
                    {
                        GUILayout.Space(5);
                        bool showAllGroups    = EditorPrefs.GetBool("AudioProfilerShowAllGroups");
                        bool newShowAllGroups = GUILayout.Toggle(showAllGroups, "Show all groups (dev mode only)", EditorStyles.toolbarButton);
                        if (showAllGroups != newShowAllGroups)
                        {
                            EditorPrefs.SetBool("AudioProfilerShowAllGroups", newShowAllGroups);
                        }
                    }
                    GUILayout.FlexibleSpace();
                    EditorGUILayout.EndHorizontal();

                    var treeRect = DrawAudioStatsPane(ref m_PaneScroll_AudioChannels);

                    // TREE
                    if (m_AudioProfilerGroupTreeViewState == null)
                    {
                        m_AudioProfilerGroupTreeViewState = new AudioProfilerGroupTreeViewState();
                    }

                    if (m_AudioProfilerGroupViewBackend == null)
                    {
                        m_AudioProfilerGroupViewBackend = new AudioProfilerGroupViewBackend(m_AudioProfilerGroupTreeViewState);
                    }

                    ProfilerProperty property = ProfilerWindow.CreateProperty();
                    if (property == null)
                    {
                        return;
                    }
                    if (!property.frameDataReady)
                    {
                        return;
                    }

                    using (property)
                    {
                        var currentFrame = ProfilerWindow.GetActiveVisibleFrameIndex();
                        if (currentFrame == -1 || m_LastAudioProfilerFrame != currentFrame)
                        {
                            m_LastAudioProfilerFrame = currentFrame;
                            var sourceItems = property.GetAudioProfilerGroupInfo();
                            if (sourceItems != null && sourceItems.Length > 0)
                            {
                                var items         = new List <AudioProfilerGroupInfoWrapper>();
                                var parentMapping = new Dictionary <int, AudioProfilerGroupInfo>();
                                foreach (var s in sourceItems)
                                {
                                    parentMapping.Add(s.uniqueId, s);
                                }
                                foreach (var s in sourceItems)
                                {
                                    bool isGroup = (s.flags & AudioProfilerGroupInfoHelper.AUDIOPROFILER_FLAGS_GROUP) != 0;
                                    if (m_ShowDetailedAudioPane == ProfilerAudioView.Channels && isGroup)
                                    {
                                        continue;
                                    }
                                    if (m_ShowDetailedAudioPane == ProfilerAudioView.Groups && !isGroup)
                                    {
                                        continue;
                                    }
                                    var wrapper = new AudioProfilerGroupInfoWrapper(s, property.GetAudioProfilerNameByOffset(s.assetNameOffset), property.GetAudioProfilerNameByOffset(s.objectNameOffset), m_ShowDetailedAudioPane == ProfilerAudioView.Channels);
                                    if (parentMapping.TryGetValue(s.parentId, out var parent))
                                    {
                                        wrapper.parentName = property.GetAudioProfilerNameByOffset(parent.objectNameOffset);
                                    }
                                    else
                                    {
                                        wrapper.parentName = "ROOT";
                                    }
                                    items.Add(wrapper);
                                }
                                m_AudioProfilerGroupViewBackend.SetData(items);
                                if (m_AudioProfilerGroupView == null)
                                {
                                    m_AudioProfilerGroupView = new AudioProfilerGroupView(ProfilerWindow as EditorWindow, m_AudioProfilerGroupTreeViewState);
                                    m_AudioProfilerGroupView.Init(treeRect, m_AudioProfilerGroupViewBackend);
                                }
                            }
                            else
                            {
                                var items = new List <AudioProfilerGroupInfoWrapper>();
                                m_AudioProfilerGroupViewBackend.SetData(items);
                                m_AudioProfilerGroupView = null;
                            }
                        }
                        if (m_AudioProfilerGroupView != null)
                        {
                            m_AudioProfilerGroupView.OnGUI(treeRect, m_ShowDetailedAudioPane);
                        }
                    }
                }
            }
            else
            {
                GUILayout.FlexibleSpace();
                EditorGUILayout.EndHorizontal();
                DrawDetailsViewText(position);
            }

            ProfilerWindow.Repaint();
        }