Example #1
0
        /// <summary>
        /// コンパイルを終了した時に呼び出されます
        /// </summary>
        private static void OnFinished(object _)
        {
            var settings = CompileTimeMeasurerSettings.LoadFromEditorPrefs();

            if (!settings.IsEnable)
            {
                return;
            }

            var state = ScriptableSingleton <CompileState> .instance;

            if (!state.IsCompiling)
            {
                return;
            }

            state.StopRecord();

            var startTimeTicks   = state.StartTimeTicks;
            var elapsedTimeTicks = DateTime.Now.Ticks - startTimeTicks;
            var entities         = TimeEntities.LoadFromConfig();
            var entry            = new TimeEntry(startTimeTicks, elapsedTimeTicks);

            entities.Add(entry, settings.MaxCount);

            TimeEntities.SaveToConfig(entities);
        }
Example #2
0
        //================================================================================
        // 関数
        //================================================================================
        /// <summary>
        /// GUI を描画する時に呼び出されます
        /// </summary>
        private void OnGUI()
        {
            if (Event.current.type == EventType.Repaint)
            {
                var backgroundRect = new Rect
                                     (
                    x: 0,
                    y: 0,
                    width: EditorGUIUtility.currentViewWidth,
                    height: EditorGUIUtility.singleLineHeight
                                     );

                EditorStyles.toolbar.Draw
                (
                    position: backgroundRect,
                    isHover: false,
                    isActive: true,
                    on: true,
                    hasKeyboardFocus: false
                );
            }

            var entities = TimeEntities.LoadFromConfig();
            var settings = CompileTimeMeasurerSettings.LoadFromEditorPrefs();

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();

                if (GUILayout.Button("Settings", EditorStyles.toolbarButton))
                {
                    SettingsService.OpenUserPreferences("Preferences/UniCompileTimeMeasurer");
                }
                if (GUILayout.Button("Clear", EditorStyles.toolbarButton))
                {
                    entities.Clear();
                    TimeEntities.SaveToConfig(entities);
                    Repaint();
                }
            }

            using (var scope = new EditorGUILayout.ScrollViewScope(m_scrollPosition))
            {
                for (var i = entities.Entities.Count - 1; i >= 0; i--)
                {
                    var entry             = entities.Entities[i];
                    var dateTimeFormat    = settings.DateTimeFormat;
                    var elapsedTimeFormat = settings.ElapsedTimeFormat;
                    var elapsedTimeSuffix = settings.ElapsedTimeSuffix;

                    var dateTime = string.IsNullOrWhiteSpace(dateTimeFormat)
                                                        ? entry.DateTime.ToString()
                                                        : entry.DateTime.ToString(dateTimeFormat)
                    ;

                    var elapsedTime = string.IsNullOrWhiteSpace(elapsedTimeFormat)
                                                        ? entry.ElapsedTime.TotalSeconds.ToString()
                                                        : entry.ElapsedTime.ToString(elapsedTimeFormat)
                    ;

                    var label1 = dateTime;
                    var label2 = elapsedTime + elapsedTimeSuffix;

                    EditorGUILayout.LabelField(label1, label2);
                }

                m_scrollPosition = scope.scrollPosition;
            }
        }
        /// <summary>
        /// 設定に保存します
        /// </summary>
        public static void SaveToConfig(TimeEntities entities)
        {
            var json = JsonUtility.ToJson(entities);

            EditorUserSettings.SetConfigValue(KEY, json);
        }