Last active
April 23, 2019 14:03
-
-
Save nekomimi-daimao/b6695e6974af4b8bf53723ceaaef9be0 to your computer and use it in GitHub Desktop.
wrapper for https://developers.google.com/poly/develop/toolkit-unity https://qiita.com/nekomimi-daimao/items/e3332b1af52c390987da
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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