예제 #1
0
        public void LoadAsync(string assetName, Type assetType, IResourcesListener listener)
        {
            //资源正在被加载,还没加载完
            foreach (var item in loadingList)
            {
                if (item.AssetName == assetName)
                {
                    item.AddListener(listener);
                    return;
                }
            }

            //等待的队列里有
            foreach (var item in waitingQue)
            {
                if (item.AssetName == assetName)
                {
                    item.AddListener(listener);
                    return;
                }
            }

            //都没有,先创建
            LoadAssets asset = new LoadAssets();

            asset.AssetName = assetName;
            asset.AssetType = assetType;
            asset.AddListener(listener);
            //添加到等待队列
            waitingQue.Enqueue(asset);
        }
예제 #2
0
        private void Update()
        {
            if (loadingList.Count > 0)
            {
                for (int i = 0; i < loadingList.Count; i++)
                {
                    if (loadingList[i].IsDone)
                    {
                        LoadAssets asset = loadingList[i];
                        for (int j = 0; j < asset.Listeners.Count; j++)
                        {
                            asset.Listeners[j].OnLoaded(asset.AssetName, asset.GetAsset);
                        }
                        loadingList.RemoveAt(i);
                    }
                }
            }

            while (waitingQue.Count > 0 && loadingList.Count < maxLoadNum)
            {
                LoadAssets asset = waitingQue.Dequeue();
                loadingList.Add(asset);
                asset.LoadAsync();
            }
        }