Skip to content

Commit

Permalink
Update AssetComponent.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mister91jiao committed Jul 1, 2022
1 parent 6adde28 commit 3016203
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion BundleMasterRuntime/AssetComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,66 @@ public static ETTask LoadSceneAsync(out LoadSceneHandler loadSceneHandler, strin
loadSceneHandler.LoadSceneBundleAsync(tcs).Coroutine();
return tcs;
}

/// <summary>
/// 从一个分包里加载shader
/// </summary>
public static Shader LoadShader(string shaderPath, string bundlePackageName = null)
{
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Develop)
{
#if UNITY_EDITOR
return AssetDatabase.LoadAssetAtPath<Shader>(shaderPath);
#else
AssetLogHelper.LogError("资源加载Develop模式只能在编辑器下运行");
return null;
#endif
}
if (bundlePackageName == null)
{
bundlePackageName = AssetComponentConfig.DefaultBundlePackageName;
}
if (!BundleNameToRuntimeInfo.TryGetValue(bundlePackageName, out BundleRuntimeInfo bundleRuntimeInfo))
{
AssetLogHelper.LogError("加载Shader没有此分包: " + bundlePackageName);
return null;
}
return bundleRuntimeInfo.Shader.LoadAsset<Shader>(shaderPath);
}

/// <summary>
/// 从一个分包里异步加载shader
/// </summary>
public static ETTask<Shader> LoadShaderAsync(string shaderPath, string bundlePackageName = null)
{
ETTask<Shader> tcs = ETTask<Shader>.Create();
if (AssetComponentConfig.AssetLoadMode == AssetLoadMode.Develop)
{
#if UNITY_EDITOR
tcs.SetResult(AssetDatabase.LoadAssetAtPath<Shader>(shaderPath));
#else
AssetLogHelper.LogError("资源加载Develop模式只能在编辑器下运行");
#endif
return tcs;

}
if (bundlePackageName == null)
{
bundlePackageName = AssetComponentConfig.DefaultBundlePackageName;
}
if (!BundleNameToRuntimeInfo.TryGetValue(bundlePackageName, out BundleRuntimeInfo bundleRuntimeInfo))
{
AssetLogHelper.LogError("加载Shader没有此分包: " + bundlePackageName);
return null;
}

AssetBundleRequest bundleRequest = bundleRuntimeInfo.Shader.LoadAssetAsync<Shader>(shaderPath);
bundleRequest.completed += operation =>
{
tcs.SetResult(bundleRequest.asset as Shader);
};
return tcs;
}

/// <summary>
/// 获取一个已经初始化完成的分包的信息
Expand Down Expand Up @@ -517,7 +577,6 @@ public static BundleRuntimeInfo GetBundleRuntimeInfo(string bundlePackageName)
return null;
}
}

}

public enum AssetLoadMode
Expand Down

0 comments on commit 3016203

Please sign in to comment.