131 lines
5.5 KiB
C#
131 lines
5.5 KiB
C#
using System.Linq;
|
|
using OCES.Audio;
|
|
using OCES.Haptic;
|
|
using UnityEngine;
|
|
using UnityEditor;
|
|
|
|
namespace OCES.Editor
|
|
{
|
|
public class AssetBundleBuilderWindow : EditorWindow
|
|
{
|
|
bool m_buildAudio = true;
|
|
bool m_buildHaptic = true;
|
|
int m_targetIndex;
|
|
string m_audioBundleSourcePath;
|
|
string m_hapticBundleSourcePath;
|
|
|
|
string m_log = "";
|
|
Vector2 m_scrollPos;
|
|
|
|
// Settings 资源路径
|
|
const string k_audioSettingsPath = "Assets/Settings/AudioExtendSettings.asset";
|
|
const string k_hapticSettingsPath = "Assets/Settings/HapticSettings.asset";
|
|
|
|
static readonly (BuildTarget target, string label)[] s_platforms =
|
|
{
|
|
(BuildTarget.Android, "Android"),
|
|
(BuildTarget.iOS, "iOS"),
|
|
(BuildTarget.StandaloneOSX, "macOS"),
|
|
(BuildTarget.StandaloneWindows64, "Windows (x64)"),
|
|
(BuildTarget.StandaloneLinux64, "Linux (x64)"),
|
|
};
|
|
|
|
static readonly string[] s_platformLabels = s_platforms.Select(p => p.label).ToArray();
|
|
|
|
[MenuItem("Tools/OCES/Asset Bundle Builder")]
|
|
public static void ShowWindow()
|
|
{
|
|
AssetBundleBuilderWindow window = GetWindow<AssetBundleBuilderWindow>(
|
|
false, "Bundle Builder", true);
|
|
window.minSize = new Vector2(360, 400);
|
|
window.Show();
|
|
}
|
|
|
|
void OnEnable()
|
|
{
|
|
// 默认选中当前 Player 平台
|
|
BuildTarget current = EditorUserBuildSettings.activeBuildTarget;
|
|
for (int i = 0; i < s_platforms.Length; i++)
|
|
{
|
|
if (s_platforms[i].target != current)
|
|
continue;
|
|
this.m_targetIndex = i;
|
|
return;
|
|
}
|
|
// 兜底:Android
|
|
this.m_targetIndex = 13;
|
|
}
|
|
|
|
void OnGUI()
|
|
{
|
|
GUILayout.Space(10);
|
|
|
|
// ── Bundle 选择 ──
|
|
EditorGUILayout.LabelField("Bundles to Build", EditorStyles.boldLabel);
|
|
this.m_buildAudio = EditorGUILayout.ToggleLeft("Audio Bundle (audios.ab)", this.m_buildAudio);
|
|
this.m_buildHaptic = EditorGUILayout.ToggleLeft("Haptic Bundle (haptic.ab)", this.m_buildHaptic);
|
|
|
|
GUILayout.Space(10);
|
|
|
|
// ── 平台选择 ──
|
|
EditorGUILayout.LabelField("Target Platform", EditorStyles.boldLabel);
|
|
this.m_targetIndex = EditorGUILayout.Popup(this.m_targetIndex, s_platformLabels);
|
|
|
|
// ── 输出路径预览 ──
|
|
AudioExtendSettings audioSettings =
|
|
AssetDatabase.LoadAssetAtPath<AudioExtendSettings>(k_audioSettingsPath);
|
|
HapticSettings hapticSettings =
|
|
AssetDatabase.LoadAssetAtPath<HapticSettings>(k_hapticSettingsPath);
|
|
|
|
if (audioSettings && this.m_buildAudio)
|
|
EditorGUILayout.LabelField(
|
|
$" Audio → {Application.streamingAssetsPath}/{audioSettings.audioBundlePath}",
|
|
EditorStyles.miniLabel);
|
|
|
|
if (hapticSettings && this.m_buildHaptic)
|
|
EditorGUILayout.LabelField(
|
|
$" Haptic → {Application.streamingAssetsPath}/{hapticSettings.hapticBundlePath}",
|
|
EditorStyles.miniLabel);
|
|
|
|
if (!audioSettings && !hapticSettings)
|
|
EditorGUILayout.HelpBox(
|
|
$"未找到 Settings 资产。\n 请初始化对应系统。",
|
|
MessageType.Warning);
|
|
|
|
GUILayout.Space(10);
|
|
|
|
// ── 构建按钮 ──
|
|
bool canBuild = (this.m_buildAudio || this.m_buildHaptic)
|
|
&& (audioSettings || !this.m_buildAudio)
|
|
&& (hapticSettings || !this.m_buildHaptic);
|
|
|
|
EditorGUI.BeginDisabledGroup(!canBuild);
|
|
if (GUILayout.Button("Build", GUILayout.Height(32)))
|
|
{
|
|
string result = AssetBundleBuilder.BuildBundles(this.m_buildAudio,
|
|
audioSettings ? audioSettings.audioBundlePath : "", this.m_buildHaptic,
|
|
hapticSettings != null ? hapticSettings.hapticBundlePath : "",
|
|
s_platforms[this.m_targetIndex].target);
|
|
this.m_log += result + "\n";
|
|
}
|
|
EditorGUI.EndDisabledGroup();
|
|
|
|
GUILayout.Space(10);
|
|
|
|
// ── 日志区 ──
|
|
EditorGUILayout.LabelField("Build Log", EditorStyles.boldLabel);
|
|
this.m_scrollPos = EditorGUILayout.BeginScrollView(this.m_scrollPos,
|
|
GUILayout.ExpandHeight(true));
|
|
EditorGUILayout.TextArea(this.m_log,
|
|
GUILayout.ExpandHeight(true));
|
|
EditorGUILayout.EndScrollView();
|
|
|
|
// 底部清空日志按钮
|
|
if (string.IsNullOrEmpty(this.m_log))
|
|
return;
|
|
GUILayout.Space(4);
|
|
if (GUILayout.Button("Clear Log", GUILayout.Width(80)))
|
|
this.m_log = "";
|
|
}
|
|
}
|
|
} |