internal static bool SetRequestDataFromPrefab(CRequest req) { // if (CResLoader.SimulateAssetBundleInEditor) { if (!req.isAssetBundle) { return(false); } // Debug.Log("SetRequestDataFromPrefab \"" + req.assetName + "\" in " + req.assetBundleName); System.Type assetType = req.assetType; if (assetType == null) { assetType = Typeof_Object; } if (Typeof_ABScene.Equals(assetType)) { string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(req.assetBundleName, req.assetName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + req.assetName + "\" in " + req.assetBundleName); return(false); } if (req.isAdditive) { req.assetBundleRequest = UnityEditor.EditorApplication.LoadLevelAdditiveAsyncInPlayMode(levelPaths[0]); } else { req.assetBundleRequest = UnityEditor.EditorApplication.LoadLevelAsyncInPlayMode(levelPaths[0]); } } else { string[] assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(req.assetBundleName, req.assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + req.assetName + "\" in " + req.assetBundleName); return(false); } bool loadAll = Typeof_ABAllAssets.Equals(assetType); object data = null; List <UnityEngine.Object> datas = null; foreach (var p in assetPaths) { if (loadAll) { // data UnityEngine.Object[] target = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(p); if (datas == null) { datas = new List <UnityEngine.Object> (); datas.AddRange(target); } else { datas.AddRange(target); } data = datas.ToArray(); } else { UnityEngine.Object target = UnityEditor.AssetDatabase.LoadAssetAtPath(p, assetType); if (target) { data = target; break; } } } req.data = data; } return(true); // } }
/// <summary> /// 从缓存设置数据 /// </summary> /// <param name="req"></param> internal static bool SetRequestDataFromCache(CRequest req) { bool re = false; int keyhash = req.keyHashCode; CacheData cachedata = GetCache(keyhash); if (cachedata != null) { AssetBundle abundle = cachedata.assetBundle; System.Type assetType = req.assetType; if (assetType == null) { assetType = Typeof_Object; } if (req.isShared) //共享的 { req.data = abundle; re = true; } else if (Typeof_AssetBundle.Equals(assetType)) { req.data = cachedata.assetBundle; re = true; } else if (Typeof_ABScene.Equals(assetType)) { #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 if (req.isAdditive) { req.assetBundleRequest = Application.LoadLevelAdditiveAsync(req.assetName); } else { req.assetBundleRequest = Application.LoadLevelAsync(req.assetName); } #else req.assetBundleRequest = SceneManager.LoadSceneAsync(req.assetName, req.isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); #endif re = true; } else { if (abundle == null) { #if UNITY_EDITOR Debug.LogWarningFormat("SetRequestDataFromCache Assetbundle is null request(url={0},assetName={1},assetType={2}) ", req.url, req.assetName, req.assetType); #endif } else if (req.async) { req.assetBundleRequest = abundle.LoadAssetAsync(req.assetName, assetType); } else { req.data = abundle.LoadAsset(req.assetName, assetType); } re = true; } } return(re); }
/// <summary> /// 从缓存设置数据 /// </summary> /// <param name="req"></param> internal static bool SetRequestDataFromCache(CRequest req) { bool re = false; #if UNITY_EDITOR if (CResLoader.SimulateAssetBundleInEditor) { if (!req.isAssetBundle) { return(false); } System.Type assetType = req.assetType; if (assetType == null) { assetType = Typeof_Object; } if (Typeof_ABScene.Equals(assetType)) { string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(req.assetBundleName, req.assetName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + req.assetName + "\" in " + req.assetBundleName); return(false); } if (req.isAdditive) { req.assetBundleRequest = UnityEditor.EditorApplication.LoadLevelAdditiveAsyncInPlayMode(levelPaths[0]); } else { req.assetBundleRequest = UnityEditor.EditorApplication.LoadLevelAsyncInPlayMode(levelPaths[0]); } } else { string[] assetPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(req.assetBundleName, req.assetName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + req.assetName + "\" in " + req.assetBundleName); return(false); } bool loadAll = Typeof_ABAllAssets.Equals(assetType); object data = null; List <UnityEngine.Object> datas = null; foreach (var p in assetPaths) { if (loadAll) { // data UnityEngine.Object[] target = UnityEditor.AssetDatabase.LoadAllAssetsAtPath(p); if (datas == null) { datas = new List <UnityEngine.Object> (); datas.AddRange(target); } else { datas.AddRange(target); } data = datas.ToArray(); } else { UnityEngine.Object target = UnityEditor.AssetDatabase.LoadAssetAtPath(p, assetType); if (target) { data = target; break; } } } req.data = data; } return(true); } #endif int keyhash = req.keyHashCode; CacheData cachedata = GetCache(keyhash); if (cachedata != null) { AssetBundle abundle = cachedata.assetBundle; System.Type assetType = req.assetType; if (assetType == null) { assetType = Typeof_Object; } if (req.isShared) //共享的 { req.data = abundle; re = true; } else if (Typeof_AssetBundle.Equals(assetType)) { req.data = cachedata.assetBundle; re = true; } else if (Typeof_ABScene.Equals(assetType)) { #if UNITY_5_0 || UNITY_5_1 || UNITY_5_2 if (req.isAdditive) { req.assetBundleRequest = Application.LoadLevelAdditiveAsync(req.assetName); } else { req.assetBundleRequest = Application.LoadLevelAsync(req.assetName); } #else req.assetBundleRequest = SceneManager.LoadSceneAsync(req.assetName, req.isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); #endif re = true; } else { bool loadAll = Typeof_ABAllAssets.Equals(assetType); if (abundle == null) { #if UNITY_EDITOR Debug.LogWarningFormat("SetRequestDataFromCache Assetbundle is null request(url={0},assetName={1},assetType={2}) ", req.url, req.assetName, req.assetType); #endif } else if (req.async) { if (loadAll) { req.assetBundleRequest = abundle.LoadAllAssetsAsync(); } else { req.assetBundleRequest = abundle.LoadAssetAsync(req.assetName, assetType); } } else { if (loadAll) { req.data = abundle.LoadAllAssets(); } else { req.data = abundle.LoadAsset(req.assetName, assetType); } } // Debug.LogFormat ("load all {0} {1} ", loadAll, req.assetBundleRequest); re = true; } } return(re); }