Skip to content

Commit

Permalink
-AssetbundleV2: Fixed on assetbundle unit change not rebuild.
Browse files Browse the repository at this point in the history
-AssetbundleV2: Add local ab check whith preview ab.
  • Loading branch information
奶泡泡 committed Apr 2, 2022
1 parent 22f8ee6 commit 9e920cd
Show file tree
Hide file tree
Showing 13 changed files with 240 additions and 103 deletions.
2 changes: 1 addition & 1 deletion BDFramework.Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
<Compile Include="Packages\com.popo.bdframework\Editor\EditorEnvironment\EditorUserGuide\EditorWindow_BDFrameworkStart.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorGUIHelper.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorPipeline\BuildPipeline\AssetBundleEditor\AssetBundleBuildingContext.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorPipeline\BuildPipeline\AssetBundleEditor\AssetBundleEditorToolsV2.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorPipeline\BuildPipeline\AssetBundleEditor\AssetBundleEditorToolsV2CheckAssetbundle.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorPipeline\BuildPipeline\AssetBundleEditor\AssetBundleEditorToolsV2ForAssetGraph.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorPipeline\BuildPipeline\AssetBundleEditor\AssetGraph\BuildAssetBundleParams.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorPipeline\BuildPipeline\AssetBundleEditor\AssetGraph\Node\BDFrameworkAssetsEnv.cs" />
<Compile Include="Packages\com.popo.bdframework\Editor\EditorPipeline\BuildPipeline\AssetBundleEditor\AssetGraph\Node\BuildAssetBundle.cs" />
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using BDFramework.Core.Tools;
using BDFramework.Editor.AssetGraph.Node;
using UnityEditor;
using UnityEngine;
Expand All @@ -11,7 +12,7 @@ namespace BDFramework.Editor.AssetBundle
/// <summary>
/// AssetGraph构建AssetBundle
/// </summary>
static public class AssetBundleEditorToolsV2ForAssetGraph
static public class AssetBundleEditorToolsV2
{
/// <summary>
/// 获取所有bd拓展的AssetGraph配置
Expand Down Expand Up @@ -54,9 +55,57 @@ static public void Build(BuildTarget buildTarget, string outPath)
var (cg, bdenvNode) = GetBDFrameExAssetGraph();
var bdenv = (bdenvNode.Operation.Object as BDFrameworkAssetsEnv);
bdenv.SetBuildParams(outPath);

//执行
AssetGraphUtility.ExecuteGraph(buildTarget, cg);
}


/// <summary>
/// 生成AssetBundle
/// </summary>
/// <param name="outputPath">导出目录</param>
/// <param name="target">平台</param>
/// <param name="options">打包参数</param>
/// <param name="isUseHashName">是否为hash name</param>
public static bool GenAssetBundle(string outputPath, RuntimePlatform platform)
{
var buildTarget = BDApplication.GetBuildTarget(platform);
Build(buildTarget, outputPath);
return true;
}


/// <summary>
/// 获取主资源类型
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
public static Type GetMainAssetTypeAtPath(string path)
{
var type = AssetDatabase.GetMainAssetTypeAtPath(path);
//图片类型得特殊判断具体的实例类型
if (type == typeof(Texture2D))
{
var sp = AssetDatabase.LoadAssetAtPath<Sprite>(path);
if (sp != null)
{
return typeof(Sprite);
}

var tex2d = AssetDatabase.LoadAssetAtPath<Texture2D>(path);
if (tex2d != null)
{
return typeof(Texture2D);
}

var tex3d = AssetDatabase.LoadAssetAtPath<Texture3D>(path);
if (tex3d != null)
{
return typeof(Texture3D);
}
}

return type;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static IEnumerator IE_LoadAll()

foreach (var asset in allRuntimeAssets)
{
var type = AssetBundleBuildingContext.GetMainAssetTypeAtPath(asset);
var type = AssetBundleEditorToolsV2.GetMainAssetTypeAtPath(asset);
if (type == null)
{
Debug.LogError("无法获得资源类型:" + asset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override void Prepare(BuildTarget target, NodeData nodeData, IEnumerable<
// var platform = BDApplication.GetRuntimePlatform(target);
BDFrameworkAssetsEnv.BuildingCtx.MergeABName(tempBuildAssetsInfo);
//对比差异文件
var changedBuildInfo = BDFrameworkAssetsEnv.BuildingCtx.GetChangedAssets(tempBuildAssetsInfo, target);
BDFrameworkAssetsEnv.BuildingCtx.GetChangedAssets(tempBuildAssetsInfo, target);

//搜集所有的 asset reference
List<AssetReference> assetReferenceList = new List<AssetReference>();
Expand Down Expand Up @@ -184,6 +184,15 @@ public override void Prepare(BuildTarget target, NodeData nodeData, IEnumerable<
/// </summary>
public static BuildAssetsInfo BuildAssetsResult { get; private set; } = null;

/// <summary>
/// 构建时候触发
/// </summary>
/// <param name="buildTarget"></param>
/// <param name="nodeData"></param>
/// <param name="incoming"></param>
/// <param name="connectionsToOutput"></param>
/// <param name="outputFunc"></param>
/// <param name="progressFunc"></param>
public override void Build(BuildTarget buildTarget, NodeData nodeData, IEnumerable<PerformGraph.AssetGroups> incoming, IEnumerable<ConnectionData> connectionsToOutput, PerformGraph.Output outputFunc,
Action<NodeData, string, float> progressFunc)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ private Dictionary<string, List<AssetReference>> DoSetABNameUseSubfolderName(IEn
for (int i = 0; i < subfolders.Length; i++)
{
var subFolder = subfolders[i];
subFolder = subFolder.Replace("\\", "/");
subfolders[i] = subFolder;
//
var guid = AssetDatabase.AssetPathToGUID(subFolder);
outMap[subFolder] = new List<AssetReference>();
//打印文件夹hash
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Diagnostics;
using UnityEngine;

namespace BDFramework.Editor.AssetGraph.Node
{
Expand All @@ -18,5 +19,6 @@ static public void End(string title = "")

UnityEngine.Debug.LogFormat("{0}耗时:{1}ms", title, sw.ElapsedMilliseconds);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class BuildAssetData
/// 在artConfig中的idx,用以辅助其他模块逻辑
/// </summary>
public int ArtConfigIdx { get; set; } = -1;

/// <summary>
/// 资源类型
/// </summary>
Expand Down Expand Up @@ -147,8 +148,32 @@ public bool SetABName(string assetName, string newABName, SetABNameMode setNameM

return isCanSetABName;
}



/// <summary>
/// 预览 assetbundle颗粒度
/// </summary>
/// <returns>ab - 所有</returns>
public Dictionary<string, List<string>> PreviewAssetbundleUnit()
{
var retMap = new Dictionary<string, List<string>>();

foreach (var item in AssetDataMaps)
{
//增加索引
var key = item.Value.ABName;
if (!retMap.ContainsKey(key))
{
retMap[key] = new List<string>();
}

//添加
retMap[key].Add(item.Key);
}

return retMap;
}


/// <summary>
/// 克隆
/// </summary>
Expand All @@ -163,6 +188,7 @@ public BuildAssetsInfo Clone()
{
tempBuildAssetsInfo.AssetDataMaps[item.Key] = item.Value;
}

return tempBuildAssetsInfo;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void BuildAssetBundle(string outputPath)
}

//生成Assetbundlebunle
AssetBundleBuildingContext.GenAssetBundle(outputPath, platform);
AssetBundleEditorToolsV2.GenAssetBundle(outputPath, platform);
AssetDatabase.Refresh();
Debug.Log("资源打包完毕");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static bool BuildAssetBundle(RuntimePlatform platform, BuildTarget targe
//1.搜集keyword
ShaderCollection.CollectShaderVariant();
//2.打包模式
return AssetBundleBuildingContext.GenAssetBundle(CI_ASSETS_PATH, platform);
return AssetBundleEditorToolsV2.GenAssetBundle(CI_ASSETS_PATH, platform);
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static public void GenAllAssets(string outputPath, RuntimePlatform platform)
try
{
//var config = BDEditorApplication.BDFrameWorkFrameEditorSetting.BuildAssetBundle;
AssetBundleBuildingContext.GenAssetBundle(outputPath, platform);
AssetBundleEditorToolsV2.GenAssetBundle(outputPath, platform);
}
catch (Exception e)
{
Expand Down
28 changes: 27 additions & 1 deletion Packages/com.popo.bdframework/Runtime/DotNetExtension/Path.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,31 @@ static public string Combine(string a, string b, string c, string d)
{
return ZString.Concat(a, "/", b, "/", c, "/", d);
}

/// <summary>
/// 路径合并
/// 这里是修复Mac下的 Path.Combine的Bug
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
// static public string Combine(params string[] paths)
// {
// var ret = "";
//
// for (int i = 0; i < paths.Length; i++)
// {
// var str = paths[i];
// if (str.EndsWith("/"))
// {
// return ZString.Concat(ret, str);
// }
// else
// {
// return ZString.Concat(ret, "/", str);
// }
// }
// return ret;
// }
}
}
}

0 comments on commit 9e920cd

Please sign in to comment.