/// <summary> /// Called when sign in finishes. /// </summary> /// <param name="wasInteractive">If true, this was the interactive (browser-based) sign-in flow.</param> /// <param name="status">The result of the sign in process.</param> private void OnSignInFinished(bool wasInteractive, PolyStatus status) { if (status.ok) { string tok = PolyApi.AccessToken; PtDebug.LogFormat("ABM: Sign in success. Access token: {0}", (tok != null && tok.Length > 6) ? tok.Substring(0, 6) + "..." : "INVALID"); PtAnalytics.SendEvent(PtAnalytics.Action.ACCOUNT_SIGN_IN_SUCCESS); } else if (wasInteractive) { Debug.LogErrorFormat("Failed to sign in. Please try again: " + status); PtAnalytics.SendEvent(PtAnalytics.Action.ACCOUNT_SIGN_IN_FAILURE, status.ToString()); } if (null != refreshCallback) { refreshCallback(); } // If we had a deferred request that was waiting for auth, send it now. if (requestToSendAfterAuth != null) { PtDebug.Log("Sending deferred request that was waiting for auth."); PolyRequest request = requestToSendAfterAuth; requestToSendAfterAuth = null; StartRequest(request); } }
public AssetBrowserManager() { PtDebug.Log("ABM initializing..."); EnsurePolyIsReady(); // Initially, show the featured assets home page. StartRequest(PolyListAssetsRequest.Featured()); }
/// <summary> /// Clears the current request. Also cancels any pending request. /// </summary> public void ClearRequest() { PtDebug.Log("ABM: clearing request..."); querying = false; // Increasing the ID will cause us to ignore the results of any pending requests // (we will know they are obsolete by their query ID). queryId++; listAssetsResult = null; resultHasMorePages = false; }
/// <summary> /// Get the next page of assets from the current request. /// </summary> public void GetNextPageRequest() { PtDebug.Log("ABM: getting next page of current request..."); if (CurrentResult == null || !CurrentResult.Ok) { Debug.LogError("Request failed, no valid current result to get next page of."); } currentRequest.pageToken = CurrentResult.Value.nextPageToken; StartRequest(currentRequest, OnNextPageRequestResult); }
/// <summary> /// Parses a single asset. /// </summary> public static PolyStatus ParseAsset(JObject asset, out PolyAsset polyAsset) { polyAsset = new PolyAsset(); if (asset["visibility"] == null) { return(PolyStatus.Error("Asset has no visibility set.")); } polyAsset.name = asset["name"].ToString(); polyAsset.authorName = asset["authorName"].ToString(); if (asset["thumbnail"] != null) { var thumbnailElements = asset["thumbnail"].ToObject <JObject>(); //IJEnumerable<JToken> thumbnailElements = asset["thumbnail"].AsJEnumerable(); polyAsset.thumbnail = new PolyFile(thumbnailElements["relativePath"].ToString(), thumbnailElements["url"].ToString(), thumbnailElements["contentType"].ToString()); } if (asset["formats"] == null) { Debug.LogError("No formats found"); } else { foreach (var format in asset["formats"].ToObject <List <JObject> >()) //foreach (JToken format in asset["formats"]) { PolyFormat newFormat = ParseAssetsPackage(format); newFormat.formatType = ParsePolyFormatType(format["formatType"]); if (newFormat.formatType == PolyFormatType.UNKNOWN) { PtDebug.Log("Did not recognize format type: " + format["formatType"].ToString()); } polyAsset.formats.Add(newFormat); } } polyAsset.displayName = asset["displayName"].ToString(); polyAsset.createTime = DateTime.Parse(asset["createTime"].ToString()); polyAsset.updateTime = DateTime.Parse(asset["updateTime"].ToString()); polyAsset.visibility = ParsePolyVisibility(asset["visibility"]); polyAsset.license = ParsePolyAssetLicense(asset["license"]); if (asset["isCurated"] != null) { polyAsset.isCurated = bool.Parse(asset["isCurated"].ToString()); } return(PolyStatus.Success()); }
/// <summary> /// Because Poly doesn't live in the Editor/ space (and couldn't, since it uses GameObjects and /// MonoBehaviours), it will die every time the user enters or exits play mode. This means /// that all of its state and objects will get wiped. So we have to check if it needs initialization /// every time we need to use it. /// </summary> public void EnsurePolyIsReady() { if (!PolyApi.IsInitialized) { PtDebug.Log("ABM: Initializing Poly."); // We need to set a service name for our auth config because we want to keep our auth credentials // separate in a different "silo", so they don't get confused with the runtime credentials // the user might be using in their project. Regular users would not set a service name, so they // use the default silo. authConfig.serviceName = "PolyToolkitEditor"; PolyApi.Init(authConfig, cacheConfig); waitingForSilentAuth = true; //PolyApi.Authenticate(interactive: false, callback: (PolyStatus status) => { // waitingForSilentAuth = false; // OnSignInFinished(/* wasInteractive */ false, status); //}); } }
public AssetBrowserManager(PolyRequest request) { PtDebug.Log("ABM initializing..."); EnsurePolyIsReady(); // If this is a request that needs authentication and we are in the process of authenticating, // wait until we're finished. bool needAuth = request is PolyListLikedAssetsRequest || request is PolyListUserAssetsRequest; if (needAuth && waitingForSilentAuth) { // Defer the request. Wait until auth is complete. PtDebug.Log("ABM: Deferring request until after auth."); requestToSendAfterAuth = request; return; } StartRequest(request); }
/// <summary> /// Callback invoked when we receive the result of a request for a specific asset. /// </summary> private void OnRequestForSpecificAssetResult(PolyStatusOr <PolyAsset> result) { if (result.Ok) { PtDebug.Log("ABM: get asset request received result."); assetResult = result.Value; if (!thumbnailCache.TryGet(assetResult.name, out assetResult.thumbnailTexture)) { PolyApi.FetchThumbnail(assetResult, OnThumbnailFetched); } } else { Debug.LogError("Error: " + result.Status.errorMessage); } querying = false; if (null != refreshCallback) { refreshCallback(); } }