public void RunResourcesTestWithAsset(bool IncludeResourcesFolders) { int builtInResourceCount = ResourcesTestUtility.GetResourcesEntryCount(m_Settings, true); var path = GetPath("Resources/test.asset"); var dir = Path.GetDirectoryName(path); Directory.CreateDirectory(dir); AssetDatabase.CreateAsset(UnityEngine.AddressableAssets.Tests.TestObject.Create("test"), path); AssetDatabase.SaveAssets(); m_Settings.FindGroup(g => g.HasSchema <PlayerDataGroupSchema>()).GetSchema <PlayerDataGroupSchema>().IncludeResourcesFolders = IncludeResourcesFolders; var locator = new AddressableAssetSettingsLocator(m_Settings); var res = locator.Locate("test", null, out var locations); Assert.AreEqual(res, IncludeResourcesFolders); if (IncludeResourcesFolders) { Assert.AreEqual(1 + builtInResourceCount, locations.Count + builtInResourceCount); } else { Assert.IsNull(locations); } AssetDatabase.DeleteAsset(path); Directory.Delete(dir); }
public void ProcessPlayerDataSchema_WhenNoResourcesAreIncluded_ShouldNotGenerateAnyResourceLocationsOrProviders() { using (new HideResourceFoldersScope()) { var resourceFolder = k_SchemaTestFolderPath + "/Resources"; int builtInPackagesResourceCount = ResourcesTestUtility.GetResourcesEntryCount(m_Settings, true); Directory.CreateDirectory(resourceFolder); var group = m_Settings.FindGroup(AddressableAssetSettings.PlayerDataGroupName); var schema = group.GetSchema(typeof(PlayerDataGroupSchema)) as PlayerDataGroupSchema; schema.IncludeResourcesFolders = true; var errorStr = m_BuildScript.ProcessPlayerDataSchema(schema, group, m_BuildContext); Assert.True(string.IsNullOrEmpty(errorStr)); var actualLocations = m_BuildContext.locations.Where( l => l.ResourceType == typeof(GameObject) && l.Provider == typeof(LegacyResourcesProvider).FullName) .ToList(); Assert.AreEqual(0, actualLocations.Count); var actualProviders = m_BuildScript.ResourceProviderData .Where(rpd => rpd.ObjectType.ClassName == typeof(LegacyResourcesProvider).FullName).ToList(); Assert.AreEqual(builtInPackagesResourceCount > 0 ? 1 : 0, actualProviders.Count); } }
public void GatherAllAssets_WhenResourcesExist_RecurseAllIsTrue_ReturnsEntriesRecursivelyForValidFilesOnly() { using (new HideResourceFoldersScope()) { var resourcePath = GetAssetPath("Resources"); var subFolderPath = resourcePath + "/Subfolder"; Directory.CreateDirectory(subFolderPath); var group = Settings.FindGroup(AddressableAssetSettings.PlayerDataGroupName); var resourceEntry = Settings.CreateOrMoveEntry(AddressableAssetEntry.ResourcesName, group, false); int builtInResourcesCount = ResourcesTestUtility.GetResourcesEntryCount(Settings, true); var r1GUID = CreateAsset(resourcePath + "/testResource1.prefab", "testResource1"); var r2GUID = CreateAsset(subFolderPath + "/testResource2.prefab", "testResource2"); var entries = new List <AddressableAssetEntry>(); resourceEntry.GatherAllAssets(entries, false, true, true); // Assert var subFolderGUID = AssetDatabase.AssetPathToGUID(subFolderPath); Assert.AreEqual(2 + builtInResourcesCount, entries.Count); Assert.IsTrue(entries.Any(e => e.guid == r1GUID)); Assert.IsTrue(entries.Any(e => e.guid == r2GUID)); Assert.IsFalse(entries.Any(e => e.guid == subFolderGUID)); // Cleanup Directory.Delete(resourcePath, true); } }
public void ResourcesEntry_AddsCorrectTreeViewItem_ForSubobjects() { using (new HideResourceFoldersScope()) { //Setup string assetPath = "SubFolder/Cube.prefab"; int builtInPackagesResourcesCount = ResourcesTestUtility.GetResourcesEntryCount(Settings, true); CreatePrefabInResourcesSubFolder(assetPath); AddressableAssetEntryTreeView treeView = new AddressableAssetEntryTreeView( new TreeViewState(), new MultiColumnHeaderState(new MultiColumnHeaderState.Column[1]), new AddressableAssetsSettingsGroupEditor(new AddressableAssetsWindow())); //Test AddressableAssetEntry entry = Settings.FindAssetEntry("Resources"); AssetEntryTreeViewItem treeViewItem = new AssetEntryTreeViewItem(entry, 0); treeView.RecurseEntryChildren(entry, treeViewItem, 0); //Assert Assert.AreEqual(1 + builtInPackagesResourcesCount, treeViewItem.children.Count); Assert.AreEqual(assetPath.Replace(".prefab", ""), treeViewItem.children[0].displayName); //Cleanup AssetDatabase.DeleteAsset("Assets/Resources/"); } }
public void BuildTree_Resources_CreatesEntriesForAllFilesInResourcesFolders() { Directory.CreateDirectory(k_TreeViewTestFolderPath + "/Resources"); Directory.CreateDirectory(k_TreeViewTestFolderPath + "/SubFolder/Resources"); var resourceGuid1 = CreateAsset(k_TreeViewTestFolderPath + "/Resources/testResource1.prefab"); var resourceGuid2 = CreateAsset(k_TreeViewTestFolderPath + "/SubFolder/Resources/testResource3.prefab"); var tree = CreateExpandedTree(); var resourcesRow = tree.GetRows().First(c => c.displayName == AddressableAssetEntry.ResourcesName); var resourcesCount = ResourcesTestUtility.GetResourcesEntryCount(m_Settings, true); Assert.AreEqual(resourcesCount, resourcesRow.children.Count); Assert.True(resourcesRow.children.Any(r => r.displayName == GetName(resourceGuid1))); Assert.True(resourcesRow.children.Any(r => r.displayName == GetName(resourceGuid2))); }