示例#1
0
        public override AssetRequest <TAsset> LoadAsync <TAsset>(string deviceList, ref ContentManifest.AssetEntry entry, AssetLoadedHandler <TAsset> handler = null)
        {
            AssetRequestWrapper <TAsset> request           = new AssetRequestWrapper <TAsset>(null);
            AsyncAssetRequest <TAsset>   asyncAssetRequest = new AsyncAssetRequest <TAsset>(entry.Key, request);

            CoroutineRunner.StartPersistent(waitForFileStreamAssetToLoad(asyncAssetRequest, entry.AssetPath, handler), this, "waitForFileStreamAssetToLoad");
            return(asyncAssetRequest);
        }
示例#2
0
        private IEnumerator waitForTextAssetToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, AssetRequest <TextAsset> textRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class
        {
            yield return(textRequest);

            byte[] bytes = textRequest.Asset.bytes;
            assetRequest.Request = new IndexedAssetRequest <TAsset>(key, (TAsset)(object)bytes);
            yield return(assetRequest);

            handler?.Invoke(key, (TAsset)(object)bytes);
        }
示例#3
0
        private IEnumerator waitForStringToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, AssetRequest <string> stringRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class
        {
            yield return(stringRequest);

            string      jsonString = stringRequest.Asset;
            JsonService json       = Service.Get <JsonService>();
            TAsset      jsonAsset  = json.Deserialize <TAsset>(jsonString);

            assetRequest.Request = new IndexedAssetRequest <TAsset>(key, jsonAsset);
            handler?.Invoke(key, jsonAsset);
        }
        private IEnumerator waitForFileStreamAssetToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class
        {
            string fileText;

            using (StreamReader streamReader = new StreamReader(key))
            {
                fileText = streamReader.ReadToEnd();
            }
            assetRequest.Request = new IndexedAssetRequest <TAsset>(key, (TAsset)(object)fileText);
            yield return(assetRequest);

            handler?.Invoke(key, (TAsset)(object)fileText);
        }
示例#5
0
        private IEnumerator waitForFileStreamAssetToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, string key, AssetLoadedHandler <TAsset> handler) where TAsset : class
        {
            FileStream fileStream = new FileStream(key, FileMode.Open, FileAccess.Read, FileShare.Read, 1024, useAsync: true);

            byte[] bytes;
            try
            {
                bytes = new byte[fileStream.Length];
                IAsyncResult asyncResult = fileStream.BeginRead(bytes, 0, bytes.Length, null, null);
                while (!asyncResult.IsCompleted)
                {
                    yield return(null);
                }
                fileStream.EndRead(asyncResult);
            }
            finally
            {
                fileStream.Close();
            }
            assetRequest.Request = new IndexedAssetRequest <TAsset>(key, (TAsset)(object)bytes);
            yield return(assetRequest);

            handler?.Invoke(key, (TAsset)(object)bytes);
        }
 private IEnumerator waitForAssetToLoad <TAsset>(AsyncAssetRequest <TAsset> assetRequest, string key, string assetPath, AssetLoadedHandler <TAsset> handler) where TAsset : class
 {
     yield return(null);
 }