예제 #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();
        }
예제 #2
0
        public void OpenProfilerOrUseExisting()
        {
            // Note we use existing if possible to fix a bug after domain reload
            // Where calling EditorWindow.GetWindow directly causes a second window to open
            if (m_ProfilerWindow == null)
            {
#if UNITY_2021_1_OR_NEWER
                m_ProfilerWindow    = EditorWindow.GetWindow <ProfilerWindow>();
                m_CpuProfilerModule = m_ProfilerWindow.GetFrameTimeViewSampleSelectionController(ProfilerWindow.cpuModuleName);
                m_CpuProfilerModule.selectionChanged -= OnSelectionChangedInCpuProfilerModule;
                m_CpuProfilerModule.selectionChanged += OnSelectionChangedInCpuProfilerModule;
#else
                // Create new
                m_ProfilerWindow = EditorWindow.GetWindow(m_ProfilerWindowType);
#endif
            }
        }