public void WhenAddressHasSquareBracketsAndGuidIsNotEmptyString_SettingTheAddressOnExistingEntry_ThrowsError() { AddressableAssetEntry entry = new AddressableAssetEntry("12345698655", "Entry", null, false); entry.SetAddress("[Entry]"); LogAssert.Expect(LogType.Error, $"Address '{entry.address}' cannot contain '[ ]'."); }
private void AddItemToGroup(AddressableAssetGroup theGroup, UnityEngine.Object theItem, string Address, string Label) { bool found = AssetDatabase.TryGetGUIDAndLocalFileIdentifier(theItem.GetInstanceID(), out string itemGUID, out long localID); if (found) { AddressableAssetEntry ae = AddressableUtility.AddressableSettings.CreateOrMoveEntry(itemGUID, theGroup, false, true); ae.SetAddress(Address); ae.labels.Add(Label); } }
static void Add() { AddressableAssetSettings setting = AssetDatabase.LoadAssetAtPath <AddressableAssetSettings>("Assets/AddressableAssetsData/AddressableAssetSettings.asset"); foreach (GameObject o in Selection.gameObjects) { AddressableAssetEntry entry = setting.CreateOrMoveEntry(AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(o)), setting.DefaultGroup); string[] s = AssetDatabase.GetAssetPath(o).Split('/'); entry.SetAddress(s[s.Length - 1]); } }
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); } }
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); }
public static void ProcessMove(string path) { string guid = AssetDatabase.AssetPathToGUID(path); AddressableAssetEntry entry = Settings.FindAssetEntry(guid); if (entry != null) { Settings.RemoveAssetEntry(guid); entry = Settings.CreateOrMoveEntry(guid, Settings.DefaultGroup); entry.SetAddress(NormalizeAddress(path)); Settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, null, true); Settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryModified, null, true); Settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, null, true); } }
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(); }
void OnWizardCreate() { //save/update any editor prefs we have changed EditorPrefs.SetString("ARW_append", append); EditorPrefs.SetString("ARW_search", search); EditorPrefs.SetString("ARW_replace", replace); 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>(); foreach (string assetGUID in assetGUIDs) { AddressableAssetEntry entry = settings.FindAssetEntry(assetGUID); if (entry != null) { string newAddress = append + entry.address; if (!string.IsNullOrEmpty(search)) { newAddress = newAddress.Replace(search, replace); } entry.SetAddress(newAddress, 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); } }
internal static void UpdateAssetAddresses(YarnProjectImporter importer) { #if USE_ADDRESSABLES var lineIDs = importer.GenerateStringsTable().Select(s => s.ID); // Get a map of language IDs to (lineID, asset path) pairs var languageToAssets = importer // Get the languages-to-source-assets map .languagesToSourceAssets // Get the asset folder for them .Select(l => new { l.languageID, l.assetsFolder }) // Only consider those that have an asset folder .Where(f => f.assetsFolder != null) // Get the path for the asset folder .Select(f => new { f.languageID, path = AssetDatabase.GetAssetPath(f.assetsFolder) }) // Use that to get the assets inside these folders .Select(f => new { f.languageID, assetPaths = FindAssetPathsForLineIDs(lineIDs, f.path) }); var addressableAssetSettings = AddressableAssetSettingsDefaultObject.Settings; foreach (var languageToAsset in languageToAssets) { var assets = languageToAsset.assetPaths .Select(pair => new { LineID = pair.Key, GUID = AssetDatabase.AssetPathToGUID(pair.Value) }); foreach (var asset in assets) { // Find the existing entry for this asset, if it has // one. AddressableAssetEntry entry = addressableAssetSettings.FindAssetEntry(asset.GUID); if (entry == null) { // This asset didn't have an entry. Create one in // the default group. entry = addressableAssetSettings.CreateOrMoveEntry(asset.GUID, addressableAssetSettings.DefaultGroup); } // Update the entry's address. entry.SetAddress(Localization.GetAddressForLine(asset.LineID, languageToAsset.languageID)); } } #else throw new System.NotSupportedException($"A method that requires the Addressable Assets package was called, but USE_ADDRESSABLES was not defined. Please either install Addressable Assets, or if you have already, add it to this project's compiler definitions."); #endif }
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 }
private static void AddAssetToGroup(string assetGuid, string groupName, string address = null) { AddressableAssetSettings settings = GetSettings(); AddressableAssetGroup assetGroup = CreateGroup(groupName); AddressableAssetEntry assetEntry = settings.CreateOrMoveEntry(assetGuid, assetGroup); if (address == null) { return; } List <AddressableAssetEntry> entries = new List <AddressableAssetEntry>(); settings.GetAllAssets(entries, true); if (CheckAddress(entries, address)) { assetEntry.SetAddress(address); } else { Debug.LogAssertion("Duplicate Address"); } }
private static void CreateAddressableSettings(bool localMode, int releaseChannel) { AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.GetSettings(true); settings.ActivePlayModeDataBuilderIndex = localMode ? 0 : 2; settings.BuildRemoteCatalog = true; settings.DisableCatalogUpdateOnStartup = true; settings.ContiguousBundles = true; settings.IgnoreUnsupportedFilesInBuild = true; settings.ShaderBundleNaming = ShaderBundleNaming.Custom; // don't include built-in data, causes shader issues settings.groups.ForEach(g => { PlayerDataGroupSchema schema = g.GetSchema <PlayerDataGroupSchema>(); if (schema != null) { schema.IncludeBuildSettingsScenes = false; schema.IncludeResourcesFolders = false; } }); // setup profiles AddressableAssetProfileSettings profile = settings.profileSettings; // activate and (re)group assets foreach (string dir in GetWorldPaths()) { string worldName = Path.GetFileName(dir); bool isBase = worldName == "Base"; // create one profile per world string profileId = profile.GetProfileId(worldName); if (string.IsNullOrEmpty(profileId)) { profileId = profile.AddProfile(worldName, settings.activeProfileId); } string guid = AssetDatabase.AssetPathToGUID($"Assets/Worlds/{worldName}"); // create group if non-existent AddressableAssetGroup group = settings.groups.FirstOrDefault(g => g.name == worldName); if (group == null) { group = CreateAssetGroup <BundledAssetGroupSchema>(settings, worldName); } if (group.CanBeSetAsDefault()) { settings.DefaultGroup = group; // default group ensures there is no accidental local default group resulting in local paths being baked into addressable for shaders } // set correct path AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, group); entry.SetAddress($"Worlds/{worldName}"); // set variables string localRoot = Application.dataPath + $"/../traVRsal/{worldName}/[BuildTarget]"; string remoteTarget = null; switch (releaseChannel) { case 0: remoteTarget = AWSUtil.S3CDNRoot_Live; break; case 1: remoteTarget = AWSUtil.S3CDNRoot_Beta; break; case 2: remoteTarget = AWSUtil.S3CDNRoot_Alpha; break; } profile.SetValue(profileId, AddressableAssetSettings.kLocalBuildPath, localRoot); profile.SetValue(profileId, AddressableAssetSettings.kLocalLoadPath, localRoot); profile.SetValue(profileId, AddressableAssetSettings.kRemoteBuildPath, $"ServerData/Worlds/{worldName}/[BuildTarget]"); profile.SetValue(profileId, AddressableAssetSettings.kRemoteLoadPath, $"{remoteTarget}Worlds/{worldName}/[BuildTarget]"); // ensure correct group settings BundledAssetGroupSchema groupSchema = group.GetSchema <BundledAssetGroupSchema>(); groupSchema.UseAssetBundleCache = true; groupSchema.UseAssetBundleCrc = false; groupSchema.IncludeInBuild = isBase; groupSchema.RetryCount = 3; groupSchema.BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash; // hash to disambiguate identically named files yields same error messages, e.g. standard shaders groupSchema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; groupSchema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4; groupSchema.BuildPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalBuildPath : AddressableAssetSettings.kRemoteBuildPath); groupSchema.LoadPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalLoadPath : AddressableAssetSettings.kRemoteLoadPath); } }
static void SetAaEntry(AddressableAssetSettings aaSettings, List <TargetInfo> targetInfos, bool create) { /* * if (create && aaSettings.DefaultGroup.ReadOnly) * { * Debug.LogError("Current default group is ReadOnly. Cannot add addressable assets to it"); * return; * } */ Undo.RecordObject(aaSettings, "AddressableAssetSettings"); if (!create) { List <AddressableAssetEntry> removedEntries = new List <AddressableAssetEntry>(targetInfos.Count); for (int i = 0; i < targetInfos.Count; ++i) { AddressableAssetEntry e = aaSettings.FindAssetEntry(targetInfos[i].Guid); AddressableAssetUtility.OpenAssetIfUsingVCIntegration(e.parentGroup); removedEntries.Add(e); aaSettings.RemoveAssetEntry(removedEntries[i], false); } if (removedEntries.Count > 0) { aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryRemoved, removedEntries, true, false); } } else { AddressableAssetGroup parentGroup = aaSettings.DefaultGroup; var resourceTargets = targetInfos.Where(ti => AddressableAssetUtility.IsInResources(ti.Path)); if (resourceTargets.Any()) { var resourcePaths = resourceTargets.Select(t => t.Path).ToList(); var resourceGuids = resourceTargets.Select(t => t.Guid).ToList(); AddressableAssetUtility.SafeMoveResourcesToGroup(aaSettings, parentGroup, resourcePaths, resourceGuids); } var entriesCreated = new List <AddressableAssetEntry>(); var entriesMoved = new List <AddressableAssetEntry>(); var otherTargetInfos = targetInfos.Except(resourceTargets); foreach (var info in otherTargetInfos) { var hook = aaSettings.hook; AddressableAssetGroup assetGroup = default; string customAddress = default; if (hook != null) { hook.BeforeSetEntryOnInspectorGUI(info.Path, out assetGroup, out customAddress); } if (assetGroup == null) { assetGroup = aaSettings.DefaultGroup; } string guid = info.Guid; if (string.IsNullOrEmpty(guid)) { continue; } AddressableAssetEntry e = aaSettings.FindAssetEntry(guid); if (e != null) //move entry to where it should go... { aaSettings.MoveEntry(e, assetGroup, false, false); } else //create entry { e = aaSettings.CreateAndAddEntryToGroup_Custom(guid, assetGroup, false, false); } if (string.IsNullOrEmpty(customAddress) == false) { e.SetAddress(customAddress, false); } entriesCreated.Add(e); entriesMoved.Add(e); } bool openedInVC = false; if (entriesMoved.Count > 0) { AddressableAssetUtility.OpenAssetIfUsingVCIntegration(parentGroup); openedInVC = true; aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entriesMoved, true, false); } if (entriesCreated.Count > 0) { if (!openedInVC) { AddressableAssetUtility.OpenAssetIfUsingVCIntegration(parentGroup); } aaSettings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryAdded, entriesCreated, true, false); } } }
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 void GenerateIcon() { Dictionary <Renderer, int> dicRenderers = new Dictionary <Renderer, int>(); if (renderers.Count == 0) { foreach (Renderer renderer in (renderers.Count == 0 ? new List <Renderer>(this.transform.root.GetComponentsInChildren <Renderer>()) : renderers)) { dicRenderers.Add(renderer, renderer.gameObject.layer); renderer.gameObject.layer = tempLayer; } } Camera cam = new GameObject().AddComponent <Camera>(); cam.transform.SetParent(this.transform); cam.orthographic = true; cam.targetTexture = RenderTexture.GetTemporary(iconResolution, iconResolution, 16); cam.clearFlags = CameraClearFlags.Color; cam.stereoTargetEye = StereoTargetEyeMask.None; cam.orthographicSize = size / 2; cam.cullingMask = 1 << tempLayer; cam.enabled = false; cam.transform.position = this.transform.position + (this.transform.forward * -1); cam.transform.rotation = this.transform.rotation; Light camLight = cam.gameObject.AddComponent <Light>(); camLight.transform.SetParent(cam.transform); camLight.type = LightType.Directional; camLight.enabled = true; string iconPath = null; if (PrefabStageUtility.GetCurrentPrefabStage() != null) { // Prefab editor iconPath = PrefabStageUtility.GetCurrentPrefabStage().prefabAssetPath; cam.scene = PrefabStageUtility.GetCurrentPrefabStage().scene; } else if (PrefabUtility.GetNearestPrefabInstanceRoot(this)) { // Prefab in scene iconPath = PrefabUtility.GetPrefabAssetPathOfNearestInstanceRoot(this); } else { // Not a prefab Debug.LogError("Unable to create an icon file if the object is not a prefab!"); } cam.Render(); RenderTexture orgActiveRenderTexture = RenderTexture.active; RenderTexture.active = cam.targetTexture; generatedIcon = new Texture2D(cam.targetTexture.width, cam.targetTexture.height, TextureFormat.ARGB32, false); generatedIcon.ReadPixels(new Rect(0, 0, cam.targetTexture.width, cam.targetTexture.height), 0, 0); generatedIcon.Apply(false); RenderTexture.active = orgActiveRenderTexture; // Clean up after ourselves cam.targetTexture = null; RenderTexture.ReleaseTemporary(cam.targetTexture); foreach (KeyValuePair <Renderer, int> renderer in dicRenderers) { renderer.Key.gameObject.layer = renderer.Value; } DestroyImmediate(cam.gameObject); if (iconPath != null) { byte[] bytes = generatedIcon.EncodeToPNG(); string path = iconPath.Replace(".prefab", ".png"); System.IO.File.WriteAllBytes(path, bytes); AssetDatabase.Refresh(); generatedIcon = AssetDatabase.LoadAssetAtPath <Texture2D>(path); TextureImporter textureImporter = (TextureImporter)TextureImporter.GetAtPath(path); textureImporter.alphaIsTransparency = true; EditorUtility.SetDirty(textureImporter); textureImporter.SaveAndReimport(); Debug.Log("Icon generated : " + path); AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings; if (settings != null) { string guid = AssetDatabase.AssetPathToGUID(path); AddressableAssetEntry entry = settings.FindAssetEntry(guid); if (entry == null) { Debug.Log("Added icon to addressable"); entry = settings.CreateOrMoveEntry(guid, settings.DefaultGroup); settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryAdded, entry, true, false); } string prefabGuid = AssetDatabase.AssetPathToGUID(iconPath); AddressableAssetEntry prefabEntry = settings.FindAssetEntry(prefabGuid); if (prefabEntry != null) { entry.SetAddress(prefabEntry.address + ".Icon", false); } } else { Debug.LogError("Could not find AddressableAssetSettings, cannot set the icon to addressable"); return; } } }
public void WhenAddressHasSquareBracketsAndGuidIsEmptyString_SettingTheAddressOnExistingEntry_ThrowsNothing() { AddressableAssetEntry entry = new AddressableAssetEntry("", "Entry", null, false); Assert.DoesNotThrow(() => entry.SetAddress("[Entry]")); }
public override void FixIssues(AddressableAssetSettings settings) { // Load template used for creating new groups var groupTemplates = settings.GroupTemplateObjects; AddressableAssetGroupTemplate foundTemplate = null; foreach (var template in groupTemplates) { if (template.name == templateToUse) { foundTemplate = template as AddressableAssetGroupTemplate; break; } } if (foundTemplate == null) { Debug.Log("Group template \"" + templateToUse + "\" not found. Aborting!"); return; } // Create groups foreach (var groupName in groupsToCreate) { // I don't know enough about schemas, so schemasToCopy is set to null here. AddressableAssetGroup newGroup = settings.CreateGroup(groupName, false, false, true, null, foundTemplate.GetTypes()); foundTemplate.ApplyToAddressableAssetGroup(newGroup); } // Remove groups foreach (var groupName in groupsToRemove) { foreach (var group in settings.groups) { if (group.name == groupName) { settings.RemoveGroup(group); break; } } } // Collect current group names Dictionary <string, AddressableAssetGroup> groups = new Dictionary <string, AddressableAssetGroup>(); foreach (var group in settings.groups) { groups.Add(group.name, group); } // Create and remove assets foreach (var action in assetActions) { if (!groups.ContainsKey(action.inGroup)) { continue; } if (action.create) { AddressableAssetEntry entry = settings.CreateOrMoveEntry(action.assetGuid, groups[action.inGroup]); entry.SetAddress(action.addressablePath); } else { AddressableAssetEntry entry = settings.FindAssetEntry(action.assetGuid); if (entry != null) { settings.RemoveAssetEntry(action.assetGuid); } else { Debug.Log("Asset guid didn't produce an entry: " + action.assetGuid); } } } ClearAnalysis(); ClearOurData(); }
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); } } }
private void CreateAddressableSettings(bool localMode) { AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.GetSettings(true); settings.ActivePlayModeDataBuilderIndex = localMode ? 0 : 2; settings.BuildRemoteCatalog = true; settings.DisableCatalogUpdateOnStartup = true; // don't include built-in data, causes shader issues settings.groups.ForEach(g => { PlayerDataGroupSchema schema = g.GetSchema <PlayerDataGroupSchema>(); if (schema != null) { schema.IncludeBuildSettingsScenes = false; schema.IncludeResourcesFolders = false; } }); // setup profiles AddressableAssetProfileSettings profile = settings.profileSettings; // activate and (re)group assets foreach (string dir in GetLevelPaths()) { string levelName = Path.GetFileName(dir); bool isBase = levelName == "Base"; // create one profile per level string profileId = profile.GetProfileId(levelName); if (string.IsNullOrEmpty(profileId)) { profileId = profile.AddProfile(levelName, settings.activeProfileId); } string guid = AssetDatabase.AssetPathToGUID($"Assets/Levels/{levelName}"); // create group if non-existent AddressableAssetGroup group = settings.groups.Where(g => g.name == levelName).FirstOrDefault(); if (group == null) { group = CreateAssetGroup <BundledAssetGroupSchema>(settings, levelName); } // set correct path AddressableAssetEntry entry = settings.CreateOrMoveEntry(guid, group); entry.SetAddress($"Levels/{levelName}"); // set variables string localRoot = Application.dataPath + $"/../Library/com.unity.addressables/aa/Windows/Levels/{levelName}/[BuildTarget]"; profile.SetValue(profileId, AddressableAssetSettings.kLocalBuildPath, localRoot); profile.SetValue(profileId, AddressableAssetSettings.kLocalLoadPath, localRoot); profile.SetValue(profileId, AddressableAssetSettings.kRemoteBuildPath, $"ServerData/Levels/{levelName}/[BuildTarget]"); profile.SetValue(profileId, AddressableAssetSettings.kRemoteLoadPath, $"{AWSUtil.S3Root}Levels/{levelName}/[BuildTarget]"); // ensure correct group settings BundledAssetGroupSchema groupSchema = group.GetSchema <BundledAssetGroupSchema>(); groupSchema.UseAssetBundleCache = true; groupSchema.UseAssetBundleCrc = false; groupSchema.IncludeInBuild = isBase ? true : false; groupSchema.BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash; // hash to disimbiguate identically named files yields same error messages, e.g. standard shaders groupSchema.BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackTogether; groupSchema.Compression = BundledAssetGroupSchema.BundleCompressionMode.LZ4; groupSchema.BuildPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalBuildPath : AddressableAssetSettings.kRemoteBuildPath); groupSchema.LoadPath.SetVariableByName(settings, localMode ? AddressableAssetSettings.kLocalLoadPath : AddressableAssetSettings.kRemoteLoadPath); } }
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(); }
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(); }