/// <summary> /// 加载资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <returns></returns> protected Object LoadAsset(string path, System.Type type) { this.LoadManifest(); string relPath, objName, envPath; LoadPath(path, type, out relPath, out objName); #if UNITY_EDITOR if (CEnv.DebugLevel == CEnv.DebugLevels.DEV) { return(UnityEditor.AssetDatabase.LoadAssetAtPath("Assets" + CEnv.ResourcesBuildPath + "/" + relPath + "/" + objName, type)); } #endif if (CEnv.DebugLevel == CEnv.DebugLevels.STAGING) { envPath = CEnv.DataPath + CEnv.ReleasePath + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); } else { envPath = CEnv.AssetPath; } AssetBundle assetTarget = LoadAssetBundle(envPath, relPath); return(assetTarget.LoadAsset(objName, type)); }
/// <summary> /// 加载资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <returns></returns> protected T LoadAsset <T>(string path) where T : Object { string relPath, objName, envPath; LoadPath <T>(path, out relPath, out objName); #if UNITY_EDITOR if (CEnv.DebugLevel == CEnv.DebugLevels.DEV) { return(UnityEditor.AssetDatabase.LoadAssetAtPath <T>("Assets" + CEnv.ResourcesBuildPath + "/" + relPath + "/" + objName)); } #endif if (CEnv.DebugLevel == CEnv.DebugLevels.STAGING) { envPath = CEnv.DataPath + CEnv.ReleasePath + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); } else { envPath = CEnv.AssetPath; } AssetBundle assetTarget = LoadAssetBundle(envPath, relPath); T targetAsset = assetTarget.LoadAsset <T>(objName); return(targetAsset); }
/// <summary> /// 加载依赖文件 /// </summary> protected void LoadManifest() { if (assetBundleManifest != null) { return; } #if UNITY_EDITOR if (CEnv.DebugLevel == CEnv.DebugLevels.DEV) { return; } #endif string envPath; if (CEnv.DebugLevel == CEnv.DebugLevels.STAGING) { envPath = CEnv.DataPath + CEnv.ReleasePath + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); } else { envPath = CEnv.AssetPath; } string manifestPath = envPath + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); AssetBundle assetBundle = AssetBundle.LoadFromFile(manifestPath); assetBundleManifest = assetBundle.LoadAsset <AssetBundleManifest>("AssetBundleManifest"); }
public T[] LoadAll <T>(string path) where T : Object { this.LoadManifest(); string relPath, objName, envPath; LoadPath <T>(path, out relPath, out objName); #if UNITY_EDITOR if (CEnv.DebugLevel == CEnv.DebugLevels.DEV) { return(UnityEditor.AssetDatabase.LoadAllAssetsAtPath("Assets" + CEnv.ResourcesBuildPath + "/" + relPath + "/" + objName).To <T>()); } #endif if (CEnv.DebugLevel == CEnv.DebugLevels.STAGING) { envPath = CEnv.DataPath + CEnv.ReleasePath + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); } else { envPath = CEnv.AssetPath; } AssetBundle assetTarget = LoadAssetBundle(envPath, relPath + "/" + objName); T[] targetAssets = assetTarget.LoadAllAssets <T>(); return(targetAssets); }
/// <summary> /// 获取文件更新列表 /// </summary> /// <returns></returns> protected IEnumerator UpdateList(string resUrl) { base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_START); resUrl = resUrl + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); UnityWebRequest request = UnityWebRequest.Get(resUrl + "/" + CUpdateList.FILE_NAME); yield return(request.Send()); if (request.isError || request.responseCode != 200) { this.isUpdate = false; base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_LIST_FAILED); yield break; } base.Event.Trigger(CAutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_START); var newLst = new CUpdateList(request).SetPath(CEnv.AssetPath); CUpdateList oldLst = new CUpdateList(CEnv.AssetPath); CDirectory.CreateDir(CEnv.AssetPath); CDirectory.Walk(CEnv.AssetPath, (file) => { if (!file.Standard().EndsWith(".meta")) { string fullName = file.Standard(); string assetName = fullName.Substring(CEnv.AssetPath.Length); oldLst.Append(assetName, CMD5.ParseFile(file), file.Length); } }); base.Event.Trigger(CAutoUpdateEvents.ON_SCANNING_DISK_FILE_HASH_END); CUpdateList needUpdateLst, needDeleteLst; oldLst.Comparison(newLst, out needUpdateLst, out needDeleteLst); yield return(this.DeleteOldAsset(needDeleteLst)); yield return(this.UpdateAssetFromUrl(needUpdateLst, resUrl)); newLst.Save(); base.Event.Trigger(CAutoUpdateEvents.ON_UPDATE_COMPLETE); }
public static void BuildAllAssetBundles() { RuntimePlatform switchPlatform = CEnv.SwitchPlatform; string platform = CEnv.PlatformToName(switchPlatform); CCreateAssetBundles.ClearAssetBundle(); CCreateAssetBundles.BuildAssetBundleName(CEnv.DataPath + CEnv.ResourcesBuildPath); string releasePath = CEnv.DataPath + CEnv.ReleasePath + "/" + platform; CDirectory.CreateDir(releasePath, CDirectory.Operations.EXISTS_TO_DELETE); BuildPipeline.BuildAssetBundles("Assets" + CEnv.ReleasePath + "/" + platform, BuildAssetBundleOptions.None, CCreateAssetBundles.PlatformToBuildTarget(switchPlatform)); CCreateAssetBundles.BuildListFile(releasePath); AssetDatabase.Refresh(); }
/// <summary> /// 加载资源(异步) /// </summary> /// <typeparam name="T"></typeparam> /// <param name="path"></param> /// <param name="callback"></param> /// <returns></returns> protected IEnumerator LoadAssetAsyn <T>(string path, System.Action <T> callback) where T : Object { string relPath, objName, envPath; LoadPath <T>(path, out relPath, out objName); #if UNITY_EDITOR if (CEnv.DebugLevel == CEnv.DebugLevels.DEV) { callback.Invoke(UnityEditor.AssetDatabase.LoadAssetAtPath <T>("Assets" + CEnv.ResourcesBuildPath + "/" + relPath + "/" + objName)); yield break; } #endif if (CEnv.DebugLevel == CEnv.DebugLevels.STAGING) { Debug.Log(CEnv.DataPath + CEnv.ReleasePath + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform)); envPath = CEnv.DataPath + CEnv.ReleasePath; } else { envPath = CEnv.AssetPath; } AssetBundle assetTarget = null; yield return(LoadAssetBundleAsyn(envPath, relPath, (ab) => { assetTarget = ab; })); AssetBundleRequest targetAssetRequest = assetTarget.LoadAssetAsync <T>(objName); yield return(targetAssetRequest); T targetAsset = targetAssetRequest.asset as T; callback.Invoke(targetAsset); }
protected IEnumerator LoadAssetAllAsyn(string path, System.Type type, System.Action <Object[]> callback) { this.LoadManifest(); string relPath, objName, envPath; LoadPath(path, type, out relPath, out objName); #if UNITY_EDITOR if (CEnv.DebugLevel == CEnv.DebugLevels.DEV) { callback.Invoke(UnityEditor.AssetDatabase.LoadAllAssetsAtPath("Assets" + CEnv.ResourcesBuildPath + "/" + relPath + "/" + objName)); yield break; } #endif if (CEnv.DebugLevel == CEnv.DebugLevels.STAGING) { envPath = CEnv.DataPath + CEnv.ReleasePath + "/" + CEnv.PlatformToName(CEnv.SwitchPlatform); } else { envPath = CEnv.AssetPath; } AssetBundle assetTarget = null; yield return(LoadAssetBundleAsyn(envPath, relPath + "/" + System.IO.Path.GetFileNameWithoutExtension(objName), (ab) => { assetTarget = ab; })); AssetBundleRequest targetAssetRequest = assetTarget.LoadAllAssetsAsync(); yield return(targetAssetRequest); callback.Invoke(targetAssetRequest.allAssets); }