コード例 #1
0
    /// <summary>
    /// 检测加载回调
    /// </summary>
    private static void CheckLoad()
    {
        List <LoadAssetInfo> loadAssetInfoList = GetLoadAssetStateList(LoadAssetStep.Loading);

        if (loadAssetInfoList.Count == 0)
        {
            return;
        }

        foreach (LoadAssetInfo loadAssetInfo in loadAssetInfoList)
        {
            AssetBundleRequest request = loadAssetInfo.request;
            if (request == null)
            {
                continue;
            }
            if (!request.isDone)
            {
                continue;
            }

            Object asset = request.asset;
            if (asset == null)
            {
                continue;
            }

            // 资源加载成功 进入等待回调状态
            string assetInBundleName = BundleAsset.GetAssetInBundleName(loadAssetInfo.assetName);
            if (asset.name == assetInBundleName)
            {
                ReferenceObject.AddObject(loadAssetInfo.assetName, asset);
                loadAssetInfo.asset = asset;
                EnterWaitCall(loadAssetInfo);
                // 加载成功一个资源之后 从等待列表中释放一个 维持每帧加载上线
                List <LoadAssetInfo> loadWaitAssetList = GetLoadAssetStateList(LoadAssetStep.LoadWait);
                if (loadWaitAssetList.Count > 0)
                {
                    LoadAssetAsync(loadWaitAssetList[0]);
                }
                break;
            }
        }
    }