//设置ID public static void SetId(AssetOperation assetOp) { assetOp.id = M_ID; M_ID++; if (M_ID == int.MaxValue) { M_ID = 1; } }
/// <summary> /// 加载资源 /// </summary> /// <param name="CRequest">request</param> /// <param name="bool">async = true 异步加载</param> /// <returns></returns> static int LoadAsset(CRequest request, bool async = true, bool subAssets = false) { totalCount++; //count ++ if (m_MarkGroup) { m_Groupes.Add(request); m_TotalGroupCount++; } int opID = 0; LoadAssetBundle(request.assetBundleName, async); #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { AssetOperationSimulation assetOperS = OperationPools <AssetOperationSimulation> .Get(); assetOperS.request = request; assetOperS.subAssets = subAssets; assetOperS.StartSync(); assetOperS.ReleaseToPool(); DispatchReqAssetOperation(request, request.error != null, 0, false); //模拟器模式下只有同步所以需要调用回调 CheckAllComplete(); } else #endif { var assetOper = OperationPools <AssetOperation> .Get(); assetOper.request = request; assetOper.subAssets = subAssets; if (async) //如果异步加载 设置id可以阻止回调 { AssetOperation.SetId(assetOper); opID = assetOper.id; completeOper.Add(opID); } if (!async) //同步加载 { assetOper.StartSync(); assetOper.ReleaseToPool(); } // else if (inProgressOperations.Count >= maxLoading) //如果大于最大值 // { // waitOperations.Enqueue(assetOper); //放入等待列表 // } else { inProgressOperations.Add(assetOper); } // Debug.LogFormat("LoadAsset({0},{1},{2})", opID, request.assetBundleName,request.assetName); } return(opID); }
static int LoadSceneAsset(CRequest request, bool allowSceneActivation = true, LoadSceneMode loadSceneMode = LoadSceneMode.Additive) { totalCount++; //count ++ LoadAssetBundle(request.assetBundleName); int opID = 0; #if UNITY_EDITOR if (SimulateAssetBundleInEditor) { var assetOper = OperationPools <AssetOperationSimulation> .Get(); assetOper.request = request; assetOper.loadSceneMode = loadSceneMode; assetOper.allowSceneActivation = allowSceneActivation; assetOper.Update(); AssetOperation.SetId(assetOper); opID = assetOper.id; completeOper.Add(opID); if (inProgressOperations.Count >= maxLoading) //如果大于最大值 { waitOperations.Enqueue(assetOper); //放入等待列表 } else { inProgressOperations.Add(assetOper); } } else #endif { AssetOperation assetOper = OperationPools <AssetOperation> .Get(); assetOper.request = request; assetOper.loadSceneMode = loadSceneMode; assetOper.allowSceneActivation = allowSceneActivation; AssetOperation.SetId(assetOper); opID = assetOper.id; completeOper.Add(opID); if (inProgressOperations.Count >= maxLoading) //如果大于最大值 { waitOperations.Enqueue(assetOper); //放入等待列表 } else { inProgressOperations.Add(assetOper); } } // Debug.LogFormat("LoadSceneAsset({0},{1})", opID, request.assetBundleName); return(opID); }