ソースコード
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
public class Example : MonoBehaviour
{
private static readonly string[] ERROR_MESSAGES =
{
"CheckCatalogsOperation failed with the following errors: ",
"TextDataProvider : unable to load from url : ",
"Content update not available.",
"ChainOperation failed because dependent operation failed",
};
private async void Start()
{
await Addressables.InitializeAsync().Task;
await UpdateCatalogs();
}
private static async Task UpdateCatalogs()
{
var isCommunicationError = false;
void OnLogMessageReceivedThreaded( string condition, string trace, LogType type )
{
if ( isCommunicationError ) return;
if ( type == LogType.Log || type == LogType.Warning ) return;
isCommunicationError = ERROR_MESSAGES.Any( x => condition.Contains( x ) );
Application.logMessageReceivedThreaded -= OnLogMessageReceivedThreaded;
}
Application.logMessageReceivedThreaded += OnLogMessageReceivedThreaded;
var result = Addressables.UpdateCatalogs();
await result.Task;
Application.logMessageReceivedThreaded -= OnLogMessageReceivedThreaded;
if ( isCommunicationError )
{
Debug.LogError( "通信に失敗しました" );
return;
}
Debug.Log( "成功" );
}
}