LoginSignup
127
48

More than 5 years have passed since last update.

Unityプログラマのための合法的休憩エディタ

Posted at

休みたい

日本人の平均勤務時間は8時間。その間ずーっと集中なんてできないですよね?
あーちょっとサボってTwitterみたい!
スタミナが溜まるころだしデイリーミッション消化したい!
そんなちょっとした合法的休憩時間を得るためだけのUnity Editorを作りました。

キャプチャ.PNG
なんかの作業を待ってるかのように見せかけ、合法的に一息つけるエディタです。

使い方

キャプチャ2.PNG

  1. totalのつまみを動かし休みたい時間を設定する
  2. launchを押すとプログレスバーが現れ、設定した時間分動いて消える

簡単2ステップ!

それ以外のプロパティはすべて見せかけだけのものです。
ちなみに、1分周期でバーは満タンになります。
リセットボタンを押すと途中でもバーを消すことができます。

ソースコード

書いてある文字列は適当なので、いろいろ改造してうまいことばれないようにしてください。

FindingPizza.cs
using System.Collections.Generic;
using UnityEngine;

#if UNITY_EDITOR
using UnityEditor;

[CanEditMultipleObjects]
public class FindingPizza : EditorWindow
{
    string path = "";
    float progress = 1;     //進捗状況 0~1
    float  totalTime = 1;   // min
    float dummyNum = 1;

    float timer;
    int idx = 0;
    float turnupTime = 1;
    float fullConter = 0;

    bool[] dummyToggles = new bool[5];


    List<string> infos = new List<string>() {
        "the process of adapting to something."
        , "ordering my lunch"
        , "finding mr.right. the process is up to population density"
         , "Transrating"

    };

    [MenuItem("Window/Custom/FindingPizza")]
    static void Create()
    {
        UnityEditor.EditorWindow window = GetWindow(typeof(FindingPizza));
        window.Show();
    }


    void OnGUI()
    {
        //無意味なフォルダ指定
        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Folder Path", GUILayout.MaxWidth(100));
        GUILayout.TextField(path);
        if (GUILayout.Button("...", GUILayout.MaxWidth(30)))
        {
            path = EditorUtility.OpenFolderPanel("Folder Path", path, "");

        }
        EditorGUILayout.EndHorizontal();

        //パーセントとか書いてるけど単位は分
        totalTime = EditorGUILayout.Slider("total (%)", totalTime, 1, 200);
        UIBar(totalTime / 200.0f, "total");

        //何の意味もない値
        dummyNum = EditorGUILayout.Slider("accuracy", dummyNum, 1, 100);
        UIBar(dummyNum / 100, "accuracy (secure)");

        //必要のないToDoリスト
        dummyToggles[0] = GUILayout.Toggle(dummyToggles[0], "Eat breakfast.");
        dummyToggles[1] = GUILayout.Toggle(dummyToggles[1], "Walk around without f**kin' phone.");
        dummyToggles[2] = GUILayout.Toggle(dummyToggles[2], "Call to your mom");
        dummyToggles[3] = GUILayout.Toggle(dummyToggles[3], "See a baby cat.");
        dummyToggles[4] = GUILayout.Toggle(dummyToggles[4], "Love yourself.");

        if (progress < 1)
        {
            var temp = string.Format(" {0} / {1}", fullConter, totalTime );
            EditorUtility.DisplayProgressBar("Optimization" + temp, infos[idx] , progress); //プログレスバー表示
            Progress();
        }


        if (GUILayout.Button("launch"))
        {
            progress = 0;
            timer = 0;
            fullConter = 0;
            turnupTime = fullConter + 1 < totalTime ? 1 : totalTime - fullConter;
        }
        if (GUILayout.Button("reset"))
        {
            progress = 1;
            ResetProgress();
        }


    }

    void ResetProgress()
    {
        //プログレスバー削除
        EditorUtility.ClearProgressBar();       
    }

        //ここでプログレスバーが進む処理
    void Progress() {

        timer += Time.deltaTime;
        progress = timer /(turnupTime * 60f);

        idx = Mathf.FloorToInt(timer/60) % infos.Count;
        //バーが満タンになったら設定時間が過ぎたかをチェック
        if (progress >= 1) {
            fullConter += turnupTime;
            if (fullConter >= totalTime)
            {
                ResetProgress();
            }
            else
            {
                turnupTime = fullConter + 1 < totalTime ? 1 : totalTime - fullConter;
                progress = 0;
                timer = 0;
            }
        }
    }

    void OnInspectorUpdate()
    {
        Repaint();
    }

    void UIBar(float value, string label)
    {
        Rect rect = GUILayoutUtility.GetRect(18, 18, "TextField");
        EditorGUI.ProgressBar(rect, value, label);
        EditorGUILayout.Space();
    }
}
#endif

休める

適度な休憩を挟んで楽しく働きましょう!
レッツエンジョイライフ~

127
48
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
127
48