public void ContentUpdateScenes_PackedSeperately_MarksNoAdditionalScenes()
        {
            AddressableAssetGroup group = Settings.CreateGroup("SceneGroup", false, false, false, null, typeof(BundledAssetGroupSchema));

            group.GetSchema <BundledAssetGroupSchema>().BundleMode = BundledAssetGroupSchema.BundlePackingMode.PackSeparately;

            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);

            List <AddressableAssetEntry> modifedEnteries = new List <AddressableAssetEntry>()
            {
                scene1
            };

            ContentUpdateScript.AddAllDependentScenesFromModifiedEnteries(modifedEnteries);

            Assert.AreEqual(1, modifedEnteries.Count);
            Assert.AreEqual(scene1, modifedEnteries[0]);

            Settings.RemoveGroup(group);
        }
        public void EditorInitialization_DoesNotDeleteFoldersThatAreStillOnDisk()
        {
            //Setup
            string folderPath = "Assets/Temp/FakeAddressablesFolder/";

            Directory.CreateDirectory(folderPath);
            AssetDatabase.ImportAsset(folderPath);
            AddressableAssetEntry entry = new AddressableAssetEntry(AssetDatabase.AssetPathToGUID(folderPath),
                                                                    folderPath, m_testGroup, false);

            m_testGroup.AddAssetEntry(entry);
            entry.m_cachedAssetPath = folderPath;

            Assert.IsTrue(m_testGroup.entries.Contains(entry), "Folder entry is no longer in Addressable group before purge.");

            //Test
            AddressableEditorInitialization.PurgeInvalidAssetEntries(Settings);

            //Assert
            Assert.IsTrue(m_testGroup.entries.Contains(entry), "Folder entry is no longer in Addressable group after purge.");

            //Cleanup
            m_testGroup.RemoveAssetEntry(entry);
            AssetDatabase.DeleteAsset(folderPath);
        }
        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);
        }
        public void RemoveEntries_InvokesModificationNotification()
        {
            AddressableAssetGroup group1 = m_Settings.CreateGroup("group1", false, false, true, null, new Type[] { });

            List <AddressableAssetEntry> entries = new List <AddressableAssetEntry>();

            for (int i = 0; i < 10; i++)
            {
                group1.AddAssetEntry(new AddressableAssetEntry("000" + i.ToString(), "unknown" + i.ToString(), group1, false));
            }


            List <AddressableAssetEntry> callbackEntries = new List <AddressableAssetEntry>();
            Action <AddressableAssetSettings, AddressableAssetSettings.ModificationEvent, object> callback = (x, y, z) => callbackEntries.AddRange((AddressableAssetEntry[])z);

            AddressableAssetSettings.OnModificationGlobal += callback;

            group1.RemoveAssetEntries(entries.ToArray());

            for (int i = 0; i < entries.Count; i++)
            {
                Assert.AreEqual(entries[i], callbackEntries[i]);
            }

            //Cleanup
            AddressableAssetSettings.OnModificationGlobal -= callback;
            m_Settings.RemoveGroup(group1);
        }
        public void DedupeEntries_WhenGroupsHaveOverlappingAssetEntries_RemovesEntries()
        {
            const string          guid    = "0000";
            const string          address = "not/a/real/address";
            AddressableAssetGroup group1  = m_Settings.CreateGroup("group1", false, false, true, null, new Type[] { });
            AddressableAssetGroup group2  = m_Settings.CreateGroup("group2", false, false, true, null, new Type[] { });

            //We're making 2 identical enteries.  This is to simulate each group having it's own copy of an AA Entry that references the same object.
            //If we use the same object the call to AddAssetEntry won't give us the state we're looking for.
            AddressableAssetEntry entry  = new AddressableAssetEntry(guid, address, group1, false);
            AddressableAssetEntry entry2 = new AddressableAssetEntry(guid, address, group2, false);

            group1.AddAssetEntry(entry);
            group2.AddAssetEntry(entry2);

            //Ensuring our setup is correct
            Assert.IsNotNull(group1.GetAssetEntry(guid));
            Assert.IsNotNull(group2.GetAssetEntry(guid));

            group1.DedupeEnteries(); //We setup our entry with group1 so it should retain its reference
            group2.DedupeEnteries(); //The entry was added to group2 afterwards and should lose its reference

            Assert.IsNotNull(group1.GetAssetEntry(guid));
            Assert.IsNull(group2.GetAssetEntry(guid));

            //Cleanup
            m_Settings.RemoveGroup(group1);
            m_Settings.RemoveGroup(group2);
        }
 void CreateGroupWithAssets(string groupName, int assetEntryCount, out AddressableAssetGroup group, out List <AddressableAssetEntry> entries)
 {
     group   = m_Settings.CreateGroup(groupName, false, false, false, null, typeof(BundledAssetGroupSchema));
     entries = new List <AddressableAssetEntry>();
     for (int i = 0; i < assetEntryCount; i++)
     {
         AddressableAssetEntry e = new AddressableAssetEntry($"111{i}", $"addr{i}", group, false);
         e.m_cachedAssetPath = $"DummyPath{i}";
         group.AddAssetEntry(e);
         entries.Add(e);
     }
 }
        public void SetAssetEntriesBundleFileIdToCatalogEntryBundleFileId_SetsBundleFileIdToBundleNameOnly_WhenGroupSchemaNamingIsSetToFilename()
        {
            //Setup
            GUID   entry1Guid         = GUID.Generate();
            string bundleFile         = "bundle";
            string internalBundleName = "bundlepath";
            string finalBundleName    = "finalBundlePath";
            string bundleCatalogEntryInternalIdHashed   = "catalogentrybundlefileid_1234567890.bundle";
            string bundleCatalogEntryInternalIdUnHashed = "catalogentrybundlefileid.bundle";

            AddressableAssetEntry entry1 = new AddressableAssetEntry(entry1Guid.ToString(), "123", null, false);
            AddressableAssetGroup group  = Settings.CreateGroup("testGroup", false, false, false,
                                                                new List <AddressableAssetGroupSchema>(), typeof(BundledAssetGroupSchema));

            group.GetSchema <BundledAssetGroupSchema>().BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash;
            group.AddAssetEntry(entry1, false);

            ICollection <AddressableAssetEntry> entries = new List <AddressableAssetEntry>()
            {
                entry1
            };

            Dictionary <string, string> bundleToIdMap = new Dictionary <string, string>()
            {
                { internalBundleName, finalBundleName }
            };

            IBundleWriteData writeData = new BundleWriteData();

            writeData.AssetToFiles.Add(entry1Guid, new List <string>()
            {
                bundleFile
            });
            writeData.FileToBundle.Add(bundleFile, internalBundleName);

            Dictionary <string, ContentCatalogDataEntry> catalogMap = new Dictionary <string, ContentCatalogDataEntry>()
            {
                {
                    finalBundleName,
                    new ContentCatalogDataEntry(typeof(IAssetBundleResource), bundleCatalogEntryInternalIdHashed,
                                                typeof(AssetBundleProvider).FullName, new[] { "catalogentry" })
                }
            };

            //Test
            BuildScriptPackedMode.SetAssetEntriesBundleFileIdToCatalogEntryBundleFileId(entries, bundleToIdMap, writeData, catalogMap);

            //Assert
            Assert.AreEqual(bundleCatalogEntryInternalIdUnHashed, entry1.BundleFileId);

            //Cleanup
            Settings.RemoveGroup(group);
        }
        public void WhenClassReferencedByAddressableAssetEntryIsReloaded_CachedMainAssetTypeIsReset()
        {
            // Setup
            var path = k_TestConfigFolder + "/resetCachedMainAssetTypeTestGroup.asset";
            AddressableAssetGroup group = ScriptableObject.CreateInstance <AddressableAssetGroup>();
            AddressableAssetEntry entry = new AddressableAssetEntry(guid, "address", null, false);

            group.AddAssetEntry(entry);

            Assert.IsNull(entry.m_cachedMainAssetType);
            Assert.AreEqual(typeof(UnityEngine.AddressableAssets.Tests.TestObject), entry.MainAssetType);

            // Test
            AssetDatabase.CreateAsset(group, path);
            Resources.UnloadAsset(group);

            var reloadedGroup = AssetDatabase.LoadAssetAtPath <AddressableAssetGroup>(path);
            var reloadedEntry = reloadedGroup.GetAssetEntry(guid);

            Assert.IsNull(reloadedEntry.m_cachedMainAssetType);

            // Cleanup
            AssetDatabase.DeleteAsset(path);
        }