Esempio n. 1
0
 /// <summary>
 /// Returns a PolyFormat of the given type, if it exists.
 /// If the asset has more than one format of the given type, returns the first one seen.
 /// If the asset does not have a format of the given type, returns null.
 /// </summary>
 public PolyFormat GetFormatIfExists(PolyFormatType type)
 {
     foreach (PolyFormat format in formats)
     {
         if (format == null)
         {
             continue;
         }
         if (format.formatType == type)
         {
             return(format);
         }
     }
     return(null);
 }
Esempio n. 2
0
        public void FetchFormatFiles(PolyAsset asset, PolyFormatType formatType,
                                     PolyApi.FetchFormatFilesCallback completionCallback, FetchProgressCallback progressCallback = null)
        {
            PolyUtils.AssertNotNull(asset, "Asset can't be null.");
            PolyUtils.AssertNotNull(formatType, "formatType can't be null.");
            PolyFormat packageToFetch = asset.GetFormatIfExists(formatType);

            if (packageToFetch == null)
            {
                if (completionCallback != null)
                {
                    completionCallback(asset, PolyStatus.Error("Format type not present in asset"));
                }
                return;
            }

            PolyUtils.AssertNotNull(packageToFetch.root, "packageToFetch.root can't be null.");
            PolyUtils.AssertNotNull(packageToFetch.root.url, "packageToFetch.root.url can't be null.");
            PolyUtils.AssertNotNull(packageToFetch.resources, "packageToFetch.resources can't be null.");

            string accessToken = GetAccessToken();

            FetchOperationState state = new FetchOperationState();

            state.asset = asset;
            state.completionCallback  = completionCallback;
            state.progressCallback    = progressCallback;
            state.packageBeingFetched = packageToFetch;

            // Indicates how many files are pending download (1 for main file + 1 for each resource).
            state.totalFiles = state.pendingFiles = 1 + packageToFetch.resources.Count;

            // Note that the callbacks are asynchronous so they may complete in any order.  What we do know is that they
            // will all be called on the main thread, so they won't be called concurrently.

            long maxCacheAge = asset.IsMutable ? MUTABLE_ASSET_MAX_CACHE_AGE : IMMUTABLE_ASSET_MAX_CACHE_AGE;

            PolyClientUtils.GetRawFileBytes(packageToFetch.root.url, accessToken, maxCacheAge,
                                            (PolyStatus status, byte[] data) => { ProcessFileFetchResult(state, ROOT_FILE_INDEX, status, data); });

            for (int i = 0; i < packageToFetch.resources.Count; i++)
            {
                int thisIndex = i; // copy of variable, for closure below.
                PolyClientUtils.GetRawFileBytes(packageToFetch.resources[i].url, accessToken, maxCacheAge,
                                                (status, data) => { ProcessFileFetchResult(state, thisIndex, status, data); });
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Retrieves information about the given asset in the given format, then calls the given callback.
 /// </summary>
 /// <param name="asset">The asset for which to fetch the files.</param>
 /// <param name="format">The desired format.</param>
 /// <param name="callback">The callback to call when the fetch is complete.</param>
 public static void FetchFormatFiles(PolyAsset asset, PolyFormatType format, FetchFormatFilesCallback callback)
 {
     CheckInitialized();
     PolyMainInternal.Instance.FetchFormatFiles(asset, format, callback);
 }