Skip to content

Commit

Permalink
提交更新内容
Browse files Browse the repository at this point in the history
  • Loading branch information
mister91jiao committed Jan 24, 2023
1 parent 131241e commit cb936a4
Show file tree
Hide file tree
Showing 26 changed files with 1,658 additions and 675 deletions.
70 changes: 18 additions & 52 deletions BundleMasterRuntime/AssetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -190,60 +190,42 @@ public static async ETTask<T> LoadAsync<T>(string assetPath, string bundlePackag
{
bundlePackageName = AssetComponentConfig.DefaultBundlePackageName;
}

T asset = null;
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Develop)
{
#if UNITY_EDITOR
asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
return AssetDatabase.LoadAssetAtPath<T>(assetPath);
#else
AssetLogHelper.LogError("加载资源: " + assetPath + " 失败(资源加载Develop模式只能在编辑器下运行)");
return null;
#endif
return asset;
}
LoadHandler loadHandler = null;
if (!BundleNameToRuntimeInfo.TryGetValue(bundlePackageName, out BundleRuntimeInfo bundleRuntimeInfo))
{
AssetLogHelper.LogError(bundlePackageName + "分包没有初始化");
return null;
}
if (!bundleRuntimeInfo.AllAssetLoadHandler.TryGetValue(assetPath, out loadHandler))
if (!bundleRuntimeInfo.AllAssetLoadHandler.TryGetValue(assetPath, out LoadHandler loadHandler))
{
loadHandler = LoadHandlerFactory.GetLoadHandler(assetPath, bundlePackageName, true, true);
bundleRuntimeInfo.AllAssetLoadHandler.Add(assetPath, loadHandler);
bundleRuntimeInfo.UnLoadHandler.Add(loadHandler.UniqueId, loadHandler);
}
//加载资源
CoroutineLock coroutineLock = await CoroutineLockComponent.Wait(CoroutineLockType.BundleMaster, LoadPathConvertHelper.LoadPathConvert("T|" + assetPath));
if (loadHandler.LoadState == LoadState.NoLoad)
{
ETTask tcs = ETTask.Create(true);
loadHandler.AwaitEtTasks.Add(tcs);
await loadHandler.LoadAsync();
AssetBundleRequest loadAssetAsync = loadHandler.FileAssetBundle.LoadAssetAsync<T>(assetPath);
ETTask tcs = ETTask.Create(true);
loadAssetAsync.completed += operation =>
{
loadHandler.Asset = loadAssetAsync.asset;
asset = loadHandler.Asset as T;
for (int i = 0; i < loadHandler.AwaitEtTasks.Count; i++)
{
ETTask etTask = loadHandler.AwaitEtTasks[i];
etTask.SetResult();
}
loadHandler.AwaitEtTasks.Clear();
tcs.SetResult();
};
await tcs;
return asset;
}
else if (loadHandler.LoadState == LoadState.Loading)
{
ETTask tcs = ETTask.Create(true);
loadHandler.AwaitEtTasks.Add(tcs);
await tcs;
return (T)loadHandler.Asset;
}
else
{
return (T)loadHandler.Asset;
}
coroutineLock.Dispose();
return (T)loadHandler.Asset;
}

/// <summary>
Expand Down Expand Up @@ -295,55 +277,39 @@ public static ETTask<T> LoadAsync<T>(out LoadHandler handler, string assetPath,
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Develop)
{
#if UNITY_EDITOR
UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
return AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
#else
UnityEngine.Object asset = null;
AssetLogHelper.LogError("加载资源: " + assetPath + " 失败(资源加载Develop模式只能在编辑器下运行)");
return null;
#endif
return asset;
}
LoadHandler loadHandler = null;
if (!BundleNameToRuntimeInfo.TryGetValue(bundlePackageName, out BundleRuntimeInfo bundleRuntimeInfo))
{
AssetLogHelper.LogError(bundlePackageName + "分包没有初始化");
return null;
}
if (!bundleRuntimeInfo.AllAssetLoadHandler.TryGetValue(assetPath, out loadHandler))
if (!bundleRuntimeInfo.AllAssetLoadHandler.TryGetValue(assetPath, out LoadHandler loadHandler))
{
loadHandler = LoadHandlerFactory.GetLoadHandler(assetPath, bundlePackageName, true, true);
bundleRuntimeInfo.AllAssetLoadHandler.Add(assetPath, loadHandler);
bundleRuntimeInfo.UnLoadHandler.Add(loadHandler.UniqueId, loadHandler);
}
//加载资源
CoroutineLock coroutineLock = await CoroutineLockComponent.Wait(CoroutineLockType.BundleMaster, LoadPathConvertHelper.LoadPathConvert("UnityObject|" + assetPath));
if (loadHandler.LoadState == LoadState.NoLoad)
{
ETTask tcs = ETTask.Create(true);
loadHandler.AwaitEtTasks.Add(tcs);
await loadHandler.LoadAsync();
AssetBundleRequest loadAssetAsync = loadHandler.FileAssetBundle.LoadAssetAsync(assetPath);
ETTask tcs = ETTask.Create(true);
loadAssetAsync.completed += operation =>
{
loadHandler.Asset = loadAssetAsync.asset;
for (int i = 0; i < loadHandler.AwaitEtTasks.Count; i++)
{
ETTask etTask = loadHandler.AwaitEtTasks[i];
etTask.SetResult();
}
loadHandler.AwaitEtTasks.Clear();
tcs.SetResult();
};
await tcs;
return loadHandler.Asset;
}
else if (loadHandler.LoadState == LoadState.Loading)
{
ETTask tcs = ETTask.Create(true);
loadHandler.AwaitEtTasks.Add(tcs);
await tcs;
return loadHandler.Asset;
}
else
{
return loadHandler.Asset;
}
coroutineLock.Dispose();
return loadHandler.Asset;
}

/// <summary>
Expand Down
13 changes: 13 additions & 0 deletions BundleMasterRuntime/AssetComponentLife.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ public static void Update()
_timer = 0;
AutoAddToTrueUnLoadPool();
}
//更新下载完成任务
lock (DownloadBundleHelper.DownLoadFinishQueue)
{
if (DownloadBundleHelper.DownLoadFinishQueue.Count > 0)
{
int downLoadFinishCount = DownloadBundleHelper.DownLoadFinishQueue.Count;
for (int i = 0; i < downLoadFinishCount; i++)
{
DownloadBundleHelper.DownLoadFinishQueue.Dequeue().SetResult();
}
}
}
DownLoadAction?.Invoke(nowTime);

}
}
}
Loading

0 comments on commit cb936a4

Please sign in to comment.