Last active
August 24, 2024 11:56
-
-
Save fumobox/1163b4e3ebb08d1c508b605f5d3245fe to your computer and use it in GitHub Desktop.
UnityのProjectRootに置いて実行すると自動で必要なフォルダやgitignoreを生成するスクリプト
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
| import os | |
| import subprocess | |
| # プロジェクトのルートディレクトリを取得 | |
| project_root = os.path.dirname(os.path.abspath(__file__)) | |
| # 作成したいフォルダ構造 | |
| folders_to_create = [ | |
| "Assets/Scripts", | |
| "Assets/Scripts/Editor", | |
| "Assets/Scripts/Runtime", | |
| "Assets/Prefabs", | |
| "Assets/Materials", | |
| "Assets/Textures", | |
| "Assets/Animations", | |
| "Assets/Scenes", | |
| "Assets/Audio" | |
| ] | |
| # .gitignoreの内容 | |
| gitignore_content = """ | |
| # This .gitignore file should be placed at the root of your Unity project directory | |
| # | |
| # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore | |
| # | |
| /[Ll]ibrary/ | |
| /[Tt]emp/ | |
| /[Oo]bj/ | |
| /[Bb]uild/ | |
| /[Bb]uilds/ | |
| /[Ll]ogs/ | |
| /[Uu]ser[Ss]ettings/ | |
| # MemoryCaptures can get excessive in size. | |
| # They also could contain extremely sensitive data | |
| /[Mm]emoryCaptures/ | |
| # Recordings can get excessive in size | |
| /[Rr]ecordings/ | |
| # Uncomment this line if you wish to ignore the asset store tools plugin | |
| # /[Aa]ssets/AssetStoreTools* | |
| # Autogenerated Jetbrains Rider plugin | |
| /[Aa]ssets/Plugins/Editor/JetBrains* | |
| # Visual Studio cache directory | |
| .vs/ | |
| # Gradle cache directory | |
| .gradle/ | |
| # Autogenerated VS/MD/Consulo solution and project files | |
| ExportedObj/ | |
| .consulo/ | |
| *.csproj | |
| *.unityproj | |
| *.sln | |
| *.suo | |
| *.tmp | |
| *.user | |
| *.userprefs | |
| *.pidb | |
| *.booproj | |
| *.svd | |
| *.pdb | |
| *.mdb | |
| *.opendb | |
| *.VC.db | |
| # Unity3D generated meta files | |
| *.pidb.meta | |
| *.pdb.meta | |
| *.mdb.meta | |
| # Unity3D generated file on crash reports | |
| sysinfo.txt | |
| # Builds | |
| *.apk | |
| *.aab | |
| *.unitypackage | |
| *.app | |
| # Crashlytics generated file | |
| crashlytics-build.properties | |
| # Packed Addressables | |
| /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* | |
| # Temporary auto-generated Android Assets | |
| /[Aa]ssets/[Ss]treamingAssets/aa.meta | |
| /[Aa]ssets/[Ss]treamingAssets/aa/* | |
| """ | |
| def create_folders(root, folders): | |
| for folder in folders: | |
| path = os.path.join(root, folder) | |
| if not os.path.exists(path): | |
| os.makedirs(path) | |
| print(f"Created folder: {path}") | |
| else: | |
| print(f"Folder already exists: {path}") | |
| # Assets/Scripts フォルダには .gitkeep を生成しない | |
| if folder != "Assets/Scripts": | |
| gitkeep_path = os.path.join(path, ".gitkeep") | |
| if not os.path.exists(gitkeep_path): | |
| with open(gitkeep_path, "w") as gitkeep_file: | |
| gitkeep_file.write("") | |
| print(f"Created .gitkeep file in: {path}") | |
| def create_gitignore(root, content): | |
| gitignore_path = os.path.join(root, ".gitignore") | |
| if not os.path.exists(gitignore_path): | |
| with open(gitignore_path, "w") as gitignore_file: | |
| gitignore_file.write(content.strip()) | |
| print(f"Created .gitignore file at: {gitignore_path}") | |
| else: | |
| print(".gitignore file already exists.") | |
| def initialize_git_repo(root): | |
| try: | |
| # git init | |
| subprocess.run(["git", "init"], cwd=root, check=True) | |
| print("Initialized empty Git repository.") | |
| # git add . | |
| # subprocess.run(["git", "add", "."], cwd=root, check=True) | |
| # print("Added files to Git staging area.") | |
| # git commit -m "Initial commit" | |
| # subprocess.run(["git", "commit", "-m", "Initial commit"], cwd=root, check=True) | |
| # print("Created initial commit.") | |
| except subprocess.CalledProcessError as e: | |
| print(f"An error occurred: {e}") | |
| if __name__ == "__main__": | |
| create_folders(project_root, folders_to_create) | |
| create_gitignore(project_root, gitignore_content) | |
| initialize_git_repo(project_root) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment