Created
March 16, 2020 21:00
-
-
Save kankikuchi/a588d7e613a4e7fb6692bf35e6a10674 to your computer and use it in GitHub Desktop.
Unityエディタでプロジェクトを(初回)起動した時の判定【Unity】【エディタ拡張】
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// EditorStartupConfirmer.cs | |
// http://kan-kikuchi.hatenablog.com/entry/EditorStartupConfirmer | |
// | |
// Created by kan.kikuchi on 2020.3.5 | |
using System.IO; | |
using UnityEditor; | |
/// <summary> | |
/// Unityエディタでプロジェクトを(初回)起動したかを確認するクラス | |
/// </summary> | |
[InitializeOnLoad]//コンストラクタがエディター起動時等に呼ばれるようになる | |
public static class EditorStartupConfirmer { | |
//起動時の種類 | |
public enum StartupType { | |
First, //初回起動時 | |
NotFirst, //初回でない起動時 | |
NotStartup//起動時でない | |
} | |
//現在の起動時の種類 | |
public static StartupType CurrentStartupType { get; } | |
//初回起動判定用のフラグをEditorUserSettingsに保存する時のKey | |
private const string FIRST_STARTUP_KEY = "FIRST_STARTUP_KEY"; | |
//起動判定の使うTempファイルのパス | |
private static readonly string TMP_FILE_PATH = "Temp/unique File Name2"; | |
//================================================================================= | |
//初期化 | |
//================================================================================= | |
static EditorStartupConfirmer(){ | |
//EditorUserSettingsにフラグが設定されていなければ初回起動 | |
if (string.IsNullOrEmpty(EditorUserSettings.GetConfigValue(FIRST_STARTUP_KEY))) { | |
EditorUserSettings.SetConfigValue(FIRST_STARTUP_KEY, FIRST_STARTUP_KEY);//初回起動フラグ設定 | |
CurrentStartupType = StartupType.First; | |
return; | |
} | |
//対象のファイルがあれば起動時ではない | |
if(File.Exists(TMP_FILE_PATH)){ | |
CurrentStartupType = StartupType.NotStartup; | |
return; | |
} | |
//対象のファイルがなければ起動時 | |
CurrentStartupType = StartupType.NotFirst; | |
File.Create(TMP_FILE_PATH);//対象のファイル作成 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment