熟悉Addressable的同学应该清楚,Addressable设置大小包,是修改AddressableAssetGroup的BuildPath、LoadPath。即Remote为小包、Local为打包
那么如何代码里修改呢?如果能代码修改就可以支持一键打包了
下面附上代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
/// <summary> /// 设置资源打进包体里(大包) /// </summary> public static void SetLargePacket() { foreach (var addressableAssetGroup in addressableAssetSettings.groups) { if (addressableAssetGroup.IsDefaultGroup() || addressableAssetGroup.ReadOnly) continue; for (int i = 0; i < addressableAssetGroup.Schemas.Count; i++) { var schema = addressableAssetGroup.Schemas[i]; if (schema is UnityEditor.AddressableAssets.Settings.GroupSchemas.ContentUpdateGroupSchema) { (schema as UnityEditor.AddressableAssets.Settings.GroupSchemas.ContentUpdateGroupSchema) .StaticContent = true; } else if (schema is UnityEditor.AddressableAssets.Settings.GroupSchemas .BundledAssetGroupSchema) { var bundledAssetGroupSchema = (schema as UnityEditor.AddressableAssets.Settings.GroupSchemas.BundledAssetGroupSchema); bundledAssetGroupSchema.BuildPath.SetVariableByName(addressableAssetGroup.Settings, AddressableAssetSettings.kLocalBuildPath); bundledAssetGroupSchema.LoadPath.SetVariableByName(addressableAssetGroup.Settings, AddressableAssetSettings.kLocalLoadPath); } } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debuger.Log("设置成大包资源完成"); } /// <summary> /// 设置资源不打进包体里(小包) /// </summary> public static void SetSmallPacket() { foreach (var addressableAssetGroup in addressableAssetSettings.groups) { if (addressableAssetGroup.IsDefaultGroup() || addressableAssetGroup.ReadOnly) continue; for (int i = 0; i < addressableAssetGroup.Schemas.Count; i++) { var schema = addressableAssetGroup.Schemas[i]; if (schema is UnityEditor.AddressableAssets.Settings.GroupSchemas.ContentUpdateGroupSchema) { (schema as UnityEditor.AddressableAssets.Settings.GroupSchemas.ContentUpdateGroupSchema) .StaticContent = true; } else if (schema is UnityEditor.AddressableAssets.Settings.GroupSchemas .BundledAssetGroupSchema) { var bundledAssetGroupSchema = (schema as UnityEditor.AddressableAssets.Settings.GroupSchemas.BundledAssetGroupSchema); bundledAssetGroupSchema.BuildPath.SetVariableByName(addressableAssetGroup.Settings, AddressableAssetSettings.kRemoteBuildPath); bundledAssetGroupSchema.LoadPath.SetVariableByName(addressableAssetGroup.Settings, AddressableAssetSettings.kRemoteLoadPath); } } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debuger.Log("设置成小包资源完成"); } private static AddressableAssetSettings m_AddressableAssetSettings; private static AddressableAssetSettings addressableAssetSettings { get { if (m_AddressableAssetSettings == null) { m_AddressableAssetSettings = AddressableAssetSettingsDefaultObject.Settings; if (m_AddressableAssetSettings == null) m_AddressableAssetSettings = AssetDatabase.LoadAssetAtPath<AddressableAssetSettings>("Assets/AddressableAssetsData/AddressableAssetSettings.asset"); } return m_AddressableAssetSettings; } } |
- 本文固定链接: http://www.u3d8.com/?p=2272
- 转载请注明: 网虫虫 在 u3d8.com 发表过
[…] Addressable之代码设置大小包 […]