Skip to content

Commit 1d7a07a

Browse files
committed
feat: ビルド後にSteamingAssets/Voice/~がない場合は生成するPostBuildProcessorの追加
1 parent 7bc2d73 commit 1d7a07a

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
using System.IO;
2+
using Unity.Logging;
3+
using UnityEditor;
4+
using UnityEditor.Callbacks;
5+
using UnityEngine;
6+
7+
public class PostBuildProcessor
8+
{
9+
/// <summary>
10+
/// ビルド後SteamAssetsフォルダを生成する
11+
/// </summary>
12+
/// <param name="target"></param>
13+
/// <param name="pathToBuiltProject"></param>
14+
[PostProcessBuild(1)]
15+
public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
16+
{
17+
// ビルドされたプロジェクトのディレクトリを取得
18+
var buildDirectory = Path.GetDirectoryName(pathToBuiltProject);
19+
if (string.IsNullOrEmpty(buildDirectory))
20+
{
21+
Log.Error("ビルドされたプロジェクトのディレクトリが取得できませんでした。");
22+
return;
23+
}
24+
25+
var appName = Path.GetFileNameWithoutExtension(pathToBuiltProject);
26+
27+
var streamingAssetsPath = "";
28+
29+
if (target == BuildTarget.StandaloneWindows || target == BuildTarget.StandaloneWindows64 ||
30+
target == BuildTarget.StandaloneLinux64)
31+
{
32+
// Windows および Linux の場合
33+
streamingAssetsPath = Path.Combine(buildDirectory, $"{appName}_Data", "StreamingAssets");
34+
} else if (target == BuildTarget.StandaloneOSX)
35+
{
36+
// macOS の場合
37+
streamingAssetsPath = Path.Combine(buildDirectory, $"{appName}.app", "Contents", "Resources", "Data",
38+
"StreamingAssets");
39+
} else
40+
{
41+
Debug.LogWarning("このプラットフォームはサポートされていません: " + target);
42+
return;
43+
}
44+
45+
// StreamingAssets フォルダが存在しない場合は作成
46+
if (!Directory.Exists(streamingAssetsPath))
47+
{
48+
Directory.CreateDirectory(streamingAssetsPath);
49+
}
50+
51+
// Voice/Click フォルダを作成
52+
var clickVoicePath = Path.Combine(streamingAssetsPath, "Voice", "Click");
53+
if (!Directory.Exists(clickVoicePath))
54+
{
55+
Directory.CreateDirectory(clickVoicePath);
56+
}
57+
58+
// Voice/Drag フォルダを作成(または Voice/Hold フォルダ)
59+
var dragVoicePath = Path.Combine(streamingAssetsPath, "Voice", "Drag");
60+
if (!Directory.Exists(dragVoicePath))
61+
{
62+
Directory.CreateDirectory(dragVoicePath);
63+
}
64+
65+
// ログ出力(必要に応じて)
66+
Log.Debug("ビルド後処理が完了しました。必要なフォルダを生成しました。");
67+
}
68+
}

Assets/uDesktopMascot/Editor/PostBuildProcessor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)