/// <summary> /// 获取资源信息 /// </summary> public static AssetBundleInfo GetAssetBundleInfo(string location, string variant) { if (_isInitialize == false) { throw new Exception($"{nameof(AssetSystem)} is not initialize."); } if (SimulationOnEditor) { #if UNITY_EDITOR string localPath = AssetPathHelper.FindDatabaseAssetPath(location); string manifestPath = AssetPathHelper.ConvertLocationToManifestPath(location, variant); AssetBundleInfo bundleInfo = new AssetBundleInfo(manifestPath, localPath); return(bundleInfo); #else throw new Exception($"AssetSystem simulation only support unity editor."); #endif } else { if (BundleServices == null) { throw new Exception($"{nameof(BundleServices)} is null. Use {nameof(AssetSystem.Initialize)}"); } string manifestPath = AssetPathHelper.ConvertLocationToManifestPath(location, variant); return(BundleServices.GetAssetBundleInfo(manifestPath)); } }
/// <summary> /// 创建资源文件加载器 /// </summary> public static AssetFileLoader CreateFileLoader(string location) { AssetFileLoader loader; if (SystemMode == EAssetSystemMode.EditorMode) { #if UNITY_EDITOR string loadPath = FindDatabaseAssetPath(location); loader = CreateFileLoaderInternal(loadPath, null); #else throw new Exception("EAssetSystemMode.EditorMode only support unity editor."); #endif } else if (SystemMode == EAssetSystemMode.ResourcesMode) { string loadPath = location; loader = CreateFileLoaderInternal(loadPath, null); } else if (SystemMode == EAssetSystemMode.BundleMode) { if (BundleServices == null) { throw new Exception($"{nameof(IBundleServices)} is null."); } string manifestPath = AssetPathHelper.ConvertLocationToManifestPath(location); string loadPath = BundleServices.GetAssetBundleLoadPath(manifestPath); loader = CreateFileLoaderInternal(loadPath, manifestPath); } else { throw new NotImplementedException($"{SystemMode}"); } return(loader); }
/// <summary> /// 同步加载接口 /// 注意:仅支持无依赖关系的资源 /// </summary> public T SyncLoad <T>(string location) where T : UnityEngine.Object { UnityEngine.Object result = null; if (AssetSystem.SystemMode == EAssetSystemMode.EditorMode) { #if UNITY_EDITOR string loadPath = AssetSystem.FindDatabaseAssetPath(location); result = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(loadPath); if (result == null) { LogSystem.Log(ELogType.Error, $"Failed to load {loadPath}"); } #else throw new Exception("AssetDatabaseLoader only support unity editor."); #endif } else if (AssetSystem.SystemMode == EAssetSystemMode.ResourcesMode) { result = Resources.Load <T>(location); if (result == null) { LogSystem.Log(ELogType.Error, $"Failed to load {location}"); } } else if (AssetSystem.SystemMode == EAssetSystemMode.BundleMode) { string fileName = System.IO.Path.GetFileNameWithoutExtension(location); string manifestPath = AssetPathHelper.ConvertLocationToManifestPath(location); string loadPath = AssetSystem.BundleServices.GetAssetBundleLoadPath(manifestPath); AssetBundle bundle = AssetBundle.LoadFromFile(loadPath); if (bundle != null) { result = bundle.LoadAsset <T>(fileName); } if (result == null) { LogSystem.Log(ELogType.Error, $"Failed to load {loadPath}"); } if (bundle != null) { bundle.Unload(false); } } else { throw new NotImplementedException($"{AssetSystem.SystemMode}"); } return(result as T); }