Exemple #1
0
        internal void OfferToConvert()
        {
            var bundleList = AssetDatabase.GetAllAssetBundleNames();

            if (EditorUtility.DisplayDialog("Legacy Bundles Detected", "We have detected the use of legacy bundles in this project.  Would you like to auto-convert those into Addressables? \nThis will take each asset bundle you have defined (we have detected " + bundleList.Length + " bundles), create an Addressables group with a matching name, then move all assets from those bundles into corresponding groups.  This will remove the asset bundle assignment from all assets, and remove all asset bundle definitions from this project.  This cannot be undone.", "Convert", "Ignore"))
            {
                AddressableAssetUtility.ConvertAssetBundlesToAddressables();
            }
            else
            {
                m_IgnoreLegacyBundles = true;
            }
        }
Exemple #2
0
        public void AddressableAssetUtility_ConvertAssetBundlesToAddressables_CanConvertBundles(int numBundles)
        {
            // Setup
            var prevGroupCount = Settings.groups.Count;
            var testAssetGUIDs = new List <string>();

            for (int i = 0; i < numBundles; i++)
            {
                var testObject = new GameObject("TestObjectForBundles" + i);
#if UNITY_2018_3_OR_NEWER
                PrefabUtility.SaveAsPrefabAsset(testObject, ConfigFolder + "/testasset" + i + ".prefab");
#else
                PrefabUtility.CreatePrefab(k_TestConfigFolder + "/testasset" + i + ".prefab", testObject);
#endif
                testAssetGUIDs.Add(AssetDatabase.AssetPathToGUID(ConfigFolder + "/testasset" + i + ".prefab"));
                var importer = AssetImporter.GetAtPath(AssetDatabase.GUIDToAssetPath(testAssetGUIDs[i]));
                importer.assetBundleName = "testAssetBundleName" + i;
                AssetDatabase.SaveAssets();
            }
            AddressableAssetSettingsDefaultObject.Settings = Settings;

            // Test
            AddressableAssetUtility.ConvertAssetBundlesToAddressables();
            Assert.AreEqual(prevGroupCount + numBundles, Settings.groups.Count);
            Assert.AreEqual(0, AssetDatabase.GetAllAssetBundleNames().Length);
            for (int i = 0; i < numBundles; i++)
            {
                Assert.NotNull(Settings.FindAssetEntry(testAssetGUIDs[i]));
            }

            // Cleanup
            for (int i = 0; i < numBundles; i++)
            {
                var lastGroupIndex = AddressableAssetSettingsDefaultObject.Settings.groups.Count - 1;
                AddressableAssetSettingsDefaultObject.Settings.RemoveGroup(AddressableAssetSettingsDefaultObject.Settings.groups[lastGroupIndex]);
            }
        }