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 void CreateBundles() { _PreProcessSpecialBundle(); List <string> list = m_dataControl.GetPublishPackagePath(); for (int i = 0; i < list.Count; ++i) { string name = Path.GetFileName(list[i]); if (EditorUtility.DisplayCancelableProgressBar("Create Bundle", name, (i * 1.0f) / list.Count)) { Debug.LogWarning("[BundleAdapter] CreateBundles Stop."); break; } string[] dep = AssetDepend.GetDependenciesCache(list[i]); for (int j = 0; j < dep.Length; ++j) { if (string.IsNullOrEmpty(dep[j])) { continue; } _ProcessSpecialResource(dep[j]); BundleImportData data = m_dataControl.GetPathSelectData(dep[j]); if (data != null && !data.SkipData) { _AddPathToBundleByPathConfig(data, dep[j]); } } } EditorUtility.ClearProgressBar(); BMDataAccessor.SaveData(); AssetDatabase.SaveAssets(); }
public static void UpdateBundleBuildList(FilterHandler filter) { if (filter == null) { m_useFilter = false; return; } m_useFilter = true; List <BundleImportData> dataList = m_dataControl.DataList; for (int l = 0; l < dataList.Count; ++l) { BundleImportData data = dataList[l]; if (data == null) { continue; } if (EditorUtility.DisplayCancelableProgressBar("Update Bundle List", data.RootPath, (l * 1.0f) / dataList.Count)) { Debug.LogWarning("CreateBundles Stop."); break; } string parentName = BundleDataManager.GetIndexBundleName(l); BundleData parent = BundleDataManager.GetBundleData(parentName); for (int i = 0; parent != null && i < parent.children.Count; ++i) { _ProcessUpdateBundleList(parent.children[i], data, filter); } } EditorUtility.ClearProgressBar(); _ProcessDependBundleList(); }
private static void _ProcessUpdateBundleList(string bundleName, BundleImportData selectData, FilterHandler filter) { BundleData data = BundleDataManager.GetBundleData(bundleName); if (data == null) { return; } for (int i = 0; i < data.includs.Count; ++i) { if (filter == null || filter(data.includs[i])) { _AddToDict(data.name, m_bundleDict); continue; } if (!selectData.Publish) { continue; } string[] dep = AssetDepend.GetDependenciesCache(data.includs[i]); for (int k = 0; k < dep.Length; ++k) { if (!filter(dep[k])) { continue; } if (!BundleDataManager.CheckPathInBundle(dep[k])) { _AddToDict(data.name, m_bundleDict); break; } } } }
public List <string> GetPublishPackagePath() { Dictionary <string, string> dict = new Dictionary <string, string>(); for (int i = 0; i < m_dataList.Count; ++i) { BundleImportData bundleImportData = m_dataList[i]; if (bundleImportData == null || !bundleImportData.Publish) { continue; } List <object> list = bundleImportData.GetObjects(); for (int j = 0; j < list.Count; ++j) { AssetPathInfo info = list[j] as AssetPathInfo; if (info == null || dict.ContainsKey(info.Path)) { continue; } dict.Add(info.Path, info.Path); } } return(new List <string>(dict.Keys)); }
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(); }
public void AddData() { m_editorData.Index = m_dataList.Count; m_dataList.Add(m_editorData); m_editorData = new BundleImportData(); m_index = -1; BMDataAccessor.SaveImportData(); RefreshDataWithSelect(); }
public void CopyData(BundleImportData data) { RootPath = data.RootPath; FileNameMatch = data.FileNameMatch; Index = data.Index; Type = data.Type; LoadState = data.LoadState; Publish = data.Publish; LimitCount = data.LimitCount; LimitKBSize = data.LimitKBSize; PushDependice = data.PushDependice; }
public void DeleteCurrentData() { if (m_index == -1) { return; } m_dataList.RemoveAt(m_index); m_index = -1; m_editorData = new BundleImportData(); BMDataAccessor.SaveImportData(); RefreshDataWithSelect(); }
public void SaveData() { if (m_index == -1) { return; } BundleImportData data = m_dataList[m_index]; data.ClearObject(); data.CopyData(m_editorData); OnDataSelected(data, m_index); BMDataAccessor.SaveImportData(); RefreshDataWithSelect(); }
public void OnDataSelected(object selected, int col) { BundleImportData importData = selected as BundleImportData; if (importData == null) { return; } m_editorData.CopyData(importData); m_index = importData.Index; if (m_bundleTable != null) { m_bundleTable.RefreshData(BundleDataManager.GetIndexBundleList(importData.Index)); } }
public void OnDataSelected(object selected, int col) { BundleImportData importData = selected as BundleImportData; if (importData == null) { return; } m_editorData.CopyData(importData); m_index = importData.Index; if (importData != null && m_showTable != null) { m_showTable.RefreshData(importData.GetObjects()); } }
public void Draw() { BundleImportData data = m_editorData; GUILayout.BeginHorizontal(TableStyles.Toolbar); { GUILayout.Label("RootPath: ", GUILayout.Width(80)); string rootPath = EditorGUILayout.TextField(data.RootPath, TableStyles.TextField, GUILayout.Width(360)); if (rootPath != data.RootPath) { data.RootPath = rootPath; } GUILayout.Label("FileName: ", GUILayout.Width(60)); string fileName = EditorGUILayout.TextField(data.FileNameMatch, TableStyles.TextField, GUILayout.Width(150)); if (fileName != data.FileNameMatch) { data.FileNameMatch = fileName; } if (Index == -1) { if (GUILayout.Button("Add Data", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { AddData(); } } else { if (GUILayout.Button("Save Data", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { SaveData(); } if (GUILayout.Button("Delete Current Data", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { DeleteCurrentData(); } if (GUILayout.Button("New Data", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { NewData(); } } GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); }
public static void BuildBundles() { //ModelDataControl dataControl = new ModelDataControl(null, null); //BuildHelper.SetDelegate(dataControl.FilterObject); BuildHelper.PushAssetDependencies(); //BuildHelper.BuildShaderBundle(); _BuildSingleBundle(BundleName.BN_SCRIPT, null); 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); } BuildHelper.PopAssetDependencies(); //BuildHelper.ExportBMDatasToOutput(); AssetDatabase.SaveAssets(); }
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); }
public void NewData() { m_index = -1; m_editorData = new BundleImportData(); }
private static void _AddPathToBundleByPathConfig(BundleImportData data, string path) { if (data == null || string.IsNullOrEmpty(path) || BundleDataManager.CheckPathInBundle(path)) { return; } string parentName = BundleDataManager.GetIndexBundleName(data.Index); if (data.Type == BundleType.Shader) { parentName = BundleName.BN_SHADER; } string bundleName = BundleDataManager.GetPathBundleName(path); if (!string.IsNullOrEmpty(bundleName)) { BundleData bundleData = BundleDataManager.GetBundleData(bundleName); if (bundleData.parent == parentName) { return; } else { BundleDataManager.RemovePathFromBundle(path, bundleName); } } _AddToDict(bundleName, m_bundleDict); BundleData parent = BundleDataManager.GetBundleData(parentName); if (parent == null) { BundleDataManager.CreateNewBundle(parentName, "", BundleType.None, BundleLoadState.UnLoadOnUnloadAsset); parent = BundleDataManager.GetBundleData(parentName); } string name = ""; for (int i = 0; i < parent.children.Count; ++i) { int index = parent.children.Count - i - 1; BundleData child = BundleDataManager.GetBundleData(parent.children[index]); if (BundleDataManager.IsBundleFull(child, data.LimitCount, data.LimitKBSize * 1024)) { continue; } if (data.Publish && BundleDataManager.IsNameDuplicatedAsset(child, path)) { continue; } name = child.name; break; } if (string.IsNullOrEmpty(name)) { name = BundleDataManager.GenBundleNameByType(data.Type); BundleDataManager.CreateNewBundle(name, parent.name, data.Type, data.LoadState); } long size = CalcPathFileSize(path, data.Type); BundleDataManager.AddPathToBundle(path, name, size); _AddToDict(name, m_bundleDict); }
public void Draw(Rect r) { int border = 10; float splitH = 0.4f; float splitW = 0.5f; int toolbarHeight = 80; float spacePixel = 10.0f; //GUILayout.BeginArea(r); GUILayout.BeginVertical(); m_control.Draw(); BundleImportData data = m_control.Data; GUILayout.BeginHorizontal(TableStyles.Toolbar); { EditorGUILayout.LabelField("LimitCount : "); data.LimitCount = EditorGUILayout.IntField(data.LimitCount); GUILayout.Space(spacePixel); EditorGUILayout.LabelField("LimitKBSize : "); data.LimitKBSize = EditorGUILayout.IntField(data.LimitKBSize); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(TableStyles.Toolbar); { EditorGUILayout.LabelField("BundleType : "); data.Type = (BundleType)EditorGUILayout.EnumPopup(data.Type); GUILayout.Space(spacePixel); EditorGUILayout.LabelField("LoadState: "); data.LoadState = (BundleLoadState)EditorGUILayout.EnumPopup(data.LoadState); GUILayout.Space(spacePixel); data.Publish = GUILayout.Toggle(data.Publish, " Publish"); GUILayout.Space(spacePixel); data.PushDependice = GUILayout.Toggle(data.PushDependice, " Push"); GUILayout.Space(spacePixel); data.SkipData = GUILayout.Toggle(data.SkipData, " SkipData"); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(TableStyles.Toolbar); { if (GUILayout.Button("Move Up Priority", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { m_control.ModifDataPriority(true); } if (GUILayout.Button("Move Down Priority", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { m_control.ModifDataPriority(false); } if (GUILayout.Button("Create Bundle", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { m_control.RefreshBaseData(); BundleAdapter.CreateBundles(); } if (GUILayout.Button("Build All Bundle", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { BundleAdapter.UpdateBundleBuildList(); BundleAdapter.BuildBundles(); } if (GUILayout.Button("Clear All Bundle", TableStyles.ToolbarButton, GUILayout.MaxHeight(140))) { BundleDataManager.RemoveAllBundle(); } GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); int startY = toolbarHeight + border; int height = (int)(r.height - startY - border * 2); if (m_dataTable != null) { m_dataTable.Draw(new Rect(border, startY, r.width - border, (int)(height * splitH - border * 1.5f))); } if (m_bundleTable != null) { m_bundleTable.Draw(new Rect(border, (int)(height * splitH + border * 0.5f + startY), (int)(r.width * splitW) - border * 1.5f, (int)(height * (1.0f - splitH) - border * 1.5f))); } if (m_assetTable != null) { m_assetTable.Draw(new Rect((int)(r.width * splitW) + border * 0.5f, (int)(height * splitH + border * 0.5f + startY), (int)(r.width * (1.0f - splitW)) - border * 1.5f, (int)(height * (1.0f - splitH) - border * 1.5f))); } GUILayout.EndVertical(); //GUILayout.EndArea(); }
public static long CalcPathFileSize(string path, BundleType type) { path = PathConfig.FormatAssetPath(path); path = PathConfig.NormalizePathSplash(path); long ret = 0; if (m_pathFileSize.TryGetValue(path, out ret)) { return(ret); } UnityEngine.Object[] objs = null; switch (type) { case BundleType.Texture: objs = AssetDatabase.LoadAllAssetsAtPath(path); for (int i = 0; i < objs.Length; ++i) { if (objs[i] is Texture) { #pragma warning disable 0618 ret += Profiler.GetRuntimeMemorySize(objs[i]); #pragma warning restore 0618 } } ret /= 4; break; case BundleType.Material: string[] deps = AssetDepend.GetDependenciesCache(path); for (int i = 0; i < deps.Length; ++i) { if (PathConfig.IsTexture(deps[i])) { BundleImportData data = m_dataControl.GetPathSelectData(deps[i]); if (data == null || data.SkipData) { ret += EditorCommon.CalculateTextureSizeBytes(deps[i]) / 4; } } } ret += 512; break; case BundleType.FBX: case BundleType.Controller: case BundleType.Animation: objs = AssetDatabase.LoadAllAssetsAtPath(path); List <UnityEngine.Object> list = new List <Object>(); BuildHelper.FilterObjectByType(objs, list, type, path); for (int i = 0; i < list.Count; ++i) { #pragma warning disable 0618 ret += Profiler.GetRuntimeMemorySize(list[i]); #pragma warning restore 0618 } ret /= 6; break; default: FileInfo fileInfo = new FileInfo(path); ret = fileInfo.Length; break; } if (objs != null) { _ProcessClear(); } for (int i = 0; objs != null && i < objs.Length; ++i) { if ((!(objs[i] is GameObject)) && (!(objs[i] is Component))) { Resources.UnloadAsset(objs[i]); } } m_pathFileSize.Add(path, ret); return(ret); }
public static long CalcAssetSize(string assetPath, BundleType type) { assetPath = EditorPath.FormatAssetPath(assetPath); assetPath = EditorPath.NormalizePathSplash(assetPath); long ret = 0; if (m_pathFileSize.TryGetValue(assetPath, out ret)) { return(ret); } BundleImportData assetImportData = BundleDataControl.Instance.GetPathImportData(assetPath); UnityEngine.Object[] assets = null; switch (type) { case BundleType.Texture: assets = AssetDatabase.LoadAllAssetsAtPath(assetPath); for (int i = 0; i < assets.Length; ++i) { if (assets[i] is Texture) { ret += EditorTool.GetRuntimeMemorySize(assets[i]); } } break; case BundleType.Material: string[] deps = AssetDepot.GetDependenciesCache(assetPath); for (int i = 0; i < deps.Length; ++i) { if (EditorPath.IsTexture(deps[i])) { BundleImportData data = BundleDataControl.Instance.GetPathImportData(deps[i]); if (assetImportData == null || data == null || assetImportData.Index < data.Index || data.SkipData) { ret += EditorTool.CalculateTextureSizeBytes(deps[i]); } } } ret += 512; break; case BundleType.FBX: case BundleType.Controller: case BundleType.Animation: assets = AssetDatabase.LoadAllAssetsAtPath(assetPath); List <UnityEngine.Object> list = AssetFilter.FilterObjectByType(assets, type, assetPath); for (int i = 0; i < list.Count; ++i) { ret += EditorTool.GetRuntimeMemorySize(list[i]); } break; default: FileInfo fileInfo = new FileInfo(assetPath); ret = fileInfo.Length; break; } for (int i = 0; assets != null && i < assets.Length; ++i) { if ((!(assets[i] is GameObject)) && (!(assets[i] is Component))) { Resources.UnloadAsset(assets[i]); } } m_pathFileSize.Add(assetPath, ret); return(ret); }
public void Draw(Rect r) { int border = 10; float split = 0.8f; int toolbarHeight = 80; float spacePixel = 10.0f; //GUILayout.BeginArea(r); GUILayout.BeginVertical(); m_control.Draw(); BundleImportData data = m_control.Data; GUILayout.BeginHorizontal(TableStyles.Toolbar); { EditorGUILayout.LabelField("LimitCount : "); data.LimitCount = EditorGUILayout.IntField(data.LimitCount); GUILayout.Space(spacePixel); EditorGUILayout.LabelField("LimitKBSize : "); data.LimitKBSize = EditorGUILayout.IntField(data.LimitKBSize); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(TableStyles.Toolbar); { EditorGUILayout.LabelField("BundleType : "); data.Type = (BundleType)EditorGUILayout.EnumPopup(data.Type); GUILayout.Space(spacePixel); EditorGUILayout.LabelField("LoadState: "); data.LoadState = (BundleLoadState)EditorGUILayout.EnumPopup(data.LoadState, TableStyles.ToolbarButton); GUILayout.Space(spacePixel); data.Publish = GUILayout.Toggle(data.Publish, " Publish"); GUILayout.Space(spacePixel); data.PushDependice = GUILayout.Toggle(data.PushDependice, " Push"); GUILayout.Space(spacePixel); data.SkipData = GUILayout.Toggle(data.SkipData, " SkipData"); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(TableStyles.Toolbar); { if (GUILayout.Button("Move Up Priority", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { m_control.ModifDataPriority(true); } if (GUILayout.Button("Move Down Priority", TableStyles.ToolbarButton, GUILayout.MaxWidth(120))) { m_control.ModifDataPriority(false); } if (GUILayout.Button("Refresh Path Data", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { m_control.RefreshBaseData(); } if (GUILayout.Button("Create Bundle", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { BundleAdapter.CreateBundles(); } // if (GUILayout.Button("Update By PackageDiff", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { // PackagesDiff.LoadData(); // BundleAdapter.UpdateBundleBuildList(PackagesDiff.IsNeedUpdatePath); // } if (GUILayout.Button("Build Bundle", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { BundleAdapter.BuildBundles(); } if (GUILayout.Button("Build Bundle All", TableStyles.ToolbarButton, GUILayout.MaxWidth(140))) { //BundleAdapter.UpdateBundleBuildList(null); //BundleAdapter.BuildBundles(); } GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); int startY = toolbarHeight + border; int height = (int)(r.height - startY - border * 2); if (m_dataTable != null) { m_dataTable.Draw(new Rect(border, startY, r.width - border, (int)(height * split - border * 1.5f))); } if (m_showTable != null) { m_showTable.Draw(new Rect(border, (int)(height * split + border * 0.5f + startY), r.width - border, (int)(height * (1.0f - split) - border * 1.5f))); } GUILayout.EndVertical(); //GUILayout.EndArea(); }