コード例 #1
0
        public static IProgressResult <float> LoadAssetBundle(this ArchiveContainer container, params string[] filenames)
        {
            return(EditorExecutors.RunAsync(new Action <IProgressPromise <float> >((promise) =>
            {
                try
                {
                    int taskCount = 8;
                    int index = -1;
                    int finishedCount = 0;
                    int count = filenames.Length;
                    CountFinishedEvent countFinishedEvent = new CountFinishedEvent(taskCount);
                    for (int i = 0; i < taskCount; i++)
                    {
                        EditorExecutors.RunAsyncNoReturn(() =>
                        {
                            while (true)
                            {
                                int currIndex = Interlocked.Increment(ref index);
                                if (currIndex > count - 1)
                                {
                                    break;
                                }

                                try
                                {
                                    container.LoadAssetBundle(filenames[currIndex]);
                                }
                                catch (Exception e)
                                {
                                    Debug.LogErrorFormat("{0}", e);
                                }
                                finally
                                {
                                    Interlocked.Increment(ref finishedCount);
                                }
                            }
                            countFinishedEvent.Set();
                        });
                    }

                    while (!countFinishedEvent.Wait(100))
                    {
                        promise.UpdateProgress((float)finishedCount / count);
                    }

                    promise.SetResult();
                }
                catch (Exception e)
                {
                    promise.SetException(e);
                }
            })));
        }
コード例 #2
0
        public static IProgressResult <float> LoadAssetBundle(this ArchiveContainer container, string root, IStreamDecryptor decryptor, params BundleInfo[] bundleInfos)
        {
            return(EditorExecutors.RunAsync(new Action <IProgressPromise <float> >((promise) =>
            {
                try
                {
                    int taskCount = 8;
                    int index = -1;
                    int finishedCount = 0;
                    int count = bundleInfos.Length;
                    CountFinishedEvent countFinishedEvent = new CountFinishedEvent(taskCount);
                    for (int i = 0; i < taskCount; i++)
                    {
                        EditorExecutors.RunAsyncNoReturn(() =>
                        {
                            while (true)
                            {
                                int currIndex = Interlocked.Increment(ref index);
                                if (currIndex > count - 1)
                                {
                                    break;
                                }

                                try
                                {
                                    var bundleInfo = bundleInfos[currIndex];
                                    var path = System.IO.Path.Combine(root, bundleInfo.Filename.Replace("/", @"\"));
                                    if (bundleInfo.IsEncrypted)
                                    {
                                        container.LoadAssetBundle(path, decryptor);
                                    }
                                    else
                                    {
                                        container.LoadAssetBundle(path);
                                    }
                                }
                                catch (Exception e)
                                {
                                    Debug.LogErrorFormat("{0}", e);
                                }
                                finally
                                {
                                    Interlocked.Increment(ref finishedCount);
                                }
                            }
                            countFinishedEvent.Set();
                        });
                    }

                    while (!countFinishedEvent.Wait(100))
                    {
                        promise.UpdateProgress((float)finishedCount / count);
                    }

                    promise.SetResult();
                }
                catch (Exception e)
                {
                    promise.SetException(e);
                }
            })));
        }