public static void BuildBundles() { BundleBuildHelper.PushAssetDependencies(); BuildSingleBundle(BundleName.BN_SCRIPT, null); BundleData shader = BundleDataManager.GetBundleData(BundleName.BN_SHADER); for (int i = 0; shader != null && i < shader.children.Count; ++i) { BundleData shaderChild = BundleDataManager.GetBundleData(shader.children[i]); BundleState childState = BundleDataManager.GetBundleState(shader.children[i]); bool result = BundleBuildHelper.BuildShaderBundle(shaderChild, childState); if (!result) { Debug.LogErrorFormat("[BundleAdapter] BuildShaderBundle {0} Failed.", shader.children[i]); } } List <BundleImportData> dataList = m_dataControl.DataList; for (int i = 0; i < dataList.Count; ++i) { BundleImportData data = dataList[i]; string parentName = BundleDataManager.GetIndexBundleName(i); BuildSingleBundle(parentName, data); } BundleBuildHelper.PopAssetDependencies(); BundleExport.ExportBundleMainfestToOutput(); AssetDatabase.SaveAssets(); }
static public BundleState GetBundleState(string name) { BundleState ret = null; m_stateDict.TryGetValue(name, out ret); return(ret); }
private static void BuildSingleBundle(string name, BundleImportData data) { BundleData bundle = BundleDataManager.GetBundleData(name); if (bundle == null) { return; } for (int i = 0; i < bundle.children.Count; ++i) { BundleData child = BundleDataManager.GetBundleData(bundle.children[i]); BundleState childState = BundleDataManager.GetBundleState(bundle.children[i]); if (child == null || child.includs.Count == 0 || childState == null) { continue; } if (m_buildAll && !m_bundleDict.ContainsKey(child.name)) { continue; } bool result = BundleBuildHelper.BuildSingleBundle(child, childState, data == null ? false : data.PushDependice); if (!result) { Debug.LogErrorFormat("[BundleAdapter] BuildSingleBundle {0} Failed.", child.name); } } }
public static bool BuildSingleBundle(BundleData bundle, BundleState state) { if (bundle == null) { return(false); } string outputPath = ""; EditorCommon.CreateDirectory(outputPath); uint crc = 0; string[] assetPaths = bundle.includs.ToArray(); bool succeed = false; if (bundle.type == BundleType.UnityMap) { succeed = BuildSceneBundle(assetPaths, outputPath, out crc); } else { succeed = BuildAssetBundle(assetPaths, outputPath, out crc, bundle.type); } succeed = UpdateBundleState(bundle, state, outputPath, succeed, crc); return(succeed); }
public static bool BuildShaderBundle(BundleData bundle, BundleState state) { if (bundle == null || state == null) { return(false); } List <UnityEngine.Object> list = new List <UnityEngine.Object>(); for (int i = 0; i < bundle.includs.Count; ++i) { string path = bundle.includs[i]; if (path.StartsWith("Assets", StringComparison.OrdinalIgnoreCase)) { UnityEngine.Object[] assetsAtPath = AssetDatabase.LoadAllAssetsAtPath(path); if (assetsAtPath != null || assetsAtPath.Length != 0) { list.AddRange(assetsAtPath); } else { Debug.LogError("Cannnot load [" + path + "] as asset object"); } } else { UnityEngine.Object obj = Shader.Find(path); if (obj == null) { Debug.LogError("Find shader " + path + " failed."); } else { list.Add(obj); } } } if (list.Count == 0) { Debug.LogError("Empty Shader Bundle " + bundle.name); return(false); } uint crc = 0; string outputPath = BuildConfig.GetBuildOutputPath(bundle.name); EditorTool.CreateDirectory(outputPath); bool succeed = BuildAssetBundle(list.ToArray(), outputPath, out crc); succeed = UpdateBundleState(bundle, state, outputPath, succeed, crc); return(succeed); }
public void AddBundleState(BundleState bundleState) { if (!m_bundleNameToState.ContainsKey(bundleState.bundleID)) { m_bundleNameToState.Add(bundleState.bundleID, bundleState); } else { m_bundleNameToState[bundleState.bundleID] = bundleState; } }
public static bool BuildSingleBundle(BundleData bundle, BundleState state, bool pushDepend) { if (pushDepend) { PushAssetDependencies(); } bool ret = BuildSingleBundle(bundle, state); if (pushDepend) { PopAssetDependencies(); } return(ret); }
public void AddBundleState(List <BundleState> bundleStates) { if (bundleStates == null) { return; } for (int i = 0; i < bundleStates.Count; ++i) { BundleState states = bundleStates[i]; if (!m_bundleStates.ContainsKey(states.bundleID)) { m_bundleStates.Add(states.bundleID, states); } } }
private static bool UpdateBundleState(BundleData bundle, BundleState state, string outputPath, bool succeed, uint crc) { if (!succeed || (crc == state.crc && state.size > 0)) { return(succeed); } state.version++; if (state.version == int.MaxValue) { state.version = 0; } state.crc = crc; FileInfo bundleFileInfo = new FileInfo(outputPath); state.size = bundleFileInfo.Length; state.loadState = bundle.loadState; state.storePos = BundleStorePos.Building; return(succeed); }
public static bool CreateNewBundle(string name, string parent, BundleType type, BundleLoadState loadState) { if (m_dataDict.ContainsKey(name)) { return(false); } BundleData newBundle = new BundleData(); newBundle.name = name; newBundle.type = type; newBundle.loadState = loadState; if (!string.IsNullOrEmpty(parent)) { if (m_dataDict.ContainsKey(parent)) { return(false); } else { m_dataDict[parent].children.Add(name); } newBundle.parent = parent; } m_dataDict.Add(name, newBundle); BMDataAccessor.Datas.Add(newBundle); BundleState newState = new BundleState(); newState.bundleID = name; newState.version = 1; m_stateDict.Add(name, newState); BMDataAccessor.States.Add(newState); return(true); }
private static void _BuildSingleBundle(string name, BundleImportData data) { BundleData bundle = BundleDataManager.GetBundleData(name); if (bundle == null) { return; } for (int i = 0; i < bundle.children.Count; ++i) { BundleData child = BundleDataManager.GetBundleData(bundle.children[i]); BundleState childState = BundleDataManager.GetBundleState(bundle.children[i]); if (child == null || child.includs.Count == 0 || childState == null) { continue; } if (m_useFilter && !m_bundleDict.ContainsKey(child.name)) { continue; } BuildHelper.BuildSingleBundle(child, childState, data.PushDependice); } }
public static void ExportBundleDictToOutput() { EditorTool.CreateDirectory(BuildConfig.InterpretedOutputPath); BundleDataControl dataControl = BundleDataControl.Instance; BundleMainfest bundleMainfest = new BundleMainfest(); BundleData[] bundleData = BundleDataAccessor.Datas.ToArray(); Dictionary <string, string> dict = new Dictionary <string, string>(); for (int i = 0; i < bundleData.Length; ++i) { for (int j = 0; j < bundleData[i].includs.Count; ++j) { string path = bundleData[i].includs[j]; if (string.IsNullOrEmpty(path)) { continue; } if (!dict.ContainsKey(path)) { dict.Add(path, bundleData[i].name); } else { Debug.LogWarningFormat("[BundleExport] Path to bundle name have same path {0} : {1} _ {2}", path, bundleData[i].name, dict[path]); } BundleImportData data = dataControl.GetPathImportData(path); if (data == null || !data.Publish || !path.StartsWith("Assets", StringComparison.OrdinalIgnoreCase)) { continue; } string bundlePath = path; // format path to load path!!! bundleMainfest.AddPathToBundle(bundlePath, bundleData[i].name); } } for (int i = 0; i < bundleData.Length; ++i) { for (int j = 0; j < bundleData[i].includs.Count; ++j) { string[] dep = AssetDepot.GetDependenciesCache(bundleData[i].includs[j]); for (int k = 0; k < dep.Length; ++k) { if (EditorPath.IsScript(dep[k]) || EditorPath.IsShader(dep[k])) { continue; } string bundleName = null; dict.TryGetValue(EditorPath.NormalizePathSplash(dep[k]), out bundleName); if (string.IsNullOrEmpty(bundleName) || bundleName == bundleData[i].name) { continue; } BundleState childBuildState = BundleDataManager.GetBundleState(bundleName); if (childBuildState.loadState == BundleLoadState.Preload || childBuildState.size == -1) { continue; } bundleMainfest.AddBundleDepend(bundleData[i].name, bundleName); } } } List <BundleState> stateList = new List <BundleState>(BundleDataAccessor.States); bundleMainfest.AddBundleState(stateList); bundleMainfest.SaveBytes(BuildConfig.BundleMainfestOutputPath); AssetDatabase.ImportAsset(BuildConfig.BundleMainfestOutputPath, ImportAssetOptions.ForceSynchronousImport); }