private void OnEnable()
        {
            if (m_AttachToPlayerState == null)
            {
                m_AttachToPlayerState = PlayerConnectionGUIUtility.GetConnectionState(this);
            }

            wantsLessLayoutEvents    = true;
            autoRepaintOnSceneChange = true;
            s_FrameDebuggers.Add(this);
            EditorApplication.pauseStateChanged    += OnPauseStateChanged;
            EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
            m_RepaintFrames = k_NeedToRepaintFrames;
        }
Exemple #2
0
 void OnEnable()
 {
     state = PlayerConnectionGUIUtility.GetConnectionState(this);
     EditorConnection.instance.Initialize();
     EditorConnection.instance.Register(RuntimeDebuggerOpenXRFeature.kPlayerToEditorSendDebuggerOutput, DebuggerState.OnMessageEvent);
 }
            protected override VisualElement CreateView()
            {
                VisualTreeAsset memoryModuleViewTree = EditorGUIUtility.Load(ResourcePaths.MemoryModuleUxmlPath) as VisualTreeAsset;

                var root = memoryModuleViewTree.CloneTree();

                m_UIState = new UIState();

                var toolbar = root.Q("memory-module__toolbar");

                m_UIState.DetailedToolbarSection = toolbar.Q("memory-module__toolbar__detailed-controls");

                m_UIState.DetailedMenu      = toolbar.Q <UnityEngine.UIElements.Button>("memory-module__toolbar__detail-view-menu");
                m_UIState.DetailedMenuLabel = m_UIState.DetailedMenu.Q <Label>("memory-module__toolbar__detail-view-menu__label");
                var menu = new GenericMenu();

                menu.AddItem(new GUIContent("Simple"), false, () => ViewChanged(ProfilerMemoryView.Simple));
                menu.AddItem(new GUIContent("Detailed"), false, () => ViewChanged(ProfilerMemoryView.Detailed));
                m_UIState.DetailedMenu.clicked += () =>
                {
                    menu.DropDown(UIElementsHelper.GetRect(m_UIState.DetailedMenu));
                };

                var takeCapture = toolbar.Q <UnityEngine.UIElements.Button>("memory-module__toolbar__take-sample-button");

                takeCapture.clicked += () => m_MemoryModule.RefreshMemoryData();

                var gatherObjectReferencesToggle = toolbar.Q <Toggle>("memory-module__toolbar__gather-references-toggle");

                gatherObjectReferencesToggle.RegisterValueChangedCallback((evt) => m_MemoryModule.m_GatherObjectReferences = evt.newValue);
                gatherObjectReferencesToggle.SetValueWithoutNotify(m_MemoryModule.m_GatherObjectReferences);

                m_UIState.InstallPackageButton = toolbar.Q <UnityEngine.UIElements.Button>("memory-module__toolbar__install-package-button");

                // in the main code base, this button offers to install the memory profiler package, here it is swapped to be one that opens it.
                if (m_InitiatedPackageSearchQuery)
                {
                    m_UIState.InstallPackageButton.schedule.Execute(CheckPackageAvailabilityStatus).Until(() => !m_InitiatedPackageSearchQuery);
                }
                m_UIState.InstallPackageButton.clicked += PackageInstallButtonClicked;
                UpdatePackageInstallButton();

                m_UIState.EditorWarningLabel = toolbar.Q("memory-module__toolbar__editor-warning");

                m_ConnectionState = PlayerConnectionGUIUtility.GetConnectionState(ProfilerWindow, ConnectionChanged);
                UIElementsHelper.SetVisibility(m_UIState.EditorWarningLabel, m_ConnectionState.connectionName == "Editor");

                m_UIState.ViewArea = root.Q("memory-module__view-area");

                m_UIState.SimpleView     = m_UIState.ViewArea.Q("memory-module__simple-area");
                m_UIState.CounterBasedUI = m_UIState.SimpleView.Q("memory-module__simple-area__counter-based-ui");

                var normalizedToggle = m_UIState.CounterBasedUI.Q <Toggle>("memory-module__simple-area__breakdown__normalized-toggle");

                normalizedToggle.value = m_MemoryModule.m_Normalized;
                normalizedToggle.RegisterValueChangedCallback((evt) =>
                {
                    m_MemoryModule.m_Normalized = evt.newValue;
                    UpdateContent(ProfilerWindow.selectedFrameIndex);
                });

                m_UIState.TopLevelBreakdown = m_UIState.CounterBasedUI.Q <MemoryUsageBreakdown>("memory-usage-breakdown__top-level");
                m_UIState.TopLevelBreakdown.Setup();
                m_UIState.Breakdown = m_UIState.CounterBasedUI.Q <MemoryUsageBreakdown>("memory-usage-breakdown");
                m_UIState.Breakdown.Setup();

                var m_ObjectStatsTable = m_UIState.CounterBasedUI.Q("memory-usage-breakdown__object-stats_list");

                SetupObjectTableRow(m_ObjectStatsTable.Q("memory-usage-breakdown__object-stats__textures"), ref m_UIState.TexturesRow, Content.Textures);
                SetupObjectTableRow(m_ObjectStatsTable.Q("memory-usage-breakdown__object-stats__meshes"), ref m_UIState.MeshesRow, Content.Meshes);
                SetupObjectTableRow(m_ObjectStatsTable.Q("memory-usage-breakdown__object-stats__materials"), ref m_UIState.MaterialsRow, Content.Materials);
                SetupObjectTableRow(m_ObjectStatsTable.Q("memory-usage-breakdown__object-stats__animation-clips"), ref m_UIState.AnimationClipsRow, Content.AnimationClips);
                SetupObjectTableRow(m_ObjectStatsTable.Q("memory-usage-breakdown__object-stats__assets"), ref m_UIState.AssetsRow, Content.Assets, true);
                SetupObjectTableRow(m_ObjectStatsTable.Q("memory-usage-breakdown__object-stats__game-objects"), ref m_UIState.GameObjectsRow, Content.GameObjects, true);
                SetupObjectTableRow(m_ObjectStatsTable.Q("memory-usage-breakdown__object-stats__scene-objects"), ref m_UIState.SceneObjectsRow, Content.SceneObjects, true);

                var m_GCAllocExtraRow = m_UIState.CounterBasedUI.Q <VisualElement>("memory-usage-breakdown__object-stats__gc");

                SetupObjectTableRow(m_GCAllocExtraRow, ref m_UIState.GCAllocRow, Content.GCAlloc);

                m_UIState.Text = m_UIState.SimpleView.Q <TextField>("memory-module__simple-area__label");

                var detailedView = m_UIState.ViewArea.Q <IMGUIContainer>("memory-module__detaile-snapshot-area");// new IMGUIContainer();

                detailedView.onGUIHandler = () => m_MemoryModule.DrawDetailedMemoryPane();
                m_UIState.DetailedView    = detailedView;

                m_UIState.NoDataView = m_UIState.ViewArea.Q("memory-module__no-frame-data__area");
                m_UIState.NoDataView.Q <Label>("memory-module__no-frame-data__label").text = Content.NoFrameDataAvailable;

                ViewChanged(m_MemoryModule.m_ShowDetailedMemoryPane);
                return(root);
            }