LoginSignup
14
7

More than 5 years have passed since last update.

Unityプロジェクトのフォルダ階層を簡単に準備できる機能

Posted at

動機

プロジェクトによってフォルダ構成は基本的に決まっていると思います。毎度作り直す手間を惜しんで拡張機能を作ってみました。
また1つのプロジェクトに複数のゲームを含める企画などにも使えるかもしれません(そっちが本来の用途でした)。
今回のフォルダ構成はUnityフォルダ構成のルールについてを参考にしました。

実装

using System.IO;
using UnityEngine;
using UnityEditor;

public static class CreateProjectFolder
{
    // フォルダー名の一覧
    private static readonly string[] folders = new string[]
    {
            "Scenes",
            "Prefabs",
            "Scripts",
            "Animations",
            "Materials",
            "PhysicsMaterials",
            "Fonts",
            "Textures",
            "Audios",
            "Resources",
            "Editor",
            "Plugins",
    };

    [MenuItem("Tools/Create Project Folder")]
    private static void Excute()
    {
        // 作成先となるフォルダーのパスを取得
        var target = EditorUtility.OpenFolderPanel("Select Project Folder", Application.dataPath, "Project");

        // プロジェクト以下にフォルダを作成
        foreach (var folder in folders)
        {
            var path = target + "/" + folder;
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
        }

        // エディターの更新
        AssetDatabase.Refresh();
    }
}
14
7
2

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
14
7