Replace TownSquare with HomeCamp art and land humanoid bots, LittleBear, and LmGirl review assets.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Pipeline script to optimize AudioImporter settings across all project sound assets.
|
||||
/// Converts uncompressed stereo one-shots to mono ADPCM, sets BGM to 2D streaming Vorbis.
|
||||
/// </summary>
|
||||
public static class OptimizeAudioSettings
|
||||
{
|
||||
const string SoundRoot = "Assets/Bundles/Sound";
|
||||
|
||||
public static string Run()
|
||||
{
|
||||
if (EditorApplication.isPlayingOrWillChangePlaymode)
|
||||
throw new InvalidOperationException("Run in Edit Mode.");
|
||||
|
||||
int count = 0;
|
||||
|
||||
var guids = AssetDatabase.FindAssets("t:AudioClip", new[] { SoundRoot });
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var importer = AssetImporter.GetAtPath(path) as AudioImporter;
|
||||
if (importer == null) continue;
|
||||
|
||||
bool isBgm = path.Contains("/BGM/");
|
||||
|
||||
// 1. Force to mono for all one-shots (cuts memory in half)
|
||||
importer.forceToMono = !isBgm;
|
||||
|
||||
// 2. Disable 3D spatial calculations for UI, 2D battle feedbacks and BGM
|
||||
var serialized = new SerializedObject(importer);
|
||||
var prop3D = serialized.FindProperty("3D");
|
||||
if (prop3D != null && prop3D.boolValue)
|
||||
{
|
||||
prop3D.boolValue = false;
|
||||
serialized.ApplyModifiedPropertiesWithoutUndo();
|
||||
}
|
||||
|
||||
// 3. Setup platform default settings
|
||||
var settings = importer.defaultSampleSettings;
|
||||
if (isBgm)
|
||||
{
|
||||
// Streaming Vorbis for long background music tracks
|
||||
settings.loadType = AudioClipLoadType.Streaming;
|
||||
settings.compressionFormat = AudioCompressionFormat.Vorbis;
|
||||
settings.quality = 0.75f;
|
||||
settings.preloadAudioData = false;
|
||||
importer.loadInBackground = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fast ADPCM with zero decompression overhead for short gameplay one-shots
|
||||
settings.loadType = AudioClipLoadType.DecompressOnLoad;
|
||||
settings.compressionFormat = AudioCompressionFormat.ADPCM;
|
||||
settings.sampleRateSetting = AudioSampleRateSetting.PreserveSampleRate;
|
||||
settings.preloadAudioData = true;
|
||||
importer.loadInBackground = false;
|
||||
}
|
||||
|
||||
importer.defaultSampleSettings = settings;
|
||||
importer.SaveAndReimport();
|
||||
count++;
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
return $"Optimized {count} audio assets across UI, Combat SFX, and BGM.";
|
||||
}
|
||||
|
||||
public static string Verify()
|
||||
{
|
||||
var guids = AssetDatabase.FindAssets("t:AudioClip", new[] { SoundRoot });
|
||||
int verified = 0;
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
string path = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var importer = AssetImporter.GetAtPath(path) as AudioImporter;
|
||||
if (importer == null) continue;
|
||||
|
||||
bool isBgm = path.Contains("/BGM/");
|
||||
var settings = importer.defaultSampleSettings;
|
||||
|
||||
if (isBgm)
|
||||
{
|
||||
if (settings.loadType != AudioClipLoadType.Streaming || settings.compressionFormat != AudioCompressionFormat.Vorbis)
|
||||
throw new Exception($"BGM not streaming Vorbis: {path}");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!importer.forceToMono)
|
||||
throw new Exception($"One-shot SFX not forced to mono: {path}");
|
||||
if (settings.compressionFormat != AudioCompressionFormat.ADPCM)
|
||||
throw new Exception($"One-shot SFX not ADPCM: {path}");
|
||||
}
|
||||
verified++;
|
||||
}
|
||||
return $"PASS all {verified} audio assets conform to mobile runtime specifications.";
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user