Esempio n. 1
0
        internal PlayAsyncOperation <long, AssetDeliveryErrorCode> GetDownloadSizeInternal(string assetBundleName)
        {
            var operation = new AssetDeliveryAsyncOperation <long>();

            if (IsInstallTimeAssetBundle(assetBundleName))
            {
                operation.SetResult(0L);
                return(operation);
            }

            var task = _assetPackManager.GetPackStates(assetBundleName);

            task.RegisterOnSuccessCallback(javaPackState =>
            {
                var assetPacks = new AssetPackStates(javaPackState);
                operation.SetResult(assetPacks.TotalBytes);
                task.Dispose();
            });
            task.RegisterOnFailureCallback((message, errorCode) =>
            {
                operation.SetError(PlayCoreTranslator.TranslatePlayCoreErrorCode(errorCode));
                task.Dispose();
            });
            return(operation);
        }
        /// <summary>
        /// Processes a java AssetPackStates object and invokes <see cref="OnForcedStateUpdate"/> for each pack
        /// state it contains.
        /// </summary>
        /// <param name="javaPackStates">A java object representing a AssetPackStates object.</param>
        private void ProcessPackStates(AndroidJavaObject javaPackStates)
        {
            try
            {
                var packStates = new AssetPackStates(javaPackStates);

                foreach (var packStatePair in packStates.PackStates)
                {
                    if (_stateUpdatesSinceGetPackStates.Contains(packStatePair.Key))
                    {
                        // A newer state update was received before the getPackStateTask finished.
                        // Discard this state.
                        continue;
                    }

                    OnStateUpdateEvent.Invoke(packStatePair.Value);
                }
            }
            finally
            {
                EndGetPackStates();
            }
        }