IEnumerator LoadAndCacheBuiltin(BuiltinVoosAsset asset) { ResourceRequest request = Resources.LoadAsync <GameObject>(asset.resourcePath); yield return(request); Debug.Assert(request.isDone); Debug.Assert(request.asset != null, $"Failed to load builtin asset resource {asset.resourcePath}"); GameObject loadedAsset = GameObject.Instantiate((GameObject)request.asset); string uri = asset.GetUri(); Texture2D thumbnail; const string BUILTIN_ASSETS_PREFIX = "builtin:BuiltinAssets/"; // We should find a less hacky way to do this. if (asset.GetUri() == VoosActor.AVATAR_EXPLORER_URI) { thumbnail = cache.playerThumbnail; } else if (uri.ToLowerInvariant().StartsWith(BUILTIN_ASSETS_PREFIX.ToLowerInvariant())) { // It's a built-in asset. string builtinId = uri.Substring(BUILTIN_ASSETS_PREFIX.Length); if (cache.builtinPrefabLibrary.PrefabExists(builtinId)) { // Corresponds to an existing prefab, so use the prefab's thumbnail. thumbnail = cache.builtinPrefabLibrary.Get(builtinId).GetThumbnail(); } else { // Some built-in assets don't correspond to prefabs. In that case don't use a thumbnail. // Warn anyway... Debug.LogWarning($"No thumbnail for built-in asset: {uri}. It does not correspond to an actor prefab."); thumbnail = null; } } else { Debug.LogError("No idea where to get thumbnail for " + uri); thumbnail = null; } cache.CreateCacheEntry(uri, loadedAsset, thumbnail); }
public void Visit(BuiltinVoosAsset asset) { cache.StartCoroutine(LoadAndCacheBuiltin(asset)); }