Ejemplo n.º 1
0
        void OnGUI()
        {
            sectionRect.x      = 0;
            sectionRect.y      = 0;
            sectionRect.width  = Screen.width;
            sectionRect.height = Screen.height;

            GUI.DrawTexture(sectionRect, sectionTexture);

            bool   isRunning             = EditorPrefs.GetBool("TimeTools." + Application.productName + ".ChronometerIsRunning", false);
            bool   clear                 = EditorPrefs.GetBool("TimeTools." + Application.productName + ".ChronometerIsClear", true);
            double chronometerTimeRemove = double.Parse(EditorPrefs.GetString("TimeTools." + Application.productName + ".ChronometerTimeRemove", "0"));
            string lbl = string.Empty;
            string btn = string.Empty;

            chronometerTime = EditorApplication.timeSinceStartup - chronometerTimeRemove;

            if (clear)
            {
                lbl = "00:00:00";
                btn = "Start";
            }
            else if (isRunning)
            {
                lbl = TimeToolsUtils.TimeFormater(chronometerTime);
                btn = "Pause";
            }
            else
            {
                lbl = TimeToolsUtils.TimeFormater(chronometerTimePause);
                btn = "Continue";
            }

            GUILayout.Label(lbl, skin.GetStyle("Chronometer"));


            EditorGUILayout.BeginHorizontal();
            GUI.color = (isRunning) ? Color.yellow : GUI.color = Color.green;
            if (GUILayout.Button(btn, EditorStyles.miniButtonLeft, GUILayout.MaxWidth(Screen.width / 2)))
            {
                if (isRunning)
                {
                    EditorPrefs.SetBool("TimeTools." + Application.productName + ".ChronometerIsRunning", false);
                    chronometerTimePause = chronometerTime;
                }
                else
                {
                    EditorPrefs.SetBool("TimeTools." + Application.productName + ".ChronometerIsRunning", true);
                    if (clear)
                    {
                        chronometerTimeRemove = EditorApplication.timeSinceStartup;
                        EditorPrefs.SetString("TimeTools." + Application.productName + ".ChronometerTimeRemove", chronometerTimeRemove.ToString());
                        chronometerTimePause = 0;
                        EditorPrefs.SetBool("TimeTools." + Application.productName + ".ChronometerIsClear", false);
                    }
                    else
                    {
                        chronometerTimeRemove += chronometerTime - chronometerTimePause;
                        EditorPrefs.SetString("TimeTools." + Application.productName + ".ChronometerTimeRemove", chronometerTimeRemove.ToString());
                    }
                }
            }
            GUI.color = Color.red;
            if (GUILayout.Button("Stop", EditorStyles.miniButtonRight, GUILayout.MaxWidth(Screen.width / 2)))
            {
                ClearData();
            }

            EditorGUILayout.EndHorizontal();
            GUI.color = Color.white;

            Repaint();
        }
Ejemplo n.º 2
0
        void OnGUI()
        {
            sectionRect.x      = 0;
            sectionRect.y      = 0;
            sectionRect.width  = Screen.width;
            sectionRect.height = Screen.height;

            GUI.DrawTexture(sectionRect, sectionTexture);



            bool   isRunning       = EditorPrefs.GetBool("TimeTools." + Application.productName + ".TimerIsRunning", false);
            bool   clear           = EditorPrefs.GetBool("TimeTools." + Application.productName + ".TimerIsClear", true);
            double timerTimeRemove = double.Parse(EditorPrefs.GetString("TimeTools." + Application.productName + ".TimerTimeRemove", "0"));
            string lbl             = string.Empty;
            string btn             = string.Empty;
            float  percent         = 0;

            timerTime = timeToWait - timerTimeRemove - (EditorApplication.timeSinceStartup - startCoundownTime);

            if (clear)
            {
                lbl = "00:00:00";
                btn = "Start";
            }
            else if (isRunning)
            {
                lbl     = TimeToolsUtils.TimeFormater(timerTime);
                btn     = "Pause";
                percent = Mathf.FloorToInt((float)(timerTime / timeToWait * 100));
            }
            else
            {
                lbl     = TimeToolsUtils.TimeFormater(timerTimePause);
                btn     = "Continue";
                percent = Mathf.FloorToInt((float)(timerTimePause / timeToWait * 100));
            }


            EditorGUI.ProgressBar(new Rect(0, 0, position.width, 15), percent / 100, percent.ToString() + "%");
            GUILayout.Label(lbl, skin.GetStyle("Timer"));

            GUI.skin = null;


            EditorGUILayout.BeginHorizontal();
            hours   = EditorGUILayout.IntField(hours);
            minutes = EditorGUILayout.IntField(minutes);
            seconds = EditorGUILayout.IntField(seconds);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUI.color = (isRunning) ? Color.yellow : GUI.color = Color.green;
            if (GUILayout.Button(btn, EditorStyles.miniButtonLeft, GUILayout.MaxWidth(Screen.width / 2)))
            {
                if (!isRunning)
                {
                    timeToWait = TimeToolsUtils.ToSeconds(hours, minutes, seconds);
                    if (timeToWait > 0)
                    {
                        EditorPrefs.SetBool("TimeTools." + Application.productName + ".TimerIsRunning", true);
                        if (clear)//start
                        {
                            startCoundownTime = EditorApplication.timeSinceStartup;
                            timerTimePause    = 0;
                            EditorPrefs.SetString("TimeTools." + Application.productName + ".TimerTimeRemove", "0");
                            EditorPrefs.SetBool("TimeTools." + Application.productName + ".TimerIsClear", false);
                        }
                        else//continue
                        {
                            timerTimeRemove += timerTime - timerTimePause;
                            EditorPrefs.SetString("TimeTools." + Application.productName + ".TimerTimeRemove", timerTimeRemove.ToString());
                        }
                    }
                }
                else//pause
                {
                    EditorPrefs.SetBool("TimeTools." + Application.productName + ".TimerIsRunning", false);
                    timerTimePause = timerTime;
                }
            }
            GUI.color = Color.red;
            if (GUILayout.Button("Stop", EditorStyles.miniButtonRight, GUILayout.MaxWidth(Screen.width / 2)))
            {
                ClearData();
            }
            EditorGUILayout.EndHorizontal();
            GUI.color = Color.white;

            Repaint();
        }