/// <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 AssetBundleInfo GetAssetBundleInfo(string location) { if (_isInitialize == false) { throw new Exception($"{nameof(AssetSystem)} is not initialize."); } if (SimulationOnEditor) { #if UNITY_EDITOR string assetPath = AssetPathHelper.FindDatabaseAssetPath(location); AssetBundleInfo bundleInfo = new AssetBundleInfo(assetPath, assetPath); 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 assetPath = $"{LocationRoot}/{location}".ToLower(); string bundleName = BundleServices.GetAssetBundleName(assetPath); return(BundleServices.GetAssetBundleInfo(bundleName)); } }
/// <summary> /// 创建资源文件加载器 /// </summary> public static AssetLoaderBase CreateLoader(string location, string variant) { if (_isInitialize == false) { throw new Exception($"{nameof(AssetSystem)} is not initialize."); } if (SimulationOnEditor) { #if UNITY_EDITOR string loadPath = AssetPathHelper.FindDatabaseAssetPath(location); return(CreateLoaderInternal(loadPath, null)); #else throw new Exception("AssetSystem virtual simulation only support unity editor."); #endif } else { if (BundleServices == null) { throw new Exception($"{nameof(AssetSystem.BundleServices)} is null. Use {nameof(AssetSystem.Initialize)}"); } string manifestPath = BundleServices.ConvertLocationToManifestPath(location, variant); string loadPath = BundleServices.GetAssetBundleLoadPath(manifestPath); return(CreateLoaderInternal(loadPath, manifestPath)); } }
/// <summary> /// 获取资源的最终加载路径 /// </summary> public string GetLoadPath(string location, string variant = "unity3d") { if (AssetSystem.SimulationOnEditor) { #if UNITY_EDITOR string loadPath = AssetPathHelper.FindDatabaseAssetPath(location); if (string.IsNullOrEmpty(loadPath)) { MotionLog.Warning($"Not found asset : {location}"); } return(loadPath); #else throw new Exception($"AssetSystem simulation only support unity editor."); #endif } else { if (AssetSystem.BundleServices == null) { throw new Exception($"{nameof(AssetSystem.BundleServices)} is null."); } string manifestPath = AssetSystem.BundleServices.ConvertLocationToManifestPath(location, variant); string loadPath = AssetSystem.BundleServices.GetAssetBundleLoadPath(manifestPath); if (string.IsNullOrEmpty(loadPath)) { MotionLog.Warning($"Not found asset : {location}"); } return(loadPath); } }
/// <summary> /// 同步加载接口 /// 注意:仅支持无依赖关系的资源 /// </summary> public T SyncLoad <T>(string location, string variant) where T : UnityEngine.Object { UnityEngine.Object result = null; if (AssetSystem.SimulationOnEditor) { #if UNITY_EDITOR string loadPath = AssetPathHelper.FindDatabaseAssetPath(location); result = UnityEditor.AssetDatabase.LoadAssetAtPath <T>(loadPath); if (result == null) { MotionLog.Log(ELogLevel.Error, $"Failed to load {loadPath}"); } #else throw new Exception($"AssetSystem virtual simulation only support unity editor."); #endif } else { if (AssetSystem.BundleServices == null) { throw new Exception($"{nameof(AssetSystem.BundleServices)} is null."); } string manifestPath = AssetSystem.BundleServices.ConvertLocationToManifestPath(location, variant); string loadPath = AssetSystem.BundleServices.GetAssetBundleLoadPath(manifestPath); AssetBundle bundle = AssetBundle.LoadFromFile(loadPath); if (bundle != null) { string fileName = System.IO.Path.GetFileName(location); result = bundle.LoadAsset <T>(fileName); } if (result == null) { MotionLog.Log(ELogLevel.Error, $"Failed to load {loadPath}"); } if (bundle != null) { bundle.Unload(false); } } return(result as T); }
public override void Update() { #if UNITY_EDITOR if (IsDone) { return; } if (States == EAssetStates.None) { States = EAssetStates.Loading; } // 1. 加载资源对象 if (States == EAssetStates.Loading) { string assetPath = _owner.BundleInfo.LocalPath; // 注意:如果加载路径指向的是文件夹 if (UnityEditor.AssetDatabase.IsValidFolder(assetPath)) { string folderPath = assetPath; string fileName = AssetName; assetPath = AssetPathHelper.FindDatabaseAssetPath(folderPath, fileName); } AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, AssetType); States = EAssetStates.Checking; } // 2. 检测加载结果 if (States == EAssetStates.Checking) { States = AssetObject == null ? EAssetStates.Fail : EAssetStates.Success; if (States == EAssetStates.Fail) { MotionLog.Warning($"Failed to load asset object : {_owner.BundleInfo.LocalPath} : {AssetName}"); } InvokeCompletion(); } #endif }