- One empty scene; App builds the canvas, safe-area layout and a shared 5x6 Grid in code. Pages (Intro, Main, Choose, Play, Account, Settings) replace 5 scenes, 5 prefabs and the per-cell spawner/display components. - Packs: the game reads Rhyculator/package/ (with All files access) or the app folder, like a plugged-in USB stick. Zips stay where they are and are extracted to a cache keyed by name/size/mtime; folders are read directly. Scans run every second on a background thread. Old songs/ imports and inbox zips are migrated automatically. - Download packs by 8-char code from the new pack website, or via rhyculator://pack/<code> links; opened/shared zips go into the package folder. - Play: pause/resume/retry, auto-pause on background, combo and progress bar; judging and scoring unchanged. Choose page fits 9:16 screens; empty state, pack delete. Android back key handled everywhere. - Slimming: removed TextMesh Pro, unused 2D/Timeline/VisualScripting/etc. packages and modules, scene template, unused sprites; menu theme wav (20MB) -> ogg (2.3MB). Build profile replaced by explicit settings in BuildAndroid. - Tests: PackLibrary/PackReader/migration/serializer tests (39 passing). Co-Authored-By: Claude Opus 5.5 <[email protected]>
79 lines
3.7 KiB
C#
79 lines
3.7 KiB
C#
using System.IO;
|
||
using System.Linq;
|
||
using UnityEditor;
|
||
using UnityEditor.Build.Reporting;
|
||
using UnityEditor.SceneManagement;
|
||
using UnityEngine;
|
||
using UnityEngine.Rendering.Universal;
|
||
|
||
// 指令列打包(產出 Build/Rhyculator.apk,並複製一份到專案根目錄 Rhyculator.apk):
|
||
// Unity.exe -batchmode -quit -projectPath <path> -buildTarget Android -executeMethod BuildAndroid.Build -logFile build.log
|
||
// 加上 -development 打包 Development Build(可看 log、連 Profiler)
|
||
public static class BuildAndroid
|
||
{
|
||
public const string ScenePath = "Assets/Scenes/Main.unity";
|
||
public const string OutputPath = "Build/Rhyculator.apk";
|
||
public const string SideloadPath = "Rhyculator.apk";
|
||
|
||
[MenuItem("Build/Android APK")]
|
||
public static void Build()
|
||
{
|
||
EnsureScene();
|
||
ApplyPlayerSettings();
|
||
|
||
bool dev = System.Environment.GetCommandLineArgs().Contains("-development");
|
||
var report = BuildPipeline.BuildPlayer(new BuildPlayerOptions
|
||
{
|
||
scenes = new[] { ScenePath },
|
||
target = BuildTarget.Android,
|
||
targetGroup = BuildTargetGroup.Android,
|
||
locationPathName = OutputPath,
|
||
options = dev ? BuildOptions.Development : BuildOptions.None,
|
||
});
|
||
|
||
if (report.summary.result == BuildResult.Succeeded)
|
||
File.Copy(OutputPath, SideloadPath, true);
|
||
|
||
Debug.Log($"[BuildAndroid] {report.summary.result}, {report.summary.totalSize / 1024 / 1024} MB, errors={report.summary.totalErrors}");
|
||
if (Application.isBatchMode)
|
||
EditorApplication.Exit(report.summary.result == BuildResult.Succeeded ? 0 : 1);
|
||
}
|
||
|
||
// 整個遊戲只有一個場景:一台清成黑色的攝影機,其他全部由 App 在執行時建立
|
||
[MenuItem("Build/Create Main Scene")]
|
||
public static void EnsureScene()
|
||
{
|
||
if (!File.Exists(ScenePath))
|
||
{
|
||
Directory.CreateDirectory(Path.GetDirectoryName(ScenePath));
|
||
var scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
|
||
var cam = new GameObject("Main Camera", typeof(Camera)).GetComponent<Camera>();
|
||
cam.tag = "MainCamera";
|
||
cam.clearFlags = CameraClearFlags.SolidColor;
|
||
cam.backgroundColor = Color.black;
|
||
cam.orthographic = true;
|
||
cam.cullingMask = 0;
|
||
cam.gameObject.AddComponent<UniversalAdditionalCameraData>();
|
||
EditorSceneManager.SaveScene(scene, ScenePath);
|
||
}
|
||
EditorBuildSettings.scenes = new[] { new EditorBuildSettingsScene(ScenePath, true) };
|
||
}
|
||
|
||
static void ApplyPlayerSettings()
|
||
{
|
||
PlayerSettings.productName = "Rhyculator";
|
||
PlayerSettings.bundleVersion = "3.0.0";
|
||
// 沿用舊的套件名,已安裝的玩家可以直接覆蓋更新(登入狀態、設定都保留)
|
||
PlayerSettings.SetApplicationIdentifier(UnityEditor.Build.NamedBuildTarget.Android, "com.DefaultCompany.Lunchpad");
|
||
PlayerSettings.SetScriptingBackend(UnityEditor.Build.NamedBuildTarget.Android, ScriptingImplementation.IL2CPP);
|
||
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARM64;
|
||
PlayerSettings.Android.minSdkVersion = AndroidSdkVersions.AndroidApiLevel25;
|
||
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
|
||
PlayerSettings.SetManagedStrippingLevel(UnityEditor.Build.NamedBuildTarget.Android, ManagedStrippingLevel.Low);
|
||
PlayerSettings.stripEngineCode = true;
|
||
// 本地伺服器走 http;正式上線(ServerConfig.UseLocal = false)只允許 https
|
||
PlayerSettings.insecureHttpOption = ServerConfig.UseLocal ? InsecureHttpOption.AlwaysAllowed : InsecureHttpOption.NotAllowed;
|
||
AssetDatabase.SaveAssets();
|
||
}
|
||
}
|