Last active
January 31, 2024 00:19
-
-
Save shimiu/5864179 to your computer and use it in GitHub Desktop.
Unity Editorで新規フォルダが作られたときに自動で.gitkeepを作成する。
Editorフォルダに入れて使う。
プロジェクトルートに.gitフォルダが無かったらスルー。
This file contains 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
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