Exemple #1
0
    void LoadAssetsFromPack(PlayAssetPackRequest packRequest)
    {
        var discreteAssets =
            gameAssetManager.GetDiscreteAssetNameList();

        foreach (string discreteAsset in discreteAssets)
        {
            var assetLocation = packRequest.GetAssetLocation(
                discreteAsset);
            if (assetLocation != null)
            {
                long assetSize       = (long)assetLocation.Size;
                long assetOffset     = (long)assetLocation.Offset;
                var  assetFileStream = File.OpenRead(assetLocation.Path);
                var  assetBuffer     = new byte[assetSize];
                assetFileStream.Seek(assetOffset, SeekOrigin.Begin);
                assetFileStream.Read(assetBuffer, 0, assetBuffer.Length);
                Debug.Log("Finished discrete load of " + discreteAsset);
                // The asset is a raw .jpg or .png, convert to a sprite
                gameAssetManager.AddSpriteAsset(discreteAsset,
                                                GameAssetManager.GenerateSpriteFromRawImage(
                                                    assetBuffer));
            }
        }
    }
        /// <summary>
        /// Display the contents of the asset located at <see cref="TextAssetPath"/> as text.
        /// </summary>
        public void ButtonEventDisplayTextAsset()
        {
            if (_request == null || _requestInProgress)
            {
                return;
            }

            var assetLocation   = _request.GetAssetLocation(TextAssetPath);
            var assetFileStream = File.OpenRead(assetLocation.Path);
            var buffer          = new byte[assetLocation.Size];

            assetFileStream.Seek((long)assetLocation.Offset, SeekOrigin.Begin);
            assetFileStream.Read(buffer, /* offset= */ 0, buffer.Length);
            var fileContents = Encoding.UTF8.GetString(buffer, 0, buffer.Length);

            DisplayTextBox.text = string.Format("Contents of file {0}: {1}", TextAssetPath, fileContents);
        }
Exemple #3
0
        private void BeginOperation(string assetPackName)
        {
            Debug.LogFormat("[{0}.{1}] assetPackName={2}", nameof(AssetPackBundleSyncResource), nameof(BeginOperation), assetPackName);
            playAssetPackRequest = PlayAssetDelivery.RetrieveAssetPackAsync(assetPackName);
            Exception exception = null;

            if (playAssetPackRequest.IsDone)
            {
                var assetLocation = playAssetPackRequest.GetAssetLocation(assetPackName);
                assetBundle = AssetBundle.LoadFromFile(assetLocation.Path, /* crc= */ 0, assetLocation.Offset);
            }
            else
            {
                exception = new Exception($"Asset Pack was not retrieved Synchronously: '{assetPackName}'.");
            }
            CompletedEvent?.Invoke(this, assetBundle != null, exception);
        }
        private void OnPlayAssetPackRequestCompleted(string assetPackName, PlayAssetPackRequest request)
        {
            if (request.Error != AssetDeliveryErrorCode.NoError)
            {
                CompletedEvent?.Invoke(this, false, new Exception($"Error downloading error pack: {request.Error}"));
                return;
            }
            if (request.Status != AssetDeliveryStatus.Available)
            {
                CompletedEvent?.Invoke(this, false, new Exception($"Error downloading status: {request.Status}"));
                return;
            }
            var assetLocation = request.GetAssetLocation(assetPackName);

            requestOperation            = AssetBundle.LoadFromFileAsync(assetLocation.Path, /* crc= */ 0, assetLocation.Offset);
            requestOperation.completed += LocalRequestOperationCompleted;
        }
Exemple #5
0
        private void OnPlayAssetPackRequestCompleted(string assetPackName, PlayAssetPackRequest request)
        {
            if (request.Error != AssetDeliveryErrorCode.NoError)
            {
                CompleteOperation(this, $"Error downloading error pack: {request.Error}");
                return;
            }
            if (request.Status != AssetDeliveryStatus.Available)
            {
                CompleteOperation(this, $"Error downloading status: {request.Status}");
                return;
            }
            var assetLocation = request.GetAssetLocation(assetPackName);

            m_RequestOperation = AssetBundle.LoadFromFileAsync(assetLocation.Path, /* crc= */ 0, assetLocation.Offset);
            if (m_RequestOperation.isDone)
            {
                LocalMRequestOperationCompleted(m_RequestOperation);
                return;
            }
            m_RequestOperation.completed += LocalMRequestOperationCompleted;
        }