ソースコード
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
public class Example : MonoBehaviour
{
private static readonly string[] ERROR_MESSAGES =
{
"JSON parse error: The document root must not follow by other values.",
"Unable to load asset of type UnityEngine.AddressableAssets.ResourceLocators.ContentCatalogData from location",
"Unknown error in AsyncOperation : Resource<ContentCatalogData>",
"Unable to load ContentCatalogData from location",
"GroupOperation failed because one of its dependencies failed",
};
private async void Start()
{
await Addressables.InitializeAsync().Task;
await UpdateCatalogs();
}
private static async Task UpdateCatalogs()
{
var isBrokenRemoteCatalog = false;
void OnLogMessageReceivedThreaded( string condition, string trace, LogType type )
{
if ( isBrokenRemoteCatalog ) return;
if ( type == LogType.Log || type == LogType.Warning ) return;
isBrokenRemoteCatalog = ERROR_MESSAGES.Any( x => condition.Contains( x ) );
Application.logMessageReceivedThreaded -= OnLogMessageReceivedThreaded;
}
Application.logMessageReceivedThreaded += OnLogMessageReceivedThreaded;
var result = Addressables.UpdateCatalogs();
await result.Task;
Application.logMessageReceivedThreaded -= OnLogMessageReceivedThreaded;
if ( isBrokenRemoteCatalog )
{
Debug.LogError( "リモートカタログのファイルが破損している" );
return;
}
Debug.Log( "成功" );
}
}