概要
using System;
using System.Text.RegularExpressions;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement;
using UnityEngine.ResourceManagement.AsyncOperations;
internal sealed class Example : MonoBehaviour
{
private static readonly Regex REGEX = new Regex( "Key=(.*), Type=(.*)" );
private void Start()
{
Addressables.InstantiateAsync( "【存在しないパスを指定】" );
ResourceManager.ExceptionHandler = Handler;
}
private void Handler( AsyncOperationHandle handle, Exception exception )
{
var message = exception.Message;
void Log() => Debug.Log( message );
if ( !message.Contains( "'UnityEngine.AddressableAssets.InvalidKeyException'" ) )
{
Log();
return;
}
var match = REGEX.Match( message );
if ( !match.Success )
{
Log();
return;
}
var groups = match.Groups;
var key = groups[ 1 ].Value;
var type = groups[ 2 ].Value;
Debug.Log( $"{key} が見つかりませんでした。({type} 型)" );
}
}