Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nekomimi-daimao
Last active April 23, 2019 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nekomimi-daimao/b6695e6974af4b8bf53723ceaaef9be0 to your computer and use it in GitHub Desktop.
Save nekomimi-daimao/b6695e6974af4b8bf53723ceaaef9be0 to your computer and use it in GitHub Desktop.
using System;
using System.Threading.Tasks;
using PolyToolkit;
using UnityEngine;
namespace NekomimiDaimao.Poly
{
public static class PolyTasker
{
public static Task<PolyListAssetsResult> SearchListAssetsAsync(PolyListAssetsRequest assetsRequest)
{
var tcs = new TaskCompletionSource<PolyListAssetsResult>();
PolyApi.ListAssets(assetsRequest, result =>
{
if (result.Ok)
{
tcs.SetResult(result.Value);
}
else
{
tcs.SetException(new Exception(result.Status.errorMessage));
}
});
return tcs.Task;
}
public static Task<PolyListAssetsResult> SearchUserListAssetsAsync(PolyListUserAssetsRequest assetsRequest)
{
var tcs = new TaskCompletionSource<PolyListAssetsResult>();
PolyApi.ListUserAssets(assetsRequest, result =>
{
if (result.Ok)
{
tcs.SetResult(result.Value);
}
else
{
tcs.SetException(new Exception(result.Status.errorMessage));
}
});
return tcs.Task;
}
public static Task<PolyListAssetsResult> SearchLikedListAssetsAsync(PolyListLikedAssetsRequest assetsRequest)
{
var tcs = new TaskCompletionSource<PolyListAssetsResult>();
PolyApi.ListLikedAssets(assetsRequest, result =>
{
if (result.Ok)
{
tcs.SetResult(result.Value);
}
else
{
tcs.SetException(new Exception(result.Status.errorMessage));
}
});
return tcs.Task;
}
public static Task<PolyAsset> FetchThumbnailAsync(PolyAsset asset, PolyFetchThumbnailOptions options)
{
var tcs = new TaskCompletionSource<PolyAsset>();
PolyApi.FetchThumbnail(asset, options, (polyAsset, status) =>
{
if (status.ok)
{
tcs.SetResult(polyAsset);
}
else
{
tcs.SetException(new Exception(status.errorMessage));
}
});
return tcs.Task;
}
public static Task<PolyAsset> GetAssetAsync(string name)
{
var tcs = new TaskCompletionSource<PolyAsset>();
PolyApi.GetAsset(name, result =>
{
if (result.Ok)
{
tcs.SetResult(result.Value);
}
else
{
tcs.SetException(new Exception(result.Status.errorMessage));
}
});
return tcs.Task;
}
public static Task<(GameObject obj, PolyAsset polyAsset)> ImportAsync(PolyAsset asset, PolyImportOptions? options = null)
{
var tcs = new TaskCompletionSource<(GameObject obj, PolyAsset polyAsset)>();
PolyApi.Import(asset, options ?? PolyImportOptions.Default(), (polyAsset, result) =>
{
if (result.Ok)
{
tcs.SetResult((result.Value.gameObject, polyAsset));
}
else
{
tcs.SetException(new Exception(result.Status.errorMessage));
}
});
return tcs.Task;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment