PolyToolkit.PolyApi

This is the main entry point for the Poly Toolkit Runtime API.

Summary

This class covers:

  • Authentication and properties of the signed-in user.
  • Wrappers around the Poly REST API endpoints.
  • Importing assets and thumbnails.
  • Managing the cache of assets.

Properties

AccessToken
static string
Returns the current user's access token, if a user is authenticated, or null if not.
IsAuthenticated
static bool
Returns whether or not a user is currently authenticated.
IsAuthenticating
static bool
Returns whether or not we are currently in the process of authenticating.
IsInitialized
static bool
Returns whether or not the API is initialized.
RefreshToken
static string
Returns the current user's refresh token, if a user is authenticated, or null if not.
UserIcon
static Sprite
Returns the current user's profile icon, if a user is authenticated, or null if not.
UserName
static string
Returns the current user's display name, if a user is authenticated, or null if not.

Public static functions

Authenticate(bool interactive, Action< PolyStatus > callback)
void
Attempts to authenticate a user.
Authenticate(string accessToken, string refreshToken, Action< PolyStatus > callback)
void
Alternative form of Authenticate() that allows usage of existing auth tokens.
CancelAuthentication()
void
Cancels the current authentication flow, if there's one in progress.
ClearCache()
void
Clears the local web cache.
FetchFormatFiles(PolyAsset asset, PolyFormatType format, FetchFormatFilesCallback callback)
void
Retrieves information about the given asset in the given format, then calls the given callback.
FetchThumbnail(PolyAsset asset, FetchThumbnailCallback callback)
void
Fetches the thumbnail for the given asset.
GenerateAttributions(bool includeStatic, List< PolyAsset > runtimeAssets)
string
Generates a list of attribution information of each asset passed, including the names of the authors and links to the original creations.
GetAsset(string name, GetAssetCallback callback)
void
Gets an asset by name (id).
Import(PolyAsset asset, PolyImportOptions options, ImportCallback callback)
void
Imports the given asset as a GameObject.
Init(PolyAuthConfig? authConfig, PolyCacheConfig? cacheConfig)
void
Initializes the Poly Toolkit runtime API.
ListAssets(PolyListAssetsRequest request, ListAssetsCallback callback)
void
Requests a listing of assets according to the specified parameters.
ListLikedAssets(PolyListLikedAssetsRequest request, ListAssetsCallback callback)
void
Requests a listing of liked assets according to the specified parameters.
ListUserAssets(PolyListUserAssetsRequest request, ListAssetsCallback callback)
void
Requests a listing of the logged-in user's own assets according to the specified parameters.
SignOut()
void
Signs out, deleting the current authentication token.

Public functions

FetchFormatFilesCallback(PolyAsset asset, PolyStatus status)
delegate void
Delegate type for the callback of FetchFormatFiles
FetchThumbnailCallback(PolyAsset asset, PolyStatus status)
delegate void
Delegate type for the callback of FetchThumbnail.
GetAssetCallback(PolyStatusOr< PolyAsset > result)
delegate void
Delegate type for the callback of GetAsset.
ImportCallback(PolyAsset asset, PolyStatusOr< PolyImportResult > result)
delegate void
Delegate type for the callback of Import.
ListAssetsCallback(PolyStatusOr< PolyListAssetsResult > result)
delegate void
Delegate type for the callback of ListAssets.

Properties

AccessToken

static string AccessToken

Returns the current user's access token, if a user is authenticated, or null if not.

IsAuthenticated

static bool IsAuthenticated

Returns whether or not a user is currently authenticated.

IsAuthenticating

static bool IsAuthenticating

Returns whether or not we are currently in the process of authenticating.

IsInitialized

static bool IsInitialized

Returns whether or not the API is initialized.

RefreshToken

static string RefreshToken

Returns the current user's refresh token, if a user is authenticated, or null if not.

UserIcon

static Sprite UserIcon

Returns the current user's profile icon, if a user is authenticated, or null if not.

UserName

static string UserName

Returns the current user's display name, if a user is authenticated, or null if not.

Public static functions

Authenticate

void Authenticate(
  bool interactive,
  Action< PolyStatus > callback
)

Attempts to authenticate a user.

Details
Parameters
interactive
If true, we may trigger user interaction to complete the authentication flow (for example, launching a browser to ask the user to log in). If false, we will attempt to authenticate using any existing tokens, but won't prompt the user.
callback
The callback to call with the result of the authentication.

Authenticate

void Authenticate(
  string accessToken,
  string refreshToken,
  Action< PolyStatus > callback
)

Alternative form of Authenticate() that allows usage of existing auth tokens.

Use this method only if you are implementing your own authentication/authorization flow, and need to provide Poly Toolkit with tokens to use. This method should be used INSTEAD of Authenticate() and will have the same effect, except that instead of launching the auth flow, the provided tokens will be used instead.

Details
Parameters
accessToken
The access token to use with API requests.
refreshToken
The refresh token to use with API requests.

CancelAuthentication

void CancelAuthentication()

Cancels the current authentication flow, if there's one in progress.

Does nothing if there is no authentication flow in progress.

ClearCache

void ClearCache()

Clears the local web cache.

This is asynchronous (the cache will be cleared in the background).

FetchFormatFiles

void FetchFormatFiles(
  PolyAsset asset,
  PolyFormatType format,
  FetchFormatFilesCallback callback
)

Retrieves information about the given asset in the given format, then calls the given callback.

Details
Parameters
asset
The asset for which to fetch the files.
format
The desired format.
callback
The callback to call when the fetch is complete.

FetchThumbnail

void FetchThumbnail(
  PolyAsset asset,
  FetchThumbnailCallback callback
)

Fetches the thumbnail for the given asset.

Details
Parameters
asset
The asset for which to fetch the thumbnail.
callback
The callback to call when the fetch finishes (optional).

GenerateAttributions

string GenerateAttributions(
  bool includeStatic,
  List< PolyAsset > runtimeAssets
)

Generates a list of attribution information of each asset passed, including the names of the authors and links to the original creations.

Details
Parameters
includeStatic
Indicates whether to include attribution information for assets imported into the project at edit time (recommended).
runtimeAssets
Additional assets to include attribution information for. Set this to the list of assets imported at runtime that you are using in your scene or project.

GetAsset

void GetAsset(
  string name,
  GetAssetCallback callback
)

Gets an asset by name (id).

Details
Parameters
name
The name (id) of the asset to get. Note that even though this is called 'name', it does not mean the asset's display name, but its unique ID.
callback
The callback to call when the request finishes.

Import

void Import(
  PolyAsset asset,
  PolyImportOptions options,
  ImportCallback callback
)

Imports the given asset as a GameObject.

This includes fetching any necessary files and importing them. The end result will be a GameObject that represents the imported asset. It will be placed at the origin with identity rotation and scale.

Details
Parameters
asset
The asset to import.
options
The options that control how to import the asset.
callback
The callback to call when the operation is complete (optional).

Init

void Init(
  PolyAuthConfig? authConfig,
  PolyCacheConfig? cacheConfig
)

Initializes the Poly Toolkit runtime API.

This will be called by PolyToolkitManager on its Awake method, you shouldn't need to call this method directly.

ListAssets

void ListAssets(
  PolyListAssetsRequest request,
  ListAssetsCallback callback
)

Requests a listing of assets according to the specified parameters.

Details
Parameters
request
The request parameters.
callback
The callback to call when the request finishes.

ListLikedAssets

void ListLikedAssets(
  PolyListLikedAssetsRequest request,
  ListAssetsCallback callback
)

Requests a listing of liked assets according to the specified parameters.

Currently, only the logged-in user's own likes are supported.

Details
Parameters
request
The request parameters.
callback
The callback to call when the request finishes.

ListUserAssets

void ListUserAssets(
  PolyListUserAssetsRequest request,
  ListAssetsCallback callback
)

Requests a listing of the logged-in user's own assets according to the specified parameters.

Details
Parameters
request
The request parameters.
callback
The callback to call when the request finishes.

SignOut

void SignOut()

Signs out, deleting the current authentication token.

Public functions

FetchFormatFilesCallback

delegate void FetchFormatFilesCallback(
  PolyAsset asset,
  PolyStatus status
)

Delegate type for the callback of FetchFormatFiles

Details
Parameters
asset
The asset for which we are fetching files.
status
The result of the operation.

FetchThumbnailCallback

delegate void FetchThumbnailCallback(
  PolyAsset asset,
  PolyStatus status
)

Delegate type for the callback of FetchThumbnail.

If this callback reports success, then the thumbnail will be available in the asset's PolyAsset.thumbnailTexture field.

Details
Parameters
asset
The asset to whose thumbnail we were fetching.
status
The result of the fetch.

GetAssetCallback

delegate void GetAssetCallback(
  PolyStatusOr< PolyAsset > result
)

Delegate type for the callback of GetAsset.

Details
Parameters
result

ImportCallback

delegate void ImportCallback(
  PolyAsset asset,
  PolyStatusOr< PolyImportResult > result
)

Delegate type for the callback of Import.

Details
Parameters
asset
The asset to which the import operation pertains.
result
The result of the operation.

ListAssetsCallback

delegate void ListAssetsCallback(
  PolyStatusOr< PolyListAssetsResult > result
)

Delegate type for the callback of ListAssets.

Details
Parameters
result