LoginSignup
4
2

More than 5 years have passed since last update.

Unityのビルドでファイル名をタイムスタンプ付きでビルドする方法

Last updated at Posted at 2018-02-05

はじめに

Unityのアプリってバージョン管理が大変ですよね。
どれが最新なのかわかりにくい。
なのでタイムスタンプをビルド後に手動で毎回入力するかバッチファイルで変更しますが、面倒なので
ビルドプレイヤーパイプラインの機能を使います。

やり方

Assets/Editor内にエディター拡張のスクリプトBuildScript.csを作成します。
フォルダが無い場合はEditorフォルダを作りそこにスクリプトを作成します。
詳しくは特殊なフォルダー名を参考にしてください。

build_01.png

スクリプト章のコードをさきほどのスクリプトに全上書きしてください。
タイムスタンプの形式はMDNのカスタム日時書式指定文字列を参照してお好みで変更してください。

スクリプト

BuildScript.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.Diagnostics;
using System;

public class BuildScript : MonoBehaviour
{

    [MenuItem("MyTools/ウィンドウズ用ビルド")]
    public static void BuildGame()
    {
        // ファイル名を取得
        string path = EditorUtility.SaveFolderPanel("Choose Location of Built Game", "", "");
        // 配列内が空欄の場合は現在のシーンをビルド
        string[] levels = new string[] { };

        var date = DateTime.Now;
        string timeStamp = date.ToString("yyyy-MM-dd-HH-mm-ss");

        // プレイヤーをビルド
        BuildPipeline.BuildPlayer(levels, path + "/sample_" + timeStamp + ".exe", BuildTarget.StandaloneWindows, BuildOptions.None);
    }
}

実行

右下のスクリプトのコンパイルの歯車アイコンのアニメーションが終わると。
メニューにMyToolsが表示されます。
ウィンドウズ用ビルドから出力先のフォルダを選択して実行します。
build_02.png

実行結果

build_03.png

4
2
0

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
4
2