Skip to content

Instantly share code, notes, and snippets.

@shimiu
Last active January 31, 2024 00:19
Show Gist options
  • Save shimiu/5864179 to your computer and use it in GitHub Desktop.
Save shimiu/5864179 to your computer and use it in GitHub Desktop.
Unity Editorで新規フォルダが作られたときに自動で.gitkeepを作成する。 Editorフォルダに入れて使う。 プロジェクトルートに.gitフォルダが無かったらスルー。
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.IO;
/// <summary>
/// 新規フォルダ作成時に.gitkeepを自動作成
/// </summary>
public class GitkeepMaker : AssetPostprocessor
{
private readonly static string folderKeeperName = ".gitkeep";
public static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetsPath)
{
if (!Directory.Exists(".git")) return;
foreach (string path in importedAssets) {
if (Directory.Exists(path)) {
string folderKeeperPath = path + "/" + folderKeeperName;
if ( !File.Exists(folderKeeperPath) ) {
File.Create(folderKeeperPath).Close();
Debug.Log(folderKeeperPath + " created");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment