private static void SetGroupsSetting(AddressableAssetGroup group, bool UseAssetBundleCache, bool UseAssetBundleCrc, BundledAssetGroupSchema.BundleNamingStyle BundleNaming, string BuildPath, string LoadPath, bool StaticContent) { BundledAssetGroupSchema bundledAssetGroupSchema = group.GetSchema <BundledAssetGroupSchema>(); if (bundledAssetGroupSchema == null) { bundledAssetGroupSchema = group.AddSchema <BundledAssetGroupSchema>(); } //bundledAssetGroupSchema.IncludeInBuild = true; bundledAssetGroupSchema.UseAssetBundleCache = UseAssetBundleCache; bundledAssetGroupSchema.UseAssetBundleCrc = UseAssetBundleCrc; bundledAssetGroupSchema.BundleNaming = BundleNaming; bundledAssetGroupSchema.BuildPath.SetVariableByName(group.Settings, BuildPath); bundledAssetGroupSchema.LoadPath.SetVariableByName(group.Settings, LoadPath); bundledAssetGroupSchema.SetAssetBundleProviderType(typeof(AssetBundleEncryptProvider)); EditorUtility.SetDirty(bundledAssetGroupSchema); ContentUpdateGroupSchema contentUpdateGroupSchema = group.GetSchema <ContentUpdateGroupSchema>(); if (contentUpdateGroupSchema == null) { contentUpdateGroupSchema = group.AddSchema <ContentUpdateGroupSchema>(); } contentUpdateGroupSchema.StaticContent = StaticContent; EditorUtility.SetDirty(contentUpdateGroupSchema); }
public static void AddSchemas(AddressableAssetGroup group) { for (int i = 0; i < group.Schemas.Count; i++) { var sc = group.Schemas[i]; group.RemoveSchema(sc.GetType()); } group.AddSchema <ContentUpdateGroupSchema>(); group.AddSchema <BundledAssetGroupSchema>(); }
void OnAddSchema(object context) { m_GroupTarget.AddSchema(context as Type); var newFoldoutState = new bool[m_GroupTarget.Schemas.Count]; for (int i = 0; i < m_FoldoutState.Length; i++) { newFoldoutState[i] = m_FoldoutState[i]; } m_FoldoutState = newFoldoutState; m_FoldoutState[m_FoldoutState.Length - 1] = true; }
public void DefaultGroupChangesToValidDefaultGroup() { LogAssert.ignoreFailingMessages = true; AddressableAssetGroup oldDefault = m_Settings.DefaultGroup; oldDefault.m_ReadOnly = true; AddressableAssetGroup newDefault = m_Settings.DefaultGroup; Assert.AreNotEqual(oldDefault, newDefault); Assert.IsFalse(m_Settings.DefaultGroup.ReadOnly); //Cleanup oldDefault.AddSchema <BundledAssetGroupSchema>(); m_Settings.DefaultGroup = oldDefault; }
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 DrawMultipleGroups() // { // InitializeMultiSelectGroupSchemas(); // // if (m_FoldoutState == null || m_FoldoutState.Length != m_GroupTarget.Schemas.Count) // m_FoldoutState = new bool[m_GroupTarget.Schemas.Count]; // // EditorGUILayout.BeginVertical(); // int lastSchemaDrawn = -1; // for (int i = 0; i < m_GroupTarget.Schemas.Count; i++) // { // if (!m_SchemaState[i]) continue; // // var schema = m_GroupTarget.Schemas[i]; // int currentIndex = i; // // // Draw divider in between schemas // if (lastSchemaDrawn > -1) // DrawDivider(); // lastSchemaDrawn = i; // // EditorGUILayout.BeginHorizontal(); // m_FoldoutState[i] = EditorGUILayout.Foldout(m_FoldoutState[i], schema.DisplayName()); // if (!m_GroupTarget.ReadOnly) // { // GUILayout.FlexibleSpace(); // GUIStyle gearIconStyle = UnityEngine.GUI.skin.FindStyle("IconButton") ?? EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle("IconButton"); // // if (EditorGUILayout.DropdownButton(EditorGUIUtility.IconContent("_Popup"), FocusType.Keyboard, gearIconStyle)) // { // var menu = new GenericMenu(); // menu.AddItem(AddressableAssetGroup.RemoveSchemaContent, false, () => // { // if (EditorUtility.DisplayDialog("Remove selected schema?", "Are you sure you want to remove " + schema.DisplayName() + " schema?\n\nYou cannot undo this action.", "Yes", "No")) // { // Type schemaType = schema.GetType(); // m_GroupTarget.RemoveSchema(schemaType); // for (int j = 0; j < m_GroupTargets.Length-1; j++) // { // m_GroupTargets[j].RemoveSchema(schemaType); // } // // InitializeMultiSelectGroupSchemas(); // // var newFoldoutstate = new bool[m_GroupTarget.Schemas.Count]; // for (int j = 0; j < newFoldoutstate.Length; j++) // { // if (j < i) // newFoldoutstate[j] = m_FoldoutState[j]; // else // newFoldoutstate[j] = m_FoldoutState[i + 1]; // } // // m_FoldoutState = newFoldoutstate; // return; // } // }); // menu.AddItem(AddressableAssetGroup.MoveSchemaUpContent, false, () => // { // foreach (var group in m_GroupTargets) // { // int index = group.FindSchema(schema.GetType()); // if (index > 0) // { // var temp = group.Schemas[index]; // group.Schemas[index] = group.Schemas[index - 1]; // group.Schemas[index - 1] = temp; // } // } // InitializeMultiSelectGroupSchemas(); // return; // }); // menu.AddItem(AddressableAssetGroup.MoveSchemaDownContent, false, () => // { // foreach (var group in m_GroupTargets) // { // int index = group.FindSchema(schema.GetType()); // if (index >= 0 && index < group.Schemas.Count - 1) // { // var temp = group.Schemas[index]; // group.Schemas[index] = group.Schemas[index + 1]; // group.Schemas[index + 1] = temp; // } // } // InitializeMultiSelectGroupSchemas(); // return; // }); // menu.AddSeparator(""); // menu.AddItem(AddressableAssetGroup.ExpandSchemaContent, false, () => // { // m_FoldoutState[currentIndex] = true; // foreach (var group in m_GroupTargets) // { // int index = group.FindSchema(schema.GetType()); // if (index != -1) // { // group.Schemas[index].ShowAllProperties(); // } // } // }); // menu.ShowAsContext(); // } // } // EditorGUILayout.EndHorizontal(); // if (m_FoldoutState[i]) // { // try // { // EditorGUI.indentLevel++; // schema.OnGUIMultiple(m_GroupSchemas[i]); // EditorGUI.indentLevel--; // } // catch (Exception se) // { // Debug.LogException(se); // } // } // } // // if (m_HiddenSchemas) // { // if (lastSchemaDrawn > -1) // DrawDivider(); // EditorGUILayout.HelpBox(new GUIContent("Only schemas that are on all selected groups can be multi-edited.")); // } // // // Draw divider before "Add component" button if schemas were drawn // if (m_HiddenSchemas || lastSchemaDrawn > -1) // DrawDivider(); // // GUILayout.Space(4); // EditorGUILayout.BeginHorizontal(); // // GUILayout.FlexibleSpace(); // GUIStyle addSchemaButton = new GUIStyle(UnityEngine.GUI.skin.button); // addSchemaButton.fontSize = 12; // addSchemaButton.fixedWidth = 225; // addSchemaButton.fixedHeight = 22; // // if (!m_GroupTarget.ReadOnly) // { // if (EditorGUILayout.DropdownButton(new GUIContent("Add Schema", "Add new schema to this group."), FocusType.Keyboard, addSchemaButton)) // { // var menu = new GenericMenu(); // for (int i = 0; i < m_SchemaTypes.Count; i++) // { // var type = m_SchemaTypes[i]; // var schema = (AddressableAssetGroupSchema)CreateInstance(type); // // bool allGroupsDoNotHave = true; // foreach(var group in m_GroupTargets) // { // if (group.HasSchema(type)) // allGroupsDoNotHave = false; // } // // // Only show schemas that none of the selected groups have // if (allGroupsDoNotHave) // { // menu.AddItem(new GUIContent(schema.DisplayName(), ""), false, () => // { // OnAddSchema(type, true); // return; // }); // } // else // { // menu.AddDisabledItem(new GUIContent(schema.DisplayName(), ""), true); // } // } // // menu.ShowAsContext(); // } // } // // GUILayout.FlexibleSpace(); // // EditorGUILayout.EndHorizontal(); // EditorGUILayout.EndVertical(); // } void OnAddSchema(Type schemaType, bool multiSelect = false) { m_GroupTarget.AddSchema(schemaType); // if (multiSelect) // { // for (int i = 0; i < m_GroupTargets.Length - 1; i++) // { // m_GroupTargets[i].AddSchema(schemaType); // } // InitializeMultiSelectGroupSchemas(); // } var newFoldoutState = new bool[m_GroupTarget.Schemas.Count]; for (int i = 0; i < m_FoldoutState.Length; i++) { newFoldoutState[i] = m_FoldoutState[i]; } m_FoldoutState = newFoldoutState; m_FoldoutState[m_FoldoutState.Length - 1] = true; }
void ImportSchemasInternal(AddressableAssetSettings settings, string groupName, string schemaFolder) { if (string.IsNullOrEmpty(schemaFolder) || !Directory.Exists(schemaFolder)) { Debug.LogError($"Schema folder path is not a valid folder '{schemaFolder}'. Schemas will not be imported."); return; } AddressableAssetGroup group = settings.FindGroup(groupName); if (group == null) { Debug.LogError($"Settings does not contain group '{groupName}'. Schemas will not be imported."); return; } string[] schemaPaths = Directory.GetFiles(schemaFolder); foreach (string unparsedPath in schemaPaths) { if (Path.GetExtension(unparsedPath).ToLower() != ".asset") { continue; } string path = unparsedPath.Replace("\\", "/"); AddressableAssetGroupSchema schema = AssetDatabase.LoadAssetAtPath <AddressableAssetGroupSchema>(path); if (schema == null) { Debug.LogError($"Cannot load schema asset at '{path}'. Schema will not be imported."); continue; } if (schema is BundledAssetGroupSchema bundledSchema) { List <string> variableNames = schema.Group.Settings.profileSettings.GetVariableNames(); SetBundledAssetGroupSchemaPaths(settings, bundledSchema.BuildPath, AddressableAssetSettings.kLocalBuildPath, "LocalBuildPath", variableNames); SetBundledAssetGroupSchemaPaths(settings, bundledSchema.LoadPath, AddressableAssetSettings.kLocalLoadPath, "LocalLoadPath", variableNames); } group.AddSchema(schema); } }
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(); }