private void AddAddressableAssets(Dictionary <int, List <UMATextRecipe> > tracker, AddressableAssetGroup sharedGroup) { float pos = 0.0f; float inc = 1.0f / tracker.Keys.Count; // Go through the each item, and add them to the groups (denoted by the list of recipes). // if an item is in 1 group, then it goes in that group. // if it's in more than 1 group, then it goes into the shared group. // if it's not in any group... not sure how we got there, but it does nothing. foreach (KeyValuePair <int, List <UMATextRecipe> > kp in tracker) { try { int iPos = Mathf.CeilToInt(pos); pos += inc; bool found = AssetDatabase.TryGetGUIDAndLocalFileIdentifier(kp.Key, out string GUID, out long localid); if (found) { EditorUtility.DisplayProgressBar("Generating", "Adding Asset " + GUID, iPos); AddressableAssetEntry ae = null; switch (kp.Value.Count) { case 0: Debug.LogWarning("Warning: No wardrobe found for item: " + kp.Key); continue; case 1: ae = AddressableUtility.AddressableSettings.CreateOrMoveEntry(GUID, GroupTracker[kp.Value[0].GetInstanceID()], false, true); break; default: ae = AddressableUtility.AddressableSettings.CreateOrMoveEntry(GUID, sharedGroup, false, true); break; } // modify ae here as needed... ae.SetAddress(AddressLookup[kp.Key]); AssetReference ar = new AssetReference(ae.guid); ae.SetLabel(umaBaseName, true, true, true); // get the name here foreach (UMATextRecipe uwr in kp.Value) { ae.SetLabel(UMAAssetIndexer.Instance.GetLabel(uwr), true, true, true); } } } catch (Exception ex) { Debug.LogException(ex); } } }
public void AddItemToSharedGroup(string GUID, string Address, List <string> labels, AddressableAssetGroup sharedGroup) { AddressableAssetEntry ae = AddressableUtility.AddressableSettings.CreateOrMoveEntry(GUID, sharedGroup, false, true); ae.SetAddress(Address); ae.SetLabel(umaBaseName, true, true, true); foreach (string s in labels) { ae.SetLabel(s, true, true, true); } }
public void ContentUpdateScenes_PackedTogetherByLabel_MarksAllScenesModifiedWithSharedLabel() { AddressableAssetGroup group = Settings.CreateGroup("SceneGroup", false, false, false, null, typeof(BundledAssetGroupSchema)); group.GetSchema <BundledAssetGroupSchema>().BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel; AddressableAssetEntry scene1 = new AddressableAssetEntry(m_SceneGuids[0], "scene1", group, false); AddressableAssetEntry scene2 = new AddressableAssetEntry(m_SceneGuids[1], "scene2", group, false); AddressableAssetEntry scene3 = new AddressableAssetEntry(m_SceneGuids[2], "scene3", group, false); group.AddAssetEntry(scene1, false); group.AddAssetEntry(scene2, false); group.AddAssetEntry(scene3, false); scene1.SetLabel("label", true); scene3.SetLabel("label", true); List <AddressableAssetEntry> modifedEnteries = new List <AddressableAssetEntry>() { scene1 }; ContentUpdateScript.AddAllDependentScenesFromModifiedEnteries(modifedEnteries); Assert.AreEqual(2, modifedEnteries.Count); Assert.AreEqual(scene1, modifedEnteries[0]); Assert.AreEqual(scene3, modifedEnteries[1]); Settings.RemoveGroup(group); }
/// <summary> /// 设置label /// </summary> /// <param name="entry"></param> /// <param name="listLabel"></param> public static void SetLabel(AddressableAssetEntry entry, List <string> listLabel) { for (int i = 0; i < listLabel.Count; i++) { entry.SetLabel(listLabel[i], true); } }
/// <summary> /// 关闭所有label /// </summary> /// <param name="entry"></param> public static void ClearAllLabel(AddressableAssetEntry entry) { AddressableAssetSettings Settings = AddressableAssetSettingsDefaultObject.Settings; List <string> listLabel = Settings.GetLabels(); for (int i = 0; i < listLabel.Count; i++) { entry.SetLabel(listLabel[i], false); } }
AddressableAssetEntry CreateEntry(string filePath, string groupName, string labelName) { string path = AssetDatabase.GUIDToAssetPath(AssetDatabase.FindAssets("t:AddressableAssetSettings").FirstOrDefault()); AddressableAssetSettings settings = AssetDatabase.LoadAssetAtPath <AddressableAssetSettings>(path); AddressableAssetGroup target = settings.groups.Find(c => c.name == groupName); string guid = AssetDatabase.AssetPathToGUID(filePath); AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, target, false, true); entry.SetAddress(filePath, true); entry.SetLabel(labelName, true, true); return(entry); }
static void CreateOrUpdateAddressableAssetEntry(AddressableAssetGroup group, string subPath, string fileName) { string filePath = subPath + "/" + fileName; string guid = AssetDatabase.AssetPathToGUID(filePath); AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, group); if (entry != null) { entry.address = fileName; entry.SetLabel(group.Name, true, true); } }
public void AssignLabel(AssetItem ai, string Label) { AddressableAssetEntry ae = AddressableUtility.GetAddressableAssetEntry(ai._Path); if (ae != null) { if (ae.labels.Contains(Label)) { return; } ae.SetLabel(Label, true, true, true); } }
/// <summary> /// 给某分组添加资源 /// </summary> /// <param name="group"></param> /// <param name="assetPath"></param> /// <param name="address"></param> /// <returns></returns> public static AddressableAssetEntry AddAssetEntry(AddressableAssetGroup group, string assetPath, string address) { string guid = AssetDatabase.AssetPathToGUID(assetPath); AddressableAssetSettings Settings = AddressableAssetSettingsDefaultObject.Settings; AddressableAssetEntry entry = group.entries.FirstOrDefault(e => e.guid == guid); if (entry == null) { entry = Settings.CreateOrMoveEntry(guid, group); } entry.address = address; entry.SetLabel(group.Name, true, false, false); return(entry); }
internal static void UpdateWordLibrary() { string groupName = "WordLibrary"; UnityEditor.EditorUtility.DisplayCancelableProgressBar("更新词库...", "", 0); AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(false); AddressableAssetGroup group = null; group = aaSettings.groups.Find(x => x.Name == groupName); if (group != null) { aaSettings.RemoveGroup(group); group = null; } group = aaSettings.CreateGroup(groupName, false, false, false, null); group.AddSchema <BundledAssetGroupSchema>(); string levelDir = string.Format("{0}/AssetsPackage/AnsycLoad/CodyLevel", Application.dataPath); if (!Directory.Exists(levelDir)) { Debug.LogError("路径不存在 " + levelDir); Directory.CreateDirectory(levelDir); } else { var files = Directory.GetFiles(levelDir); var index = 0; foreach (var item in files) { index++; UnityEditor.EditorUtility.DisplayCancelableProgressBar("更新词库...", Path.GetFileName(item), index / (float)files.Length); var extention = Path.GetExtension(item); if (extention.Equals(".txt")) { string guid = AssetDatabase.AssetPathToGUID(string.Format("Assets/AssetsPackage/AnsycLoad/CodyLevel/{0}", Path.GetFileName(item))); AddressableAssetEntry entity = aaSettings.CreateOrMoveEntry(guid, group); entity.SetAddress(Path.GetFileName(item)); bool result = entity.SetLabel("WordLibrary", true); Debug.Log("set label result " + result); } } } UnityEditor.EditorUtility.ClearProgressBar(); }
static void CreateAddressableAssetEntry(string path, string address, string label, string groupName = "Default Local Group") { #if UNITY_EDITOR AddressableAssetSettings settings; settings = AssetDatabase.LoadAssetAtPath <AddressableAssetSettings>("Assets/AddressableAssetsData/AddressableAssetSettings.asset"); AddressableAssetGroup group = settings.FindGroup(groupName); if (group == null) { group = settings.CreateGroup(groupName, false, false, false, null, typeof(BundledAssetGroupSchema)); } string assetGUID = AssetDatabase.AssetPathToGUID(path); AddressableAssetEntry entry = settings.CreateOrMoveEntry(assetGUID, group); entry.SetAddress(address); var labels = settings.GetLabels(); if (!labels.Contains(label)) { settings.AddLabel(label); } entry.SetLabel(label, true); #endif }
public static void AddFileToAddressables() { AddressablesRules rules = new AddressablesRules(); Dictionary <string, BuildAddressablesData> bundles = rules.GetBuilds(); AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(false); AddressableAssetGroup group = null; //清理错误group for (int i = aaSettings.groups.Count - 1; i >= 0; i--) { var g = aaSettings.groups[i]; if (g == null || g.entries.Count == 0) { aaSettings.RemoveGroup(g); g = null; continue; } // // if (g != null) // { // g.Name = $"{g.Name}_delete"; // } } foreach (string key in bundles.Keys) { group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); if (group == null) { group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null); } BundledAssetGroupSchema schema = group.GetSchema <BundledAssetGroupSchema>(); if (schema == null) { schema = group.AddSchema <BundledAssetGroupSchema>(); } ContentUpdateGroupSchema contentUpdateGroupSchema = group.GetSchema <ContentUpdateGroupSchema>(); if (contentUpdateGroupSchema == null) { contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>(); } schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4; if (bundles[key].packageType == "PackSeparately") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately; } else if (bundles[key].packageType == "PackTogether") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; } else if (bundles[key].packageType == "PackTogetherByLabel") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel; } schema.IncludeInBuild = true; schema.UseAssetBundleCache = true; schema.UseAssetBundleCrc = false; schema.UseAssetBundleCrcForCachedBundles = false; if (bundles[key].ResType == "online") { schema.BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteBuildPath); schema.LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteLoadPath); schema.BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.AppendHash; schema.UseAssetBundleCrc = true; contentUpdateGroupSchema.StaticContent = false; } else { schema.BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kLocalBuildPath); schema.LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kLocalLoadPath); schema.BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash; contentUpdateGroupSchema.StaticContent = true; } } foreach (string key in bundles.Keys) { int count = 0; int MaxCount = bundles[key].entitys.Count; group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); foreach (string entitysKey in bundles[key].entitys.Keys) { count++; if (count % 3 == 0) { if (UnityEditor.EditorUtility.DisplayCancelableProgressBar(string.Format("Collecting... [{0}/{1}]", count, MaxCount), entitysKey, count * 1f / MaxCount)) { break; } } string guid = AssetDatabase.AssetPathToGUID(bundles[key].entitys[entitysKey].filestring); AddressableAssetEntry entity = aaSettings.CreateOrMoveEntry(guid, group); entity.SetAddress(entitysKey); for (int i = 0; i < bundles[key].Lable.Length; i++) { if (bundles[key].Lable[i].Contains("#")) { if (!string.IsNullOrEmpty(bundles[key].entitys[entitysKey].folderlabel)) { aaSettings.AddLabel(bundles[key].entitys[entitysKey].folderlabel); entity.SetLabel(bundles[key].entitys[entitysKey].folderlabel, true); } } else { aaSettings.AddLabel(bundles[key].Lable[i]); entity.SetLabel(bundles[key].Lable[i], true); } } } } // for (int i = aaSettings.groups.Count - 1; i >= 0; i--) // { // var g = aaSettings.groups[i]; // if (g == null || g.entries.Count == 0) // { // aaSettings.RemoveGroup(g); // g = null; // continue; // } // // if (g != null) // { // if (g.Name.Contains("_delete")) // { // aaSettings.RemoveGroup(g); // g = null; // } // } // } UnityEditor.EditorUtility.ClearProgressBar(); }
private static void GenerateWithAssetRule(AddressableAssetSettings settings, GenerateSetting generateSetting, AddressableAssetGroup group, GroupRule groupRule, AssetRule assetRule) { int assetsIndexOf = Application.dataPath.LastIndexOf("Assets"); string realPath = Application.dataPath.Substring(0, assetsIndexOf) + assetRule.Path; if (!Directory.Exists(realPath)) { Debug.LogError(string.Format("Path ({0}) of group ({1}) not exists", realPath, groupRule.GroupName)); return; } DirectoryInfo directoryInfo = new DirectoryInfo(realPath); FileInfo[] files = directoryInfo.GetFiles("*.*", assetRule.IncludeChilder ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); for (int iFile = 0; iFile < files.Length; iFile++) { FileInfo iterFile = files[iFile]; string iterFileName = iterFile.Name.Substring(0, iterFile.Name.Length - iterFile.Extension.Length); // meta文件肯定是要忽略的 if (iterFile.Extension == ".meta") { continue; } if (!Filter(assetRule.ExtensionFilterType, iterFile.Extension, assetRule.ExtensionFilters) || !Filter(assetRule.FileNameFilterType, iterFileName, assetRule.FileNameFilters)) { continue; } string iterAssetPath = iterFile.FullName.Substring(assetsIndexOf); string assetKey; switch (assetRule.AssetKeyType) { case AssetKeyType.FileName: assetKey = iterFileName; break; case AssetKeyType.FileNameFormat: assetKey = string.Format(assetRule.AssetKeyFormat, iterFileName); break; case AssetKeyType.Path: // Unity默认的路径分隔符是'/' assetKey = iterAssetPath.Replace('\\', '/'); break; default: assetKey = string.Empty; throw new System.Exception(string.Format("not support ExtensionFilterType ({0})", assetRule.ExtensionFilterType)); } string iterAssetGuid = AssetDatabase.AssetPathToGUID(iterAssetPath); AddressableAssetEntry iterAssetEntry = AddressableAssetSettingsDefaultObject.Settings.CreateOrMoveEntry(iterAssetGuid, group); if (iterAssetEntry == null) { Debug.LogError(string.Format("Cant load asset at path ({0})", iterAssetPath)); } iterAssetEntry.SetAddress(assetKey); for (int iLabel = 0; iLabel < assetRule.AssetLables.Length; iLabel++) { iterAssetEntry.SetLabel(assetRule.AssetLables[iLabel], true); } } }
void OnWizardCreate() { //save/update any editor prefs we have changed EditorPrefs.SetString("ARW_Prefix0", prefix0); EditorPrefs.SetString("ARW_Prefix1", prefix1); EditorPrefs.SetString("ARW_Prefix2", prefix2); EditorPrefs.SetString("ARW_Postfix0", postfix0); EditorPrefs.SetBool("ARW_Prepend", prependFolderName); string[] assetGUIDs = Selection.assetGUIDs; if (assetGUIDs != null) { AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings; if (settings == null) { Debug.LogError("Could not find AddressableAssetSettings!"); return; } var entries = new List <AddressableAssetEntry>(); StringBuilder newAddress = new StringBuilder(50); foreach (string assetGUID in assetGUIDs) { AddressableAssetEntry entry = settings.FindAssetEntry(assetGUID); if (entry != null) { string assetName = Path.GetFileNameWithoutExtension(entry.AssetPath); string folderName = Path.GetFileName(Path.GetDirectoryName(entry.AssetPath)); newAddress.Clear(); if (!string.IsNullOrEmpty(prefix0)) { newAddress.Append(prefix0); newAddress.Append("."); } if (!string.IsNullOrEmpty(prefix1)) { newAddress.Append(prefix1); newAddress.Append("."); } if (!string.IsNullOrEmpty(prefix2)) { newAddress.Append(prefix2); newAddress.Append("."); } if (prependFolderName) { newAddress.Append(folderName); newAddress.Append("."); } newAddress.Append(assetName); if (!string.IsNullOrEmpty(postfix0)) { newAddress.Append("."); newAddress.Append(postfix0); } entry.SetAddress(newAddress.ToString(), false); foreach (string label in labelsToAdd) { entry.SetLabel(label, true, false, false); } foreach (string label in labelsToRemove) { entry.SetLabel(label, false, false, false); } entries.Add(entry); } else { string assetPath = AssetDatabase.GUIDToAssetPath(assetGUID); if (string.IsNullOrEmpty(assetPath)) { Debug.LogWarning(assetGUID + " is not marked as Addressable."); } else { Debug.LogWarning(assetPath + " is not marked as Addressable."); } } } settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, entries, true, false); } }
public static void AddFileToAddressables() { AddressablesRules rules = new AddressablesRules(); Dictionary <string, BuildAddressablesData> bundles = rules.GetBuilds(); AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.GetSettings(false); AddressableAssetGroup group = null; //清理重名group foreach (string key in bundles.Keys) { group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); if (group != null) { aaSettings.RemoveGroup(group); group = null; } } foreach (string key in bundles.Keys) { group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); if (group == null) { if (bundles[key].ResType == "online") { group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null); BundledAssetGroupSchema schema = group.AddSchema <BundledAssetGroupSchema>(); schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4; if (bundles[key].packageType == "PackSeparately") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately; } else if (bundles[key].packageType == "PackTogether") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; } else if (bundles[key].packageType == "PackTogetherByLabel") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel; } schema.BuildPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteBuildPath); schema.LoadPath.SetVariableByName(group.Settings, AddressableAssetSettings.kRemoteLoadPath); schema.UseAssetBundleCache = true; schema.UseAssetBundleCrc = true; ContentUpdateGroupSchema contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>(); contentUpdateGroupSchema.StaticContent = false; group = null; } else { group = aaSettings.CreateGroup(bundles[key].GroupName, false, false, false, null); BundledAssetGroupSchema schema = group.AddSchema <BundledAssetGroupSchema>(); schema.Compression = BundledAssetGroupSchema.BundleCompressionMode.Uncompressed; if (bundles[key].packageType == "PackSeparately") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately; } else if (bundles[key].packageType == "PackTogether") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; } else if (bundles[key].packageType == "PackTogetherByLabel") { schema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogetherByLabel; } if (bundles[key].canUpdate) { ContentUpdateGroupSchema contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>(); contentUpdateGroupSchema.StaticContent = false; } schema.UseAssetBundleCache = true; schema.UseAssetBundleCrc = true; group = null; } } } foreach (string key in bundles.Keys) { int count = 0; int MaxCount = bundles[key].entitys.Count; group = aaSettings.groups.Find(x => x.Name == bundles[key].GroupName); foreach (string entitysKey in bundles[key].entitys.Keys) { count++; if (count % 3 == 0) { if (UnityEditor.EditorUtility.DisplayCancelableProgressBar( string.Format("Collecting... [{0}/{1}]", count, MaxCount), entitysKey, count * 1f / MaxCount)) { break; } } string guid = AssetDatabase.AssetPathToGUID(bundles[key].entitys[entitysKey]); AddressableAssetEntry entity = aaSettings.CreateOrMoveEntry(guid, group); entity.SetAddress(entitysKey); for (int i = 0; i < bundles[key].Lable.Length; i++) { aaSettings.AddLabel(bundles[key].Lable[i]); entity.SetLabel(bundles[key].Lable[i], true); } } } UnityEditor.EditorUtility.ClearProgressBar(); }