Ejemplo n.º 1
0
        protected override void OnAsyncRequestUpdate(AsyncRequest request)
        {
            var result = request.result;

            string[] assetPaths = request.paths;
            for (int i = 0; i < assetPaths.Length; i++)
            {
                if (result.IsDoneAt(i))
                {
                    continue;
                }

                string    assetPath = assetPaths[i];
                AssetNode assetNode = assetNodeDic[assetPath];
                if (assetNode.IsLoaded())
                {
                    if (request.isInstance)
                    {
                        request.SetUObject(i, assetNode.CreateInstance());
                    }
                    else
                    {
                        request.SetUObject(i, assetNode.GetAsset());
                    }
                    assetNode.ReleaseRef();
                    continue;
                }
                else
                {
                    string     bundlePath = assetDetailConfig.GetBundleByPath(assetPath);
                    BundleNode bundleNode = bundleNodeDic[bundlePath];
                    if (bundleNode.IsDone && !assetOperationDic.ContainsKey(assetPath))
                    {
                        BundleAssetAsyncOperation assetOperation = assetOperationPool.Get();
                        assetOperation.DoInitilize(assetPath);
                        assetOperation.OnOperationComplete = OnAssetFromBundleCreated;

                        assetOperationDic.Add(assetPath, assetOperation);
                        operationLDic.Add(assetPath, assetOperation);
                    }
                    request.SetProgress(i, GetAsyncAssetProgress(assetPath));
                }
            }
            if (result.IsDone())
            {
                if (request.isInstance)
                {
                    request.state = RequestState.InstanceFinished;
                }
                else
                {
                    request.state = RequestState.LoadFinished;
                }
            }
        }
Ejemplo n.º 2
0
        protected override void OnAsyncRequestUpdate(AsyncRequest request)
        {
            var result = request.result;

            string[] assetPaths = request.paths;
            for (int i = 0; i < assetPaths.Length; i++)
            {
                if (result.IsDoneAt(i))
                {
                    continue;
                }

                string    assetPath = assetPaths[i];
                AssetNode assetNode = assetNodeDic[assetPath];
                if (assetNode.IsLoaded())
                {
                    if (request.isInstance)
                    {
                        request.SetUObject(i, assetNode.CreateInstance());
                    }
                    else
                    {
                        request.SetUObject(i, assetNode.GetAsset());
                    }
                    assetNode.ReleaseRef();
                    continue;
                }
                else
                {
                    if (!operationLDic.TryGetValue(assetPath, out var assetOperation))
                    {
                        assetOperation = assetOperationPool.Get();
                        assetOperation.DoInitilize(assetPath);
                        assetOperation.OnOperationComplete = OnAssetLoadCompleted;

                        operationLDic.Add(assetPath, assetOperation);
                    }

                    request.SetProgress(i, assetOperation.Progress);
                }
            }
            if (result.IsDone())
            {
                if (request.isInstance)
                {
                    request.state = RequestState.InstanceFinished;
                }
                else
                {
                    request.state = RequestState.LoadFinished;
                }
            }
        }
Ejemplo n.º 3
0
        private int RequestAssetsAsync(
            string[] addresses,
            string[] paths,
            bool isInstance,
            OnAssetProgress progressCallback,
            OnAssetComplete completeCallback,
            OnAssetsProgress progressesCallback,
            OnAssetsComplete completesCallback,
            AsyncPriority priority,
            SystemObject userdata)
        {
            int          id      = uniqueIDCreator.GetNextID();
            AsyncRequest request = requestPool.Get();

            request.id                 = id;
            request.addresses          = addresses;
            request.paths              = paths;
            request.isInstance         = isInstance;
            request.progressCallback   = progressCallback;
            request.completeCallback   = completeCallback;
            request.progressesCallback = progressesCallback;
            request.completesCallback  = completesCallback;
            request.priority           = priority;
            request.userdata           = userdata;
            request.state              = RequestState.WaitingForStart;

            AsyncResult result = resultPool.Get();

            result.DoInitialize(id, addresses);
            resultDic.Add(id, result);

            request.result = result;

            requestDic.Add(id, request);
            waitingRequestQueue.Enqueue(request, request.priority);

            return(id);
        }
Ejemplo n.º 4
0
 protected override void OnAsyncRequestCancel(AsyncRequest request)
 {
 }
Ejemplo n.º 5
0
 protected override void OnAsyncRequestEnd(AsyncRequest request)
 {
 }
Ejemplo n.º 6
0
 protected override void OnAsyncRequestStart(AsyncRequest request)
 {
 }
Ejemplo n.º 7
0
 protected abstract void OnAsyncRequestCancel(AsyncRequest request);
Ejemplo n.º 8
0
 protected abstract void OnAsyncRequestEnd(AsyncRequest request);
Ejemplo n.º 9
0
 protected abstract void OnAsyncRequestUpdate(AsyncRequest request);
Ejemplo n.º 10
0
 protected abstract void OnAsyncRequestStart(AsyncRequest request);
Ejemplo n.º 11
0
        public void DoUdpate(float deltaTime, float unscaleDeltaTime)
        {
            if (State == LoaderState.Initializing)
            {
                if (OnInitializeUpdate(deltaTime))
                {
                    if (State == LoaderState.Initialized)
                    {
                        State = LoaderState.Running;
                        initializedCallback?.Invoke(true);
                    }
                    else
                    {
                        initializedCallback?.Invoke(false);
                    }
                }
                return;
            }

            if (State != LoaderState.Running)
            {
                return;
            }

            if (operationLDic.Count > 0 && operationCount < OperationMaxCount)
            {
                int diffCount = OperationMaxCount - operationCount;
                for (int i = 0; i < operationLDic.Count; i++)
                {
                    if (!operationLDic[i].IsRunning)
                    {
                        operationLDic[i].DoStart();
                        diffCount--;
                    }
                    if (diffCount <= 0)
                    {
                        break;
                    }
                }
            }

            for (int i = runningRequestList.Count - 1; i >= 0; --i)
            {
                AsyncRequest request = runningRequestList[i];
                if (request.state == RequestState.Instancing || request.state == RequestState.Loading)
                {
                    OnAsyncRequestUpdate(request);
                }
                if (request.state == RequestState.WaitingForInstance)
                {
                    request.state = RequestState.Instancing;
                }
                else if (request.state == RequestState.LoadFinished && request.isInstance)
                {
                    request.state = RequestState.WaitingForInstance;
                }
                else if ((request.state == RequestState.LoadFinished && !request.isInstance) ||
                         (request.state == RequestState.InstanceFinished && request.isInstance))
                {
                    OnAsyncRequestEnd(request);
                    requestDic.Remove(request.id);
                    runningRequestList.RemoveAt(i);
                    resultDic.Remove(request.id);
                    resultPool.Release(request.result);
                    requestPool.Release(request);
                }
            }

            while (waitingRequestQueue.Count > 0 && (operationCount < OperationMaxCount))
            {
                AsyncRequest request = waitingRequestQueue.Dequeue();
                request.state = RequestState.Loading;

                string[] assetPaths = request.paths;
                for (int i = 0; i < assetPaths.Length; i++)
                {
                    string    assetPath = assetPaths[i];
                    AssetNode assetNode = GetAssetNodeAsync(assetPath);
                    assetNode.RetainRef();
                }

                OnAsyncRequestStart(request);

                runningRequestList.Add(request);
            }

            if (unloadOperation != null)
            {
                if (unloadOperation.isDone)
                {
                    if (OnUnloadAssetsUpdate())
                    {
                        unloadFinishedCallbacks.Clear();
                        unloadOperation = null;
                    }
                }
            }
        }