示例#1
0
        void OnGUI()
        {
            Initialize();
#if UNITY_2018_1_OR_NEWER
            if (attachProfilerState != null)
            {
                ConnectionGUILayout.AttachToPlayerDropdown(attachProfilerState, EditorStyles.toolbarDropDown);
            }
#else
            // AttachProfiler
            if (m_attachProfilerUIOnGUILayOut != null && m_attachProfilerUI != null)
            {
                m_attachProfilerUIOnGUILayOut.Invoke(m_attachProfilerUI, new object[] { this });
            }
#endif
            // 接続済みPlayerのリスト表示部
            var           playerCount = EditorConnection.instance.ConnectedPlayers.Count;
            StringBuilder builder     = new StringBuilder();
            builder.AppendLine(string.Format("{0} players connected.", playerCount));
            int i = 0;
            foreach (var p in EditorConnection.instance.ConnectedPlayers)
            {
                builder.AppendLine(string.Format("[{0}] - {1} {2}", i++, p.name, p.playerId));
            }
            EditorGUILayout.HelpBox(builder.ToString(), MessageType.Info);

            // Snapshot保存先
            EditorGUILayout.BeginHorizontal(GUI.skin.box);
            GUILayout.Label("SavePath");
            GUILayout.TextField(m_savePath, GUILayout.Width(300));
            if (GUILayout.Button("Browse"))
            {
                var path = EditorUtility.OpenFolderPanel("Save Directory Path", m_savePath, "");
                if (path != "")
                {
                    m_savePath = path;
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        private void DrawMainToolbar()
        {
            GUILayout.BeginHorizontal(EditorStyles.toolbar);

            // Graph types
            Rect popupRect = GUILayoutUtility.GetRect(Styles.addArea, EditorStyles.toolbarDropDown, GUILayout.Width(Chart.kSideWidth - EditorStyles.toolbarDropDown.padding.left));

            if (EditorGUI.DropdownButton(popupRect, Styles.addArea, FocusType.Passive, EditorStyles.toolbarDropDown))
            {
                int length  = m_Charts.Length;
                var names   = new string[length];
                var enabled = new bool[length];
                for (int c = 0; c < length; ++c)
                {
                    names[c]   = L10n.Tr(((ProfilerArea)c).ToString());
                    enabled[c] = !m_Charts[c].active;
                }
                EditorUtility.DisplayCustomMenu(popupRect, names, enabled, null, AddAreaClick, null);
            }

            GUILayout.FlexibleSpace();

            // Record
            var profilerEnabled = GUILayout.Toggle(m_Recording, Styles.profilerRecord, EditorStyles.toolbarButton);

            if (profilerEnabled != m_Recording)
            {
                ProfilerDriver.enabled = profilerEnabled;
                m_Recording            = profilerEnabled;
                SessionState.SetBool(kProfilerEnabledSessionKey, profilerEnabled);
            }

            EditorGUI.BeginDisabledGroup(m_AttachProfilerState.connectedToTarget != ConnectionTarget.Editor);

            // Deep profiling
            SetProfileDeepScripts(GUILayout.Toggle(ProfilerDriver.deepProfiling, Styles.deepProfile, EditorStyles.toolbarButton));

            // Profile Editor
            ProfilerDriver.profileEditor = GUILayout.Toggle(ProfilerDriver.profileEditor, Styles.profileEditor, EditorStyles.toolbarButton);

            EditorGUI.EndDisabledGroup();

            // Engine attach
            ConnectionGUILayout.AttachToPlayerDropdown(m_AttachProfilerState, EditorStyles.toolbarDropDown);

            // Allocation callstacks
            AllocationCallstacksToolbarItem();

            GUILayout.FlexibleSpace();

            SetClearOnPlay(GUILayout.Toggle(GetClearOnPlay(), Styles.clearOnPlay, EditorStyles.toolbarButton));

            // Clear
            if (GUILayout.Button(Styles.clearData, EditorStyles.toolbarButton))
            {
                Clear();
            }

            // Load profile
            if (GUILayout.Button(Styles.loadProfilingData, EditorStyles.toolbarButton))
            {
                LoadProfilingData(Event.current.shift);
            }

            // Save profile
            using (new EditorGUI.DisabledScope(ProfilerDriver.lastFrameIndex == -1))
            {
                if (GUILayout.Button(Styles.saveProfilingData, EditorStyles.toolbarButton))
                {
                    SaveProfilingData();
                }
            }

            GUILayout.Space(5);

            FrameNavigationControls();

            GUILayout.EndHorizontal();
        }
        private void GUILayoutConnect()
        {
            EditorGUILayout.BeginHorizontal();
            var content     = new GUIContent("Connect To");
            var contentSize = EditorStyles.label.CalcSize(content);

            EditorGUILayout.LabelField(content, GUILayout.MaxWidth(contentSize.x));
            if (attachProfilerState != null)
            {
                ConnectionGUILayout.AttachToPlayerDropdown(attachProfilerState, EditorStyles.toolbarDropDown);
            }
            EditorGUI.BeginChangeCheck();
            contentSize  = EditorStyles.label.CalcSize(Styles.RecOnContent);
            mIsRecording = GUILayout.Toggle(mIsRecording, mIsRecording ? Styles.RecOnContent : Styles.RecOffContent, EditorStyles.toolbarButton, GUILayout.MaxWidth(contentSize.x + 10));
            if (EditorGUI.EndChangeCheck())
            {
                if (mIsRecording)
                {
                    SendMessage(MessageData.MessageID.RECORDING_ON);
                }
                else
                {
                    SendMessage(MessageData.MessageID.RECORDING_OFF);
                }
            }

            content     = new GUIContent(string.Format("Frame:{0,6}/", profileDataList.Count));
            contentSize = EditorStyles.label.CalcSize(content);
            EditorGUILayout.LabelField(content, GUILayout.MaxWidth(contentSize.x + 10));

            content     = new GUIContent(string.Format("Frame:{0}", frameCountMax));
            contentSize = EditorStyles.label.CalcSize(content);
            var tmp = EditorGUILayout.DelayedIntField(frameCountMax, GUILayout.MaxWidth(contentSize.x - 32));

            if (tmp > 0)
            {
                frameCountMax = tmp;
            }
            //
            // Clear
            //
            contentSize = EditorStyles.label.CalcSize(Styles.clearData);
            if (GUILayout.Button(Styles.clearData, EditorStyles.toolbarButton, GUILayout.MaxWidth(contentSize.x + 10)))
            {
                profileDataList.Clear();
                mSlider = 0;
            }

            //
            // Save File
            //
            contentSize = EditorStyles.label.CalcSize(Styles.SaveContent);
            if (GUILayout.Button(Styles.SaveContent, EditorStyles.toolbarButton, GUILayout.MaxWidth(contentSize.x + 10)))
            {
                var path = EditorUtility.SaveFilePanel(
                    "Save Profile Data as CSV",
                    "",
                    "",
                    "csv");
                if (path.Length != 0)
                {
                    using (StreamWriter sw = new StreamWriter(path))
                    {
                        sw.WriteLine(ProfileData.GetCSVHeader());
                        foreach (var d in profileDataList)
                        {
                            sw.WriteLine(d.GetCSVBody());
                        }
                        sw.Close();
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            contentSize   = EditorStyles.label.CalcSize(Styles.statsContent);
            mEnabledStats = GUILayout.Toggle(mEnabledStats, Styles.statsContent, EditorStyles.toolbarButton, GUILayout.MaxWidth(contentSize.x + 10));
            if (EditorGUI.EndChangeCheck())
            {
                SendMessage(mEnabledStats ? MessageData.MessageID.STATS_ON : MessageData.MessageID.STATS_OFF);
            }
            EditorGUILayout.EndHorizontal();

            var           playerCount = EditorConnection.instance.ConnectedPlayers.Count;
            StringBuilder builder     = new StringBuilder();

            builder.AppendLine(string.Format("{0} players connected.", playerCount));
            int i = 0;

            foreach (var p in EditorConnection.instance.ConnectedPlayers)
            {
                builder.AppendLine(string.Format("[{0}] - {1} {2}", i++, p.name, p.playerId));
            }
            EditorGUILayout.HelpBox(builder.ToString(), MessageType.Info);
        }