ソースコード
using System.Linq;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.AddressableAssets;
public class Example : MonoBehaviour
{
private static readonly string[] ERROR_MESSAGES =
{
"RuntimeData is null. Please ensure you have built the correct Player Content.",
"Invalid path in TextDataProvider : ",
"Unable to load ContentCatalogData from location ",
"Failed to load content catalog.",
"OperationException : ChainOperation failed because dependent operation failed",
};
private async void Start()
{
await InitializeAsync();
}
private static async Task InitializeAsync()
{
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.InitializeAsync();
await result.Task;
Application.logMessageReceivedThreaded -= OnLogMessageReceivedThreaded;
if ( isCommunicationError )
{
Debug.LogError( "ローカルカタログの読み込みに失敗しました" );
return;
}
Debug.Log( "成功" );
}
}