/// <summary> /// 在 Addressables Groups 动态创建groups /// </summary> private static void addAddressablesGroups() { //先创建一个global AASUtility.CreateGroup("global", false); return; }
/// <summary> /// mark 单个文件 /// </summary> /// <param name="path"></param> static void MarkedSingleFile(string path) { //Logger.LogError("file path:" + path); string temp_path = path.Replace("Assets/AssetsPackage/", ""); //Logger.LogError("temp_path:" + temp_path); string[] path_list = temp_path.Split('/'); string groupName = "tempgroup"; if (path_list.Length > 1) { string validation_path = "Assets/AssetsPackage/" + path_list[0] + "/" + path_list[1]; if (path_list.Length > 2)//是文件,没有二级目录 { //Logger.LogError("二级目录:" + path); groupName = path_list[0].ToLower() + "_" + path_list[1].ToLower(); } else { //Logger.LogError("一级目录 :" + path); groupName = path_list[0].ToLower(); } var guid = UnityEditor.AssetDatabase.AssetPathToGUID(path); AASUtility.AddAssetToGroup(guid, groupName); } else { Debug.LogError("file path error:" + path); } }
static public bool AddGroup(string asset) { var dir = System.IO.Path.GetDirectoryName(asset); //グループに含めていいかのチェック //ディレクトリとエディターディレクトリのアセットは含めない if (System.IO.Directory.Exists(asset)) { return(false); } if (dir.Contains(editorDir)) { return(false); } //アドレス名を求める計算 var filename = System.IO.Path.GetFileName(asset); dir = dir.Replace(assetRoot, ""); string group = dir.Replace(System.IO.Path.DirectorySeparatorChar, '_'); var address = group + "_" + System.IO.Path.GetFileNameWithoutExtension(asset); AASUtility.AddAssetToGroup(AssetDatabase.AssetPathToGUID(asset), group, address); return(true); }
public static void AddImportAssetToaddressable(string path) { string dir = Path.GetDirectoryName(path); int index = dir.IndexOf(Assets_Package + Path.DirectorySeparatorChar); if (index < 0) { return; } dir = dir.Substring(index + (Assets_Package + Path.DirectorySeparatorChar).Length); index = dir.IndexOf(Path.DirectorySeparatorChar); if (index > 0) { index = dir.IndexOf(Path.DirectorySeparatorChar, index + 1); if (index > 0) { dir = dir.Substring(0, index); } } string groupName = dir.ToLower().Replace(Path.DirectorySeparatorChar, '_'); string guid = AssetDatabase.AssetPathToGUID(path); AASUtility.AddAssetToGroup(guid, groupName); }
public void CheckAssetBundleName() { var checkerFilters = config.CheckerFilters; if (checkerFilters == null || checkerFilters.Count == 0) { CheckAddressablePath(new DirectoryInfo(assetsPath)); } else { foreach (var checkerFilter in checkerFilters) { var relativePath = assetsPath; if (!string.IsNullOrEmpty(checkerFilter.RelativePath)) { relativePath = Path.Combine(assetsPath, checkerFilter.RelativePath); } var groupName = config.PackagePath.Replace("/", "-").ToLower(); string[] objGuids = AssetDatabase.FindAssets(checkerFilter.ObjectFilter, new string[] { relativePath }); foreach (var guid in objGuids) { AASUtility.AddAssetToGroup(guid, groupName); } } } }
public static void SingleFileAddress(string group, string path) { string relativePath = path.Substring(path.IndexOf("Assets\\")); Logger.Log(relativePath); AASUtility.AddAssetToGroup(AssetDatabase.AssetPathToGUID(relativePath), group); }
public void CheckAssetBundleName(string is_atlas_model, Dictionary <string, List <string> > groupDi) { var checkerFilters = config.CheckerFilters; //Debug.LogError("checkffilters" + checkerFilters); if (checkerFilters == null || checkerFilters.Count == 0) { var di = new DirectoryInfo(assetsPath); CheckAddressablePath(di, is_atlas_model, groupDi); //Logger.LogError("==========CheckAssetBundleName====5=====" + assetsPath); } else { foreach (var checkerFilter in checkerFilters) { var relativePath = assetsPath; if (!string.IsNullOrEmpty(checkerFilter.RelativePath)) { relativePath = Path.Combine(assetsPath, checkerFilter.RelativePath); } var groupName = config.PackagePath.Replace("/", "_").Replace("\\", "_").ToLower(); string[] objGuids = AssetDatabase.FindAssets(checkerFilter.ObjectFilter, new string[] { relativePath }); foreach (var guid in objGuids) { AASUtility.AddAssetToGroup(guid, groupName); } } } }
/// <summary> /// 将所以的groups 设置成Remote_Static模式 /// </summary> public static void SetAllGroupsToRemoteStatic() { AddressableAssetSettings settings = AASUtility.GetSettings(); foreach (var group in settings.groups) { SetGroupsSetting(group, true, true, BundledAssetGroupSchema.BundleNamingStyle.AppendHash, AddressableAssetSettings.kRemoteBuildPath, AddressableAssetSettings.kRemoteLoadPath, true); } }
/// <summary> /// 将所以的groups 设置成Local_Static模式 /// </summary> public static void SetAllGroupsToLocalStatic() { AddressableAssetSettings settings = AASUtility.GetSettings(); foreach (var group in settings.groups) { SetGroupsSetting(group, false, false, BundledAssetGroupSchema.BundleNamingStyle.NoHash, AddressableAssetSettings.kLocalBuildPath, AddressableAssetSettings.kLocalLoadPath, true); } }
/// <summary> /// 将所以的groups 设置成Remote_NoStatic模式 /// </summary> public static void SetAllGroupsToRemoteNoStatic() { AddressableAssetSettings settings = AASUtility.GetSettings(); settings.OverridePlayerVersion = "1"; foreach (var group in settings.groups) { SetGroupsSetting(group, true, true, BundledAssetGroupSchema.BundleNamingStyle.NoHash, AddressableAssetSettings.kRemoteBuildPath, AddressableAssetSettings.kRemoteLoadPath, false); } }
public static string assetsPath = Path.Combine(Application.dataPath, Assets_Package); //资源目录 public static void RunCheckAssetBundle(bool _is_atlas_model = true) { EditorUserSettings.SetConfigValue(is_atlas_model, _is_atlas_model ? "1" : "0"); //先把之前的config删除 clear(assetspackageConfigPath); AddressableAssetSettings settings = AASUtility.GetSettings(); foreach (var group in settings.groups) { if (group == null) { Debug.LogError("addressable坏了"); } } //动态增加 addressables groups addAddressablesGroups(); //动态增加 config refreshConfig(); CheckAssetBundles.Run(); string assetFolder = Path.Combine(Application.dataPath, AssetBundleConfig.AssetsFolderName); //特殊文件 string app_version = Path.Combine(assetFolder, BuildUtils.AppVersionFileName); string assets_map = Path.Combine(assetFolder, AssetBundleConfig.AssetsPathMapFileName); string channel_name = Path.Combine(assetFolder, BuildUtils.ChannelNameFileName); string notice_version = Path.Combine(assetFolder, BuildUtils.NoticeVersionFileName); string res_version = Path.Combine(assetFolder, BuildUtils.ResVersionFileName); string ifix_map = Path.Combine(assetFolder, BuildUtils.IfixMapFileName); string config = Path.Combine(assetFolder, BuildUtils.ConfigFileName); SingleFileAddress("global", app_version); SingleFileAddress("global", assets_map); SingleFileAddress("global", channel_name); SingleFileAddress("global", notice_version); SingleFileAddress("global", res_version); SingleFileAddress("global", ifix_map); SingleFileAddress("global", config); //设置AssetBundle Provider SetAllGroupsToAssetBundleEncryptProvider(); //设置Asset Address SetAssetAddressAndLabel(); //将资源全部打成远程模式 SetAllGroupsToRemoteNoStatic(); }
private static void SetAllGroupsToAssetBundleEncryptProvider() { AddressableAssetSettings settings = AASUtility.GetSettings(); foreach (var group in settings.groups) { BundledAssetGroupSchema bundledAssetGroupSchema = group.GetSchema <BundledAssetGroupSchema>(); if (bundledAssetGroupSchema == null) { bundledAssetGroupSchema = group.AddSchema <BundledAssetGroupSchema>(); } bundledAssetGroupSchema.SetAssetBundleProviderType(typeof(AssetBundleEncryptProvider)); EditorUtility.SetDirty(bundledAssetGroupSchema); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public static void RunCheckAssetBundle() { var initGroups = new string[] { "static_effect", "static_js", "static_models", "static_shaders", "static_fb", "static_fairygui" }; var start = DateTime.Now; //初始化Groups foreach (var g in initGroups) { AASUtility.CreateGroup(g); } Debug.Log("Finished Update Asset Path Map... " + (DateTime.Now - start).TotalSeconds + "s"); }
public void CheckAddressablePath(DirectoryInfo di) { var groupName = config.PackagePath.Replace("/", "-").ToLower(); FileInfo[] fis = di.GetFiles(); foreach (FileInfo f in fis) { if (f.Extension.Equals(".meta")) { continue; } string relativePath = f.FullName.Substring(f.FullName.IndexOf("\\Assets\\") + 1); AASUtility.AddAssetToGroup(AssetDatabase.AssetPathToGUID(relativePath), groupName); } DirectoryInfo[] dis = di.GetDirectories(); foreach (DirectoryInfo d in dis) { CheckAddressablePath(d); } }
public static void RunCheckAssetBundle() { var initGroups = new string[] { "static_effect", "static_js", "static_models", "static_shaders", "static_ui", "static_fb", "static_jsmap", "static_fairygui" }; var start = DateTime.Now; //更新assetmap List <AddressableAssetEntry> assets = new List <AddressableAssetEntry>(); AASUtility.GetSettings().GetAllAssets(assets, false, (g) => { return(g.name.Equals("static_js")); }); string[] address = assets.Select(e => e.address).ToArray(); string assetFolder = Path.Combine(Application.dataPath, AddressableConfig.AssetsFolderName); var assetPathMap = Path.Combine(assetFolder, AddressableConfig.AssetsPathMapFileName); GameUtility.SafeWriteAllLines(assetPathMap, address); AssetDatabase.Refresh(); //初始化Groups foreach (var g in initGroups) { AASUtility.CreateGroup(g); } Debug.Log("Finished Update Asset Path Map... " + (DateTime.Now - start).TotalSeconds + "s"); }
public static void HandleProject() { //清除图集 //AltasHelper.ClearAllAtlas(); AASUtility.CleanPlayerContent(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); //生成图集 // AltasHelper.GeneratingAtlas(); //Marked AssetsPackage Addressable AddressableTools.RunCheckAssetBundle(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); //Build Default Build Script AddressableTools.BuildPlayerContent(); }
/// <summary> /// 自动设置asset的label,如果是皮肤下面的asset则会同时修改其address, 同时会将带皮肤的asset写入到文件中 /// /// </summary> public static void SetAssetAddressAndLabel() { Debug.Log("SetAllGroupsLabel Begin"); var setting = AASUtility.GetSettings(); foreach (var group in setting.groups) { string label = "default"; List <AddressableAssetEntry> assetEntry = new List <AddressableAssetEntry>(); group.GatherAllAssets(assetEntry, true, true, false); for (var i = 0; i < assetEntry.Count; i++) { //先清除掉asset身上的labels var labels = assetEntry[i].labels.ToArray <string>(); if (labels.Length == 1) { if (labels[0] != label) { for (var j = 0; j < labels.Length; j++) { assetEntry[i].SetLabel(labels[j], false); } assetEntry[i].SetLabel(label, true, true); } } else { for (var j = 0; j < labels.Length; j++) { assetEntry[i].SetLabel(labels[j], false); } assetEntry[i].SetLabel(label, true, true); } } } AssetDatabase.Refresh(); Debug.Log("SetAllGroupsLabel Finished"); }
public static void RunCheckAssetBundle() { var start = DateTime.Now; CheckAssetBundles.Run(); //更新assetmap List <AddressableAssetEntry> assets = new List <AddressableAssetEntry>(); AASUtility.GetSettings().GetAllAssets(assets, false, (g) => { return(g.name.Equals("lua")); }); string[] address = assets.Select(e => e.address).ToArray(); string assetPathMap = Path.Combine(Application.dataPath, AssetBundleConfig.AssetsFolderName); assetPathMap = Path.Combine(assetPathMap, AssetBundleConfig.AssetsPathMapFileName); GameUtility.SafeWriteAllLines(assetPathMap, address); AssetDatabase.Refresh(); //特殊文件 string app_version = Path.Combine(assetPathMap, "app_version.bytes"); string assets_map = Path.Combine(assetPathMap, "AssetsMap.bytes"); string channel_name = Path.Combine(assetPathMap, "channel_name.bytes"); string notice_version = Path.Combine(assetPathMap, "notice_version.bytes"); string res_version = Path.Combine(assetPathMap, "res_version.bytes"); SingleFileAddress("global", app_version); SingleFileAddress("global", assets_map); SingleFileAddress("global", channel_name); SingleFileAddress("global", notice_version); SingleFileAddress("global", res_version); Debug.Log("Finished CheckAssetBundles.Run! use " + (DateTime.Now - start).TotalSeconds + "s"); }
public static void SingleFileAddress(string group, string path) { string relativePath = path.Substring(path.IndexOf("Assets" + Path.DirectorySeparatorChar)); AASUtility.AddAssetToGroup(AssetDatabase.AssetPathToGUID(relativePath), group); }
public static void BuildPlayerContent() { AASUtility.BuildPlayerContent(); }
static void BuildHandle(PlatformType type, BuildOptions buildOptions, bool isBuildExe, bool clearFolder, bool isInject) { BuildTarget buildTarget = BuildTarget.StandaloneWindows; string programName = "ET"; string exeName = programName; string platform = ""; switch (type) { case PlatformType.PC: buildTarget = BuildTarget.StandaloneWindows64; exeName += ".exe"; IFixEditor.Patch(); platform = "pc"; break; case PlatformType.Android: KeystoreSetting(); buildTarget = BuildTarget.Android; exeName += ".apk"; IFixEditor.CompileToAndroid(); platform = "android"; break; case PlatformType.IOS: buildTarget = BuildTarget.iOS; IFixEditor.CompileToIOS(); platform = "ios"; break; case PlatformType.MacOS: buildTarget = BuildTarget.StandaloneOSX; IFixEditor.Patch(); platform = "pc"; break; } //打程序集 BuildAssemblieEditor.BuildCodeRelease(); if (isInject) { //Inject IFixEditor.InjectAssemblys(); } HandleProject(); //string fold = string.Format(BuildFolder, type); if (clearFolder && Directory.Exists(relativeDirPrefix)) { Directory.Delete(relativeDirPrefix, true); Directory.CreateDirectory(relativeDirPrefix); } else { Directory.CreateDirectory(relativeDirPrefix); } if (isBuildExe) { AssetDatabase.Refresh(); string[] levels = { "Assets/AssetsPackage/Scenes/InitScene/Init.unity", }; UnityEngine.Debug.Log("开始EXE打包"); BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions); UnityEngine.Debug.Log("完成exe打包"); } string jstr = File.ReadAllText("Assets/AssetsPackage/config.bytes"); var obj = LitJson.JsonMapper.ToObject <Dictionary <string, string> >(jstr); string version = obj["ResVer"]; var settings = AASUtility.GetSettings(); string fold = Directory.GetParent(settings.RemoteCatalogBuildPath.GetValue(settings)).FullName; string targetPath = Path.Combine(relativeDirPrefix, $"{version}_{platform}"); if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } FileHelper.CleanDirectory(targetPath); FileHelper.CopyFiles(fold, targetPath); UnityEngine.Debug.Log("完成cdn资源打包"); }
private static void RunAllCheckersTask() { ThreadPars[] threadParses = new ThreadPars[ThreadCount]; for (int index = 0; index < ThreadCount; index++) { threadParses[index] = new ThreadPars(); } var guids = AssetDatabase.FindAssets("t:AddressableDispatcherConfig", new string[] { AddressableInspectorUtils.DatabaseRoot }); var length = guids.Length; var count = 0; foreach (var guid in guids) { count++; var assetPath = AssetDatabase.GUIDToAssetPath(guid); var config = AssetDatabase.LoadAssetAtPath <AddressableDispatcherConfig>(assetPath); config.Load(); int index = count % ThreadCount; threadParses[index].ChildDataList.Add(config); threadParses[index].is_atlas_model = EditorUserSettings.GetConfigValue(AddressableTools.is_atlas_model); } List <Task <Dictionary <string, List <string> > > > taskList = new List <Task <Dictionary <string, List <string> > > >(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[0])); })); taskList[0].Start(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[1])); })); taskList[1].Start(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[2])); })); taskList[2].Start(); taskList.Add(new Task <Dictionary <string, List <string> > >(() => { return(ThreadFind(threadParses[3])); })); taskList[3].Start(); for (int i = 0; i < ThreadCount; i++) { taskList[i].Wait(); } //Logger.LogError("=======over========="); Dictionary <string, UnityEditor.AddressableAssets.Settings.AddressableAssetGroup> groupsDic = new Dictionary <string, UnityEditor.AddressableAssets.Settings.AddressableAssetGroup>(); for (int i = 0; i < ThreadCount; i++) { foreach (var keyvalue in taskList[i].Result) { keyvalue.Value.Sort(); foreach (var pathStr in keyvalue.Value) { //Logger.LogError("path:" + pathStr + " groupName:" + keyvalue.Key); if (!groupsDic.ContainsKey(keyvalue.Key)) { groupsDic.Add(keyvalue.Key, AASUtility.CreateGroup(keyvalue.Key)); } UnityEditor.AddressableAssets.Settings.AddressableAssetEntry temp_entry = null; var s = AASUtility.GetSettings(); foreach (UnityEditor.AddressableAssets.Settings.AddressableAssetGroup group in s.groups) { if (group == null) { continue; } foreach (UnityEditor.AddressableAssets.Settings.AddressableAssetEntry entry in group.entries) { //Logger.LogError("entry.AssetPath:" + entry.AssetPath + " pathstr:" + pathStr + " group.name:" + group.name + " keyvalue.key:" + keyvalue.Key); if ((entry.AssetPath.Replace('\\', '/') == pathStr.Replace('\\', '/')) && (group.name == keyvalue.Key)) { //Logger.LogError("============temp_entry=====================" + pathStr); temp_entry = entry; } } } if (temp_entry == null) { //Logger.LogError("=================================" + pathStr); var guid = AssetDatabase.AssetPathToGUID(pathStr); AASUtility.AddAssetToGroup(guid, keyvalue.Key); } } } } AssetDatabase.Refresh(); }