Feat : Wwise Integration
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9e477556c144fa5468b8bd978b04e26f
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 687e6ec8aa2d6634289f2d87797b8a49
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
{
|
||||
"name": "AK.Wwise.Unity.AddressableInstaller",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"AK.Wwise.Unity.MonoBehaviour.Editor",
|
||||
"Unity.Addressables.Editor",
|
||||
"Unity.Addressables",
|
||||
"Unity.ScriptableBuildPipeline.Editor",
|
||||
"Unity.ResourceManager",
|
||||
"Unity.ScriptableBuildPipeline",
|
||||
"AK.Wwise.Unity.API",
|
||||
"AK.Wwise.Unity.Addressables",
|
||||
"AK.Wwise.Unity.API.WwiseTypes",
|
||||
"AK.Wwise.Unity.ProjectDatabase",
|
||||
"AK.Wwise.Unity.Addressables.Editor",
|
||||
"AK.Wwise.Unity.MonoBehaviour",
|
||||
"AK.Wwise.Unity.Utilities",
|
||||
"AK.Wwise.Unity.Logging"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [ "!UNITY_SERVER" ],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.addressables",
|
||||
"expression": "1.8",
|
||||
"define": "UNITY_ADDRESSABLES"
|
||||
},
|
||||
{
|
||||
"name": "com.audiokinetic.wwise.addressables",
|
||||
"expression": "1.0.0",
|
||||
"define": "AK_WWISE_ADDRESSABLES"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2965f2128381b174fbc9ee9f65719982
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,223 @@
|
||||
/*******************************************************************************
|
||||
The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
|
||||
Technology released in source code form as part of the game integration package.
|
||||
The content of this file may not be used without valid licenses to the
|
||||
AUDIOKINETIC Wwise Technology.
|
||||
Note that the use of the game engine is subject to the Unity(R) Terms of
|
||||
Service at https://unity3d.com/legal/terms-of-service
|
||||
|
||||
License Usage
|
||||
|
||||
Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
|
||||
this file in accordance with the end user license agreement provided with the
|
||||
software or, alternatively, in accordance with the terms contained
|
||||
in a written agreement between you and Audiokinetic Inc.
|
||||
Copyright (c) 2026 Audiokinetic Inc.
|
||||
*******************************************************************************/
|
||||
#if UNITY_ADDRESSABLES
|
||||
using System;
|
||||
using System.IO;
|
||||
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
|
||||
using AK.Wwise.Unity.WwiseAddressables;
|
||||
#endif
|
||||
using UnityEditor;
|
||||
using UnityEditor.AddressableAssets;
|
||||
using UnityEditor.AddressableAssets.Build;
|
||||
using UnityEditor.AddressableAssets.Build.DataBuilders;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
using UnityEngine;
|
||||
using AK.Wwise.Unity.Logging;
|
||||
|
||||
public static class AddressableAssetBuilder
|
||||
{
|
||||
private static string Name = nameof(AddressableAssetBuilder);
|
||||
private static bool _useCustomBuildScript = false;
|
||||
private static string _addressableAssetBuilderPath = "";
|
||||
|
||||
public static void ApplySettings(bool useCustomBuildScript, string addressableAssetBuilderPath)
|
||||
{
|
||||
_useCustomBuildScript = useCustomBuildScript;
|
||||
if (!useCustomBuildScript)
|
||||
{
|
||||
string folderPath = "Assets/AddressableAssetsData/DataBuilders";
|
||||
string assetPath = Path.Combine(folderPath, "BuildScriptWwisePacked.asset");
|
||||
AkWwiseEditorSettings.Instance.AddressableAssetBuilderPath = assetPath;
|
||||
AkWwiseEditorSettings.Instance.SaveSettings();
|
||||
_addressableAssetBuilderPath = assetPath;
|
||||
}
|
||||
else
|
||||
{
|
||||
_addressableAssetBuilderPath = addressableAssetBuilderPath;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute an Addressable Group build using the Wwise Build script
|
||||
/// </summary>
|
||||
public static void Build(bool isInstalling)
|
||||
{
|
||||
// Get the Addressable Asset Settings
|
||||
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
|
||||
if (settings == null)
|
||||
{
|
||||
AddressableInstaller.LogError(Name,"AddressableAssetSettings not found. Ensure Addressables is set up in your project.");
|
||||
return;
|
||||
}
|
||||
|
||||
BuildScriptPackedMode buildScript;
|
||||
if (isInstalling)
|
||||
{
|
||||
buildScript = AssetDatabase.LoadAssetAtPath<ScriptableObject>(_addressableAssetBuilderPath) as BuildScriptPackedMode;
|
||||
|
||||
if (buildScript == null)
|
||||
{
|
||||
AddressableInstaller.LogError(Name,$"Asset at {_addressableAssetBuilderPath} could not be loaded or is not a BuildScriptPackedMode.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string defaultBuilderPath = "Assets/AddressableAssetsData/DataBuilders/BuildScriptPackedMode.asset";
|
||||
buildScript = AssetDatabase.LoadAssetAtPath<ScriptableObject>(defaultBuilderPath) as BuildScriptPackedMode;
|
||||
}
|
||||
|
||||
// Set the custom build script as the active data builder
|
||||
settings.ActivePlayerDataBuilderIndex = settings.DataBuilders.IndexOf(buildScript);
|
||||
|
||||
if (settings.ActivePlayerDataBuilderIndex < 0)
|
||||
{
|
||||
AddressableInstaller.LogError(Name,"Failed to set custom build script as active. Ensure it is added to Addressables settings.");
|
||||
return;
|
||||
}
|
||||
|
||||
WwiseLogger.Log($"Using build script: {buildScript.Name}");
|
||||
// Start the Addressables build process
|
||||
WwiseLogger.Log("Starting Addressables build...");
|
||||
AddressableAssetSettings.BuildPlayerContent();
|
||||
WwiseLogger.Log("Addressables build completed successfully.");
|
||||
}
|
||||
|
||||
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
|
||||
/// <summary>
|
||||
/// Create the BuildScriptWwisePacked content builder.
|
||||
/// </summary>
|
||||
public static void CreateContentBuilder()
|
||||
{
|
||||
// Define the path where the asset will be created
|
||||
string folderPath = "Assets/AddressableAssetsData/DataBuilders";
|
||||
string assetPath = Path.Combine(folderPath, "BuildScriptWwisePacked.asset");
|
||||
|
||||
// Ensure the folder exists
|
||||
if (!Directory.Exists(folderPath))
|
||||
{
|
||||
Directory.CreateDirectory(folderPath);
|
||||
WwiseLogger.Log($"Created folder: {folderPath}");
|
||||
}
|
||||
|
||||
// Check if the asset already exists
|
||||
var existingAsset = AssetDatabase.LoadAssetAtPath<BuildScriptWwisePacked>(assetPath);
|
||||
if (existingAsset != null)
|
||||
{
|
||||
WwiseLogger.Log("BuildScriptWwisePacked.asset already exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Create and save the new asset
|
||||
var newAsset = ScriptableObject.CreateInstance<BuildScriptWwisePacked>();
|
||||
AssetDatabase.CreateAsset(newAsset, assetPath);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
WwiseLogger.Log("Created BuildScriptWwisePacked.asset at " + assetPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add the build script created at Assets/AddressableAssetsData/DataBuilders/BuildScriptWwisePacked.asset to the addressable group build
|
||||
/// </summary>
|
||||
public static void AddBuildScript()
|
||||
{
|
||||
// Path to the newly created build script asset
|
||||
string assetPath = "Assets/AddressableAssetsData/DataBuilders/BuildScriptWwisePacked.asset";
|
||||
|
||||
// Load the Addressable Asset Settings
|
||||
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
|
||||
if (settings == null)
|
||||
{
|
||||
AddressableInstaller.LogError(Name,"AddressableAssetSettings not found. Ensure Addressables is set up in your project.");
|
||||
settings = AddressableAssetSettings.Create(AddressableAssetSettingsDefaultObject.kDefaultConfigFolder, AddressableAssetSettingsDefaultObject.kDefaultConfigAssetName, false, true);
|
||||
}
|
||||
|
||||
// Load the custom build script asset
|
||||
var customBuildScript = AssetDatabase.LoadAssetAtPath<ScriptableObject>(assetPath);
|
||||
if (customBuildScript == null)
|
||||
{
|
||||
AddressableInstaller.LogError(Name,$"Build script asset not found at path: {assetPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if the build script is already added
|
||||
foreach (var builder in settings.DataBuilders)
|
||||
{
|
||||
if (builder == customBuildScript)
|
||||
{
|
||||
WwiseLogger.Log("Build script already exists in Addressables settings.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the build script to the Addressables settings
|
||||
settings.DataBuilders.Add(customBuildScript);
|
||||
EditorUtility.SetDirty(settings);
|
||||
AssetDatabase.SaveAssets();
|
||||
|
||||
WwiseLogger.Log($"Added build script to Addressables settings: {assetPath}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Utility function that combines all the necessary steps to do a Wwise Addressable Group build
|
||||
/// </summary>
|
||||
public static void AddressableSetup()
|
||||
{
|
||||
if (!_useCustomBuildScript)
|
||||
{
|
||||
CreateContentBuilder();
|
||||
}
|
||||
AddBuildScript();
|
||||
Build(true);
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
/// Remove the build script created at Assets/AddressableAssetsData/DataBuilders/BuildScriptWwisePacked.asset from the addressable group build
|
||||
/// </summary>
|
||||
public static void RemoveBuildScript()
|
||||
{
|
||||
//We do not handle uninstalling a custom build script
|
||||
if (_useCustomBuildScript)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string assetPath = "Assets/AddressableAssetsData/DataBuilders/BuildScriptWwisePacked.asset";
|
||||
|
||||
// Load the Addressable Asset Settings
|
||||
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
|
||||
if (settings == null)
|
||||
{
|
||||
AddressableInstaller.LogError(Name,"AddressableAssetSettings not found. Ensure Addressables is set up in your project.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Load the custom build script asset
|
||||
var customBuildScript = AssetDatabase.LoadAssetAtPath<ScriptableObject>(assetPath);
|
||||
if (customBuildScript == null)
|
||||
{
|
||||
AddressableInstaller.LogError(Name,$"Build script asset not found at path: {assetPath}");
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove the build scripts
|
||||
settings.DataBuilders.Remove(customBuildScript);
|
||||
EditorUtility.SetDirty(settings);
|
||||
AssetDatabase.SaveAssets();
|
||||
WwiseLogger.Log($"Removed build script from Addressables settings: {assetPath}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f1c7da82218f0bc48a93e0a78d73bfd9
|
||||
@@ -0,0 +1,96 @@
|
||||
/*******************************************************************************
|
||||
The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
|
||||
Technology released in source code form as part of the game integration package.
|
||||
The content of this file may not be used without valid licenses to the
|
||||
AUDIOKINETIC Wwise Technology.
|
||||
Note that the use of the game engine is subject to the Unity(R) Terms of
|
||||
Service at https://unity3d.com/legal/terms-of-service
|
||||
|
||||
License Usage
|
||||
|
||||
Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
|
||||
this file in accordance with the end user license agreement provided with the
|
||||
software or, alternatively, in accordance with the terms contained
|
||||
in a written agreement between you and Audiokinetic Inc.
|
||||
Copyright (c) 2026 Audiokinetic Inc.
|
||||
*******************************************************************************/
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using AK.Wwise.Unity.Logging;
|
||||
|
||||
public class AddressableBankPathSetter
|
||||
{
|
||||
/// <summary>
|
||||
/// Set the bank path for unity addressable
|
||||
/// </summary>
|
||||
/// <param name="bankFolder">The path of the folder in which to output the bank. Should be relative to the Asset Folder</param>
|
||||
public static bool SetBankPath(string bankFolder)
|
||||
{
|
||||
if (bankFolder == null)
|
||||
{
|
||||
WwiseLogger.Error("AddressableBankPathSetter: Bank folder was not specified.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var fullPath = Path.Combine(UnityEngine.Application.dataPath, bankFolder);
|
||||
fullPath = fullPath.Replace('\\', '/');
|
||||
|
||||
if (bankFolder.Length != 0)
|
||||
{
|
||||
var settings = AkWwiseEditorSettings.Instance;
|
||||
settings.RootOutputPath = bankFolder;
|
||||
var projectPath = AkUtilities.GetFullPath(UnityEngine.Application.dataPath, settings.WwiseProjectPath);
|
||||
var relPath = AkUtilities.MakeRelativePath(System.IO.Path.GetDirectoryName(projectPath), fullPath);
|
||||
AkUtilities.SetSoundbanksDestinationFoldersInWproj(projectPath, relPath);
|
||||
settings.SaveSettings();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool SetExternalSourcePath(string externalSourcePath)
|
||||
{
|
||||
if (externalSourcePath == null)
|
||||
{
|
||||
WwiseLogger.Error("AddressableBankPathSetter: Bank folder was not specified.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var fullPath = Path.Combine(UnityEngine.Application.dataPath, externalSourcePath);
|
||||
fullPath = fullPath.Replace('\\', '/');
|
||||
|
||||
if (externalSourcePath.Length != 0)
|
||||
{
|
||||
var settings = AkWwiseEditorSettings.Instance;
|
||||
var projectPath = AkUtilities.GetFullPath(UnityEngine.Application.dataPath, settings.WwiseProjectPath);
|
||||
var relPath = AkUtilities.MakeRelativePath(System.IO.Path.GetDirectoryName(projectPath), fullPath);
|
||||
AkUtilities.SetExternalSourceDestinationFolderInWproj(projectPath, relPath);
|
||||
settings.SaveSettings();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void SetStreamingAssetsPath(string soundBankPath)
|
||||
{
|
||||
if (soundBankPath == null)
|
||||
{
|
||||
WwiseLogger.Error("AddressableBankPathSetter: Bank folder was not specified.");
|
||||
}
|
||||
|
||||
var fullPath = Path.Combine(UnityEngine.Application.streamingAssetsPath, soundBankPath);
|
||||
fullPath = fullPath.Replace('\\', '/');
|
||||
|
||||
if (soundBankPath.Length != 0)
|
||||
{
|
||||
var settings = AkWwiseEditorSettings.Instance;
|
||||
settings.RootOutputPath = AkUtilities.MakeRelativePath(UnityEngine.Application.dataPath, fullPath);
|
||||
var projectPath = AkUtilities.GetFullPath(UnityEngine.Application.dataPath, settings.WwiseProjectPath);
|
||||
var relPath = AkUtilities.MakeRelativePath(System.IO.Path.GetDirectoryName(projectPath), fullPath);
|
||||
AkUtilities.SetWwiseRootOutputPath(projectPath, relPath);
|
||||
AkUtilities.SetPlatformsSoundBankPath(projectPath, "GeneratedSoundBanks");
|
||||
settings.SaveSettings();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c0ea98e20b8c9d14b8f9c964cc002e9f
|
||||
@@ -0,0 +1,600 @@
|
||||
/*******************************************************************************
|
||||
The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
|
||||
Technology released in source code form as part of the game integration package.
|
||||
The content of this file may not be used without valid licenses to the
|
||||
AUDIOKINETIC Wwise Technology.
|
||||
Note that the use of the game engine is subject to the Unity(R) Terms of
|
||||
Service at https://unity3d.com/legal/terms-of-service
|
||||
|
||||
License Usage
|
||||
|
||||
Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
|
||||
this file in accordance with the end user license agreement provided with the
|
||||
software or, alternatively, in accordance with the terms contained
|
||||
in a written agreement between you and Audiokinetic Inc.
|
||||
Copyright (c) 2026 Audiokinetic Inc.
|
||||
*******************************************************************************/
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEditor.PackageManager.Requests;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEngine;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using UnityEditor.Callbacks;
|
||||
using AK.Wwise.Unity.Logging;
|
||||
using PackageInfo = UnityEditor.PackageManager.PackageInfo;
|
||||
|
||||
#if AK_WWISE_ADDRESSABLES
|
||||
using UnityEditor.AddressableAssets;
|
||||
using UnityEditor.AddressableAssets.Settings;
|
||||
using AK.Wwise.Unity.WwiseAddressables;
|
||||
#endif
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class AddressableInstaller
|
||||
{
|
||||
static AddressableInstaller()
|
||||
{
|
||||
// Subscribe to the event at editor load time
|
||||
Events.registeredPackages += OnPackagesRegistered;
|
||||
}
|
||||
|
||||
private static void OnPackagesRegistered(PackageRegistrationEventArgs args)
|
||||
{
|
||||
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
|
||||
if (AkWwiseEditorSettings.Instance.InstallationWasRequested)
|
||||
{
|
||||
foreach (var package in args.added)
|
||||
{
|
||||
if (package.assetPath == "Packages/com.audiokinetic.wwise.addressables")
|
||||
{
|
||||
AkWwiseEditorSettings.Instance.InstallationWasRequested = false;
|
||||
AkWwiseEditorSettings.Instance.SaveSettings();
|
||||
AddressableSetup();
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
foreach (var package in args.removed)
|
||||
{
|
||||
if (package.assetPath == "Packages/com.audiokinetic.wwise.addressables")
|
||||
{
|
||||
CompleteUninstallation();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
private static string Name = nameof(AddressableInstaller);
|
||||
|
||||
// Local value of the settings used to determine whether to use command line arguments or settings from the xml file.
|
||||
private static string _addressableBankFolder = "";
|
||||
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
|
||||
private static bool _automaticallyUpdateExternalSourcesPath = false;
|
||||
private static string _externalSourcesPath = "";
|
||||
private static bool _enableUninstallationPrompt = true;
|
||||
private static bool _disableAsynchronousBankLoading = true;
|
||||
#else
|
||||
private static string _packageSource = "";
|
||||
#endif
|
||||
|
||||
private static void ReadSettings()
|
||||
{
|
||||
string[] args = System.Environment.GetCommandLineArgs();
|
||||
|
||||
_addressableBankFolder = AkWwiseEditorSettings.Instance.AddressableBankFolder;
|
||||
if (args.Contains("-addressableBankFolder"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-addressableBankFolder");
|
||||
_addressableBankFolder = args[index + 1];
|
||||
}
|
||||
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
|
||||
_automaticallyUpdateExternalSourcesPath = AkWwiseEditorSettings.Instance.AutomaticallyUpdateExternalSourcesPath;
|
||||
if (args.Contains("-updateExternalSourcesPath"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-updateExternalSourcesPath");
|
||||
_automaticallyUpdateExternalSourcesPath = args[index + 1] == "true";
|
||||
}
|
||||
_externalSourcesPath = AkWwiseEditorSettings.Instance.ExternalSourcesPath;
|
||||
if (args.Contains("-externalSourcesPath"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-externalSourcesPath");
|
||||
_externalSourcesPath = args[index + 1];
|
||||
//updateExternalSourcesPath would be optional if externalSourcesPath is provided
|
||||
_automaticallyUpdateExternalSourcesPath = true;
|
||||
}
|
||||
|
||||
// AddressableAssetBuilder Settings
|
||||
bool useCustomBuildScript = AkWwiseEditorSettings.Instance.UseCustomBuildScript;
|
||||
if (args.Contains("-useCustomBuildScript"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-useCustomBuildScript");
|
||||
_externalSourcesPath = args[index + 1];
|
||||
}
|
||||
string addressableAssetBuilderPath = AkWwiseEditorSettings.Instance.AddressableAssetBuilderPath;
|
||||
if (args.Contains("-addressableAssetBuilderPath"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-addressableAssetBuilderPath");
|
||||
_externalSourcesPath = args[index + 1];
|
||||
//useCustomBuildScript would be optional if addressableAssetBuilderPath is provided
|
||||
useCustomBuildScript = true;
|
||||
}
|
||||
AddressableAssetBuilder.ApplySettings(useCustomBuildScript, addressableAssetBuilderPath);
|
||||
_enableUninstallationPrompt = AkWwiseEditorSettings.Instance.EnableUninstallationPrompt;
|
||||
if (args.Contains("-disableUninstallationPrompt"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-disableUninstallationPrompt");
|
||||
_enableUninstallationPrompt = args[index + 1] == "true";
|
||||
}
|
||||
_disableAsynchronousBankLoading = AkWwiseEditorSettings.Instance.DisableAsynchronousBankLoading;
|
||||
if (args.Contains("-disableAsynchronousBankLoadingOnUninstallation"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-disableAsynchronousBankLoadingOnUninstallation");
|
||||
_disableAsynchronousBankLoading = args[index + 1] == "true";
|
||||
}
|
||||
#else
|
||||
_packageSource = AkWwiseEditorSettings.Instance.UseGitRepository ? WwiseSettings.GitRepositoryLink : AkWwiseEditorSettings.Instance.PackageSource;
|
||||
if (args.Contains("-packageSource"))
|
||||
{
|
||||
int index = Array.IndexOf(args, "-packageSource");
|
||||
_packageSource = args[index + 1];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toogle the AkInitializer On or Off
|
||||
/// </summary>
|
||||
/// <param name="value">The value at which the AkInitializer enabled will be set at.</param>
|
||||
private static void ToggleAkInitializer(bool value)
|
||||
{
|
||||
GameObject targetObject = GameObject.Find("WwiseGlobal");
|
||||
if (targetObject != null)
|
||||
{
|
||||
AkInitializer script = targetObject.GetComponent<AkInitializer>();
|
||||
if (script != null)
|
||||
{
|
||||
script.enabled = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Simple Debug Log formatter
|
||||
/// </summary>
|
||||
/// <param name="source">The source of the log</param>
|
||||
/// <param name="errorMsg">The message to log</param>
|
||||
public static void LogError(string source, string errorMsg)
|
||||
{
|
||||
WwiseLogger.Error($"{source}: {errorMsg}");
|
||||
}
|
||||
|
||||
public static void LogWarning(string source, string errorMsg)
|
||||
{
|
||||
WwiseLogger.Warning($"{source}: {errorMsg}");
|
||||
}
|
||||
|
||||
public static void Log(string source, string errorMsg)
|
||||
{
|
||||
WwiseLogger.Log($"{source}: {errorMsg}");
|
||||
}
|
||||
private static AddRequest _addRequest;
|
||||
|
||||
#if !AK_WWISE_ADDRESSABLES
|
||||
/// <summary>
|
||||
/// Menu item to install the Wwise Addressable Package and set it up
|
||||
/// </summary>
|
||||
[MenuItem("Wwise/Install Addressables")]
|
||||
public static void InstallPackage()
|
||||
{
|
||||
ReadSettings();
|
||||
AkWwiseEditorSettings.Instance.InstallationWasRequested = true;
|
||||
AkWwiseEditorSettings.Instance.SaveSettings();
|
||||
var installationPathIsEmpty = string.IsNullOrEmpty(AkWwiseEditorSettings.Instance.WwiseInstallationPath);
|
||||
var waapiPortIsEmpty = string.IsNullOrEmpty(AkWwiseEditorSettings.Instance.WaapiPort);
|
||||
var waapiIPIsEmpty = string.IsNullOrEmpty(AkWwiseEditorSettings.Instance.WaapiIP);
|
||||
if (installationPathIsEmpty || waapiPortIsEmpty || waapiIPIsEmpty)
|
||||
{
|
||||
string missingSettings = (installationPathIsEmpty ? "WwiseApplicationPath, " : string.Empty) + (waapiPortIsEmpty ? "Waapi Port, " : string.Empty) + (waapiIPIsEmpty ? "Waapi IP, " : string.Empty);
|
||||
missingSettings = missingSettings.TrimEnd(new char[] { ',', ' ' });
|
||||
|
||||
EditorUtility.DisplayDialog("Wwise Addressables installation aborted", $"The installation process was aborted as the following setting(s) were not set:\n{missingSettings}.\nAdjust your Wwise integration settings and try again.", "OK");
|
||||
return;
|
||||
}
|
||||
AdjustLoadBankAsynchronously();
|
||||
if (!InstallAddressablePackage(_packageSource))
|
||||
{
|
||||
LogError(Name, $"Failed to install the Wwise Unity Addressable package from {_packageSource}");
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Menu item to uninstall the Wwise Addressable Package and clean up the Unity project
|
||||
/// </summary>
|
||||
[MenuItem("Wwise/Uninstall Addressables")]
|
||||
public static void UninstallPackage()
|
||||
{
|
||||
ReadSettings();
|
||||
if (!AdjustLoadBankAsynchronously())
|
||||
{
|
||||
return;
|
||||
}
|
||||
ToggleAkInitializer(false);
|
||||
AkSoundEngineController.Instance.DisableEditorLateUpdate();
|
||||
EditorApplication.update += ContinueUninstallation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Continue the uninstallation process after disabling Wwise components interacting with the Wwise Addressables Package.
|
||||
/// </summary>
|
||||
private static void ContinueUninstallation()
|
||||
{
|
||||
ReadSettings();
|
||||
//Clean the addressables assets being used.
|
||||
CleanupAddressables();
|
||||
//Remove the init bank holder (Wwise Addressables only asset)
|
||||
RemoveInitBankHolder();
|
||||
//Delete the Wwise Addressables Assets under Unity Application data path
|
||||
DeleteWwiseAddressablesBankFolder();
|
||||
//Delete the Wwise Addressable Groups
|
||||
DeleteWwiseAddressableGroups();
|
||||
//Remove the build script
|
||||
AddressableAssetBuilder.RemoveBuildScript();
|
||||
//Remove the Wwise Addresables Package
|
||||
RemoveWwiseAddressablePackage();
|
||||
EditorApplication.update -= ContinueUninstallation;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
private static bool AdjustLoadBankAsynchronously()
|
||||
{
|
||||
#if AK_WWISE_ADDRESSABLES
|
||||
bool shouldDisableAsynchronousBankLoading = false;
|
||||
if (_enableUninstallationPrompt)
|
||||
{
|
||||
int dialogChoiceIndex = EditorUtility.DisplayDialogComplex(
|
||||
"Wwise Unity Addressables Uninstallation",
|
||||
"Set the Load Bank Asynchronous settings to false during uninstallation? The original value was modified during the installation of the Wwise Unity Addressables integration package. In most projects, it is disabled when not working with Addressables. You can set a default value for this prompt or disable it in the Wwise Settings.",
|
||||
"Yes",
|
||||
"Cancel",
|
||||
"No"
|
||||
);
|
||||
|
||||
if (dialogChoiceIndex == 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
shouldDisableAsynchronousBankLoading = dialogChoiceIndex == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
shouldDisableAsynchronousBankLoading = _disableAsynchronousBankLoading;
|
||||
}
|
||||
|
||||
if (shouldDisableAsynchronousBankLoading)
|
||||
{
|
||||
var platformSettings = AkWwiseInitializationSettings.GetAllPlatformSettings();
|
||||
foreach (var platformSetting in platformSettings)
|
||||
{
|
||||
platformSetting.LoadBanksAsynchronously = false;
|
||||
EditorUtility.SetDirty(platformSetting);
|
||||
}
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
return true;
|
||||
#else
|
||||
|
||||
var platformSettings = AkWwiseInitializationSettings.Instance.PlatformSettingsList;
|
||||
foreach (var platformSetting in platformSettings)
|
||||
{
|
||||
if (platformSetting)
|
||||
{
|
||||
platformSetting.LoadBanksAsynchronously = true;
|
||||
EditorUtility.SetDirty(platformSetting);
|
||||
}
|
||||
}
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
|
||||
/// <summary>
|
||||
/// Setup the Wwise Addressable Package
|
||||
/// </summary>
|
||||
private static void AddressableSetup()
|
||||
{
|
||||
ReadSettings();
|
||||
if (!AddressableBankPathSetter.SetBankPath(_addressableBankFolder))
|
||||
{
|
||||
LogError(Name, $"Failed to set the bank folder to {_addressableBankFolder}");;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_automaticallyUpdateExternalSourcesPath)
|
||||
{
|
||||
if (!AddressableBankPathSetter.SetExternalSourcePath(_externalSourcesPath))
|
||||
{
|
||||
LogError(Name, $"Failed to set the bank folder to {_externalSourcesPath}");;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!AkUtilities.IsSoundbankGenerationAvailable(AkWwiseEditorSettings.Instance.WwiseInstallationPath))
|
||||
{
|
||||
LogWarning(Name,$"Sound bank generation is not available. Make sure that the Wwise Project is opened in the Wwise Authoring and please edit the Wwise Settings to ensure the the ip and port are set properly. If it's still not working, ensure that the Wwise Application Path is properly set.");;
|
||||
}
|
||||
AkUtilities.GenerateSoundbanks(AkWwiseEditorSettings.Instance.WwiseInstallationPath, AkWwiseEditorSettings.WwiseProjectAbsolutePath);
|
||||
AddressableAssetBuilder.AddressableSetup();
|
||||
SceneUpdater.ReloadAllScenes();
|
||||
}
|
||||
#else
|
||||
/// <summary>
|
||||
/// Complete the Wwise Addressable Package uninstallation process after the package removal.
|
||||
/// </summary>
|
||||
private static void CompleteUninstallation()
|
||||
{
|
||||
ReadSettings();
|
||||
//Reset the Root output Path and SoundBank Paths to asset the Unity Application Data Path.
|
||||
var settings = AkWwiseEditorSettings.Instance;
|
||||
AddressableBankPathSetter.SetStreamingAssetsPath(settings.WwiseStreamingAssetsPath);
|
||||
AddressableBankPathSetter.SetExternalSourcePath("GeneratedSoundBanks");
|
||||
|
||||
//Regenerate the soundbanks
|
||||
string wwiseInstallationPath = "";
|
||||
#if UNITY_EDITOR_WIN
|
||||
wwiseInstallationPath = AkWwiseEditorSettings.Instance.WwiseInstallationPathWindows;
|
||||
#elif UNITY_EDITOR_OSX
|
||||
wwiseInstallationPath = AkWwiseEditorSettings.Instance.WwiseInstallationPathMac;
|
||||
#endif
|
||||
if (!AkUtilities.IsSoundbankGenerationAvailable(wwiseInstallationPath))
|
||||
{
|
||||
LogWarning(Name,$"Sound bank generation is not available. Make sure that the Wwise Project is opened in the Wwise Authoring and please edit the Wwise Settings to ensure the the ip and port are set properly. If it's still not working, ensure that the Wwise Application Path is properly set.");;
|
||||
}
|
||||
else
|
||||
{
|
||||
AkUtilities.GenerateSoundbanks(wwiseInstallationPath, AkWwiseEditorSettings.WwiseProjectAbsolutePath);
|
||||
}
|
||||
//Re-enable the SoundEngineController LateUpdate and the AkInitializer that were disabled during the uninstallation process.
|
||||
AkSoundEngineController.Instance.EnableEditorLateUpdate();
|
||||
ToggleAkInitializer(true);
|
||||
#if UNITY_ADDRESSABLES
|
||||
AddressableAssetBuilder.Build(false);
|
||||
#endif
|
||||
if (UnityEditorInternal.InternalEditorUtility.inBatchMode)
|
||||
{
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/// <summary>
|
||||
/// Installs the Wwise Addressable Package
|
||||
/// </summary>
|
||||
/// <param name="packageSource">The source of the package. Can either be a local path or a git url</param>
|
||||
private static bool InstallAddressablePackage(string packageSource)
|
||||
{
|
||||
if (string.IsNullOrEmpty(packageSource))
|
||||
{
|
||||
WwiseLogger.Error("Package source not provided. Use -packageSource=<url_or_path> in the command line.");
|
||||
return false;
|
||||
}
|
||||
|
||||
packageSource = packageSource.Replace('\\', '/');
|
||||
|
||||
if (IsGitUrl(packageSource))
|
||||
{
|
||||
InstallFromUrl(packageSource);
|
||||
}
|
||||
else if (Directory.Exists(packageSource))
|
||||
{
|
||||
InstallFromLocalPath(packageSource);
|
||||
}
|
||||
else
|
||||
{
|
||||
WwiseLogger.Error($"Invalid package source: {packageSource}. Ensure it is a valid Git URL or local path.");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs a Unity package from a Git URL.
|
||||
/// </summary>
|
||||
/// <param name="url">The Git URL of the package.</param>
|
||||
private static void InstallFromUrl(string url)
|
||||
{
|
||||
WwiseLogger.Log($"Installing package from Git URL: {url}");
|
||||
_addRequest = Client.Add(url);
|
||||
EditorApplication.update += Progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Installs a Unity package from a local path.
|
||||
/// </summary>
|
||||
/// <param name="path">The local path of the package.</param>
|
||||
private static void InstallFromLocalPath(string path)
|
||||
{
|
||||
// Replace backslashes with forward slashes
|
||||
string pathUri = path.Replace("\\", "/");
|
||||
|
||||
// Prepend "file:" only if not already present
|
||||
if (!pathUri.StartsWith("file:"))
|
||||
{
|
||||
pathUri = $"file:{pathUri}";
|
||||
}
|
||||
_addRequest = Client.Add(pathUri);
|
||||
EditorApplication.update += Progress;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extracts the package name from a package.json file content.
|
||||
/// </summary>
|
||||
/// <param name="packageJson">The content of the package json file.</param>
|
||||
private static string ExtractPackageName(string packageJson)
|
||||
{
|
||||
var match = Regex.Match(packageJson, "\"name\": \"(?<name>.*?)\"");
|
||||
return match.Success ? match.Groups["name"].Value : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Utility to check if a string is a Git URL.
|
||||
/// </summary>
|
||||
/// <param name="source">The git repository link</param>
|
||||
private static bool IsGitUrl(string source)
|
||||
{
|
||||
return source.StartsWith("http://") || source.StartsWith("https://") || source.EndsWith(".git");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Utility to get the relative path from one directory to another.
|
||||
/// </summary>
|
||||
/// <param name="fromPath">The path of the first directory</param>
|
||||
/// <param name="toPath">The path of the second directory</param>
|
||||
private static string GetRelativePath(string fromPath, string toPath)
|
||||
{
|
||||
Uri fromUri = new Uri(fromPath);
|
||||
Uri toUri = new Uri(toPath);
|
||||
return fromUri.MakeRelativeUri(toUri).ToString().Replace('/', Path.DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tracks the progress of a package installation.
|
||||
/// </summary>
|
||||
private static void Progress()
|
||||
{
|
||||
if (_addRequest.IsCompleted)
|
||||
{
|
||||
if (_addRequest.Status == StatusCode.Success)
|
||||
{
|
||||
WwiseLogger.Log($"Successfully installed package: {_addRequest.Result.packageId}");
|
||||
}
|
||||
else if (_addRequest.Status >= StatusCode.Failure)
|
||||
{
|
||||
WwiseLogger.Error($"Failed to install package: {_addRequest.Error.message}");
|
||||
}
|
||||
|
||||
EditorApplication.update -= Progress;
|
||||
}
|
||||
}
|
||||
|
||||
#if AK_WWISE_ADDRESSABLES
|
||||
/*
|
||||
* Uninstall
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// Clean up the current Addressables Assets that are in use before starting the Wwise Addressables Package uninstallation process.
|
||||
/// </summary>
|
||||
private static void CleanupAddressables()
|
||||
{
|
||||
AkAddressableBankManager.Instance.DoUnloadBank();
|
||||
|
||||
// Force Addressables Build Cleanup
|
||||
AddressableAssetSettings.CleanPlayerContent();
|
||||
|
||||
// Clear Unity Cache
|
||||
Caching.ClearCache();
|
||||
|
||||
// Refresh Unity Database
|
||||
AssetDatabase.SaveAssets();
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
WwiseLogger.Log("Addressables cleaned successfully.");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the Wwise Init Bank Holder from the Wwise Global GameObject as it's a Wwise Addressables Package specific component.
|
||||
/// </summary>
|
||||
public static void RemoveInitBankHolder()
|
||||
{
|
||||
string targetObjectName = "WwiseGlobal"; // Change to the name of the object
|
||||
string targetComponentName = "InitBankHolder"; // Change to the component name
|
||||
// Find the GameObject by name
|
||||
GameObject targetObject = GameObject.Find(targetObjectName);
|
||||
|
||||
if (targetObject == null)
|
||||
{
|
||||
WwiseLogger.Error($"GameObject '{targetObjectName}' not found in the scene.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Find the component by name dynamically
|
||||
Component component = targetObject.GetComponent(targetComponentName);
|
||||
if (component != null)
|
||||
{
|
||||
UnityEngine.GameObject.DestroyImmediate(component);
|
||||
WwiseLogger.Log($"Removed component '{targetComponentName}' from '{targetObjectName}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
WwiseLogger.Warning($"Component '{targetComponentName}' not found on '{targetObjectName}'.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove the Wwise Addressables Package through the package manager API.
|
||||
/// </summary>
|
||||
public static void RemoveWwiseAddressablePackage()
|
||||
{
|
||||
Client.Remove("com.audiokinetic.wwise.addressables");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete the Wwise Addressables Bank Folder and it's content from the Unity Application Data Path.
|
||||
/// </summary>
|
||||
public static void DeleteWwiseAddressablesBankFolder()
|
||||
{
|
||||
string folderPath = "Assets/" + _addressableBankFolder;
|
||||
|
||||
if (AssetDatabase.IsValidFolder(folderPath))
|
||||
{
|
||||
if (AssetDatabase.DeleteAsset(folderPath))
|
||||
{
|
||||
WwiseLogger.Log($"Folder deleted: {folderPath}");
|
||||
}
|
||||
else
|
||||
{
|
||||
WwiseLogger.Error($"Failed to delete folder: {folderPath}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
WwiseLogger.Error($"Folder does not exist: {folderPath}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete The Wwise Addressables Groups
|
||||
/// </summary>
|
||||
public static void DeleteWwiseAddressableGroups()
|
||||
{
|
||||
AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;
|
||||
if (settings == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
string addressableGroupPrefix = "Wwise";
|
||||
var groupsToRemove = settings.groups.Where(g => g != null && g.Name.StartsWith(addressableGroupPrefix)).ToList();
|
||||
|
||||
if (groupsToRemove.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var group in groupsToRemove)
|
||||
{
|
||||
settings.RemoveGroup(group);
|
||||
}
|
||||
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f6101963fd01ce24fa7b0d196d14ac17
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c45b6dba6d84c444da2c61f67bafba7d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4828088243871349abedc2ea0e6dad4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "AK.Wwise.Unity.AddressableUpdater",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"AK.Wwise.Unity.MonoBehaviour.Editor",
|
||||
"AK.Wwise.Unity.API",
|
||||
"AK.Wwise.Unity.API.WwiseTypes",
|
||||
"AK.Wwise.Unity.ProjectDatabase",
|
||||
"AK.Wwise.Unity.Addressables",
|
||||
"AK.Wwise.Unity.MonoBehaviour",
|
||||
"AK.Wwise.Unity.Logging"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [ "!UNITY_SERVER" ],
|
||||
"versionDefines": [
|
||||
{
|
||||
"name": "com.unity.addressables",
|
||||
"expression": "1.8",
|
||||
"define": "UNITY_ADDRESSABLES"
|
||||
},
|
||||
{
|
||||
"name": "com.audiokinetic.wwise.addressables",
|
||||
"expression": "1.0.0",
|
||||
"define": "AK_WWISE_ADDRESSABLES"
|
||||
}
|
||||
],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce7e2eb766a504747a2170989958d7a6
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,103 @@
|
||||
/*******************************************************************************
|
||||
The content of this file includes portions of the proprietary AUDIOKINETIC Wwise
|
||||
Technology released in source code form as part of the game integration package.
|
||||
The content of this file may not be used without valid licenses to the
|
||||
AUDIOKINETIC Wwise Technology.
|
||||
Note that the use of the game engine is subject to the Unity(R) Terms of
|
||||
Service at https://unity3d.com/legal/terms-of-service
|
||||
|
||||
License Usage
|
||||
|
||||
Licensees holding valid licenses to the AUDIOKINETIC Wwise Technology may use
|
||||
this file in accordance with the end user license agreement provided with the
|
||||
software or, alternatively, in accordance with the terms contained
|
||||
in a written agreement between you and Audiokinetic Inc.
|
||||
Copyright (c) 2026 Audiokinetic Inc.
|
||||
*******************************************************************************/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using AK.Wwise.Unity.Logging;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class AddressableUpdater
|
||||
{
|
||||
|
||||
#if AK_WWISE_ADDRESSABLES && UNITY_ADDRESSABLES
|
||||
[MenuItem("Wwise/Update Addressables")]
|
||||
public static void UpdateAddressables()
|
||||
{
|
||||
string wwiseVersion = AkUnitySoundEngine.WwiseVersion;
|
||||
string shortWwiseVersion = wwiseVersion.Substring(2, wwiseVersion.IndexOf("Build")-3); //-3 for the space and the 2 first character that are skipped.
|
||||
string manifestPath = "Packages/manifest.json";
|
||||
//If using local installation, we cannot update through the updater. The user have to update their package locally.
|
||||
string addressablesGitHubLink = "https://github.com/audiokinetic/WwiseUnityAddressables.git#";
|
||||
if (!File.Exists(manifestPath))
|
||||
{
|
||||
WwiseLogger.Error($"Wwise Addressables Updater: {manifestPath} not found.");
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
List<string> lines = new List<string>();
|
||||
bool lineFoundAndReplaced = false;
|
||||
using (StreamReader reader = new StreamReader(manifestPath))
|
||||
{
|
||||
while (reader.ReadLine() is { } line)
|
||||
{
|
||||
if (line.Contains(addressablesGitHubLink))
|
||||
{
|
||||
int hashIndex = line.IndexOf('#');
|
||||
int quoteIndex = line.IndexOf('"', hashIndex);
|
||||
if (hashIndex != -1)
|
||||
{
|
||||
string prefix = line.Substring(0, hashIndex + 1);
|
||||
|
||||
string suffix = "";
|
||||
if (quoteIndex != -1 && quoteIndex > hashIndex)
|
||||
{
|
||||
suffix = line.Substring(quoteIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
int commaIndex = line.LastIndexOf(',');
|
||||
if (commaIndex != -1 && commaIndex > hashIndex)
|
||||
{
|
||||
suffix = line.Substring(commaIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// Reconstruct the line
|
||||
string gitHubWwiseVersion = line.Substring(hashIndex+1, quoteIndex - hashIndex-1);
|
||||
if (gitHubWwiseVersion != shortWwiseVersion)
|
||||
{
|
||||
line = prefix + 'v' +shortWwiseVersion + suffix;
|
||||
lineFoundAndReplaced = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
lines.Add(line);
|
||||
}
|
||||
}
|
||||
if (lineFoundAndReplaced)
|
||||
{
|
||||
File.WriteAllLines(manifestPath, lines);
|
||||
AssetDatabase.Refresh(); // Important to refresh Unity's asset database
|
||||
WwiseLogger.Log($"Wwise Addressables Updater: Successfully updated the Wwise Addressable Package to {shortWwiseVersion}.");
|
||||
}
|
||||
else
|
||||
{
|
||||
WwiseLogger.Log($"Wwise Addressables Updater: Already up to date. Current version {shortWwiseVersion}.");
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
WwiseLogger.Error($"Wwise Addressables Updater: Error processing JSON file: {e.Message}");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f790d3d3bf8f9549822d1f4a205abc9
|
||||
@@ -0,0 +1,97 @@
|
||||
'''
|
||||
Created on Mar 12, 2013
|
||||
|
||||
@author: bli
|
||||
'''
|
||||
|
||||
import sys, os, argparse
|
||||
from os.path import exists, join, dirname, abspath
|
||||
ScriptDir = abspath(dirname(__file__))
|
||||
g_PosixLinebreak = '\n'
|
||||
|
||||
class WwiseIDConverter(object):
|
||||
'''Convert Wwise soundbank ID header from C++ to C#. Save it under the same folder of the input header.'''
|
||||
|
||||
def __init__(self, inHeader):
|
||||
self.inHeader = inHeader
|
||||
outDir = dirname(self.inHeader)
|
||||
self.outHeader = join(outDir, 'Wwise_IDs.cs')
|
||||
|
||||
def Convert(self):
|
||||
lines = self._ImportFile(self.inHeader)
|
||||
|
||||
# Extract ID part
|
||||
IDStartKey = 'namespace'
|
||||
startLine = self._FindKeyLine(lines, IDStartKey)
|
||||
IDEndKey = '#endif'
|
||||
endLine = self._FindKeyLine(lines, IDEndKey)
|
||||
lines = lines[startLine : endLine]
|
||||
|
||||
# Use C# class for namespace
|
||||
CType = 'namespace'
|
||||
CSType = 'public class'
|
||||
self._ReplaceLineByLine(lines, CType, CSType)
|
||||
|
||||
# Replace "public class AK" with "namespace AK"
|
||||
CType = 'public class AK'
|
||||
CSType = 'namespace AK'
|
||||
self._ReplaceLineByLine(lines, CType, CSType)
|
||||
|
||||
# Replace AK type with C# types
|
||||
CType = 'static const AkUniqueID'
|
||||
CSType = 'public static uint'
|
||||
self._ReplaceLineByLine(lines, CType, CSType)
|
||||
|
||||
outDir = abspath(dirname(self.outHeader))
|
||||
if not os.path.exists(outDir):
|
||||
os.makedirs(outDir)
|
||||
self._ExportFile(self.outHeader, lines)
|
||||
|
||||
def _ImportFile(self, inputFile):
|
||||
rawLines = []
|
||||
with open(inputFile) as f:
|
||||
rawLines = f.readlines()
|
||||
f.close()
|
||||
|
||||
return rawLines
|
||||
|
||||
def _ExportFile(self, outputFile, outputLines):
|
||||
# append line separators if none
|
||||
for ll in range(len(outputLines)):
|
||||
hasNoLinebreak = outputLines[ll].find(os.linesep) == -1 and outputLines[ll].find(g_PosixLinebreak) == -1
|
||||
if hasNoLinebreak:
|
||||
outputLines[ll] += g_PosixLinebreak
|
||||
|
||||
with open(outputFile, 'w') as f:
|
||||
f.writelines(outputLines)
|
||||
f.close()
|
||||
|
||||
|
||||
def _FindKeyLine(self, lines, key):
|
||||
keyLineNumber = 0
|
||||
for ll in range(len(lines)):
|
||||
foundKey = lines[ll].find(key) != -1
|
||||
if foundKey:
|
||||
keyLineNumber = ll
|
||||
break
|
||||
return keyLineNumber
|
||||
|
||||
def _ReplaceLineByLine(self, lines, inPattern, outPattern):
|
||||
for ll in range(len(lines)):
|
||||
namespaceStartCol = lines[ll].find(inPattern)
|
||||
foundNamespace = namespaceStartCol != -1
|
||||
if foundNamespace:
|
||||
lines[ll] = lines[ll].replace(inPattern, outPattern)
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Convert Wwise SoundBank ID C++ header into C# for Unity. Generated in the same folder.')
|
||||
parser.add_argument('WwiseIDHeader', action='store', default='UndefinedHeader', help='Full path to Wwise SoundBank ID C++ header, e.g., Wwise_IDs.h')
|
||||
|
||||
args = parser.parse_args()
|
||||
inHeader = args.WwiseIDHeader
|
||||
if not exists(inHeader):
|
||||
raise RuntimeError('Input header file does not exist: {}'.format(inHeader))
|
||||
|
||||
converter = WwiseIDConverter(inHeader)
|
||||
converter.Convert()
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31d328412607d4f4c917785ed1c9bf1d
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user