public void BuildEntryCreateOrMoveInfoByRules_ExistsMatchedRule_BuildInfoCorrectly() { // Set up. var dummyFolderPath = $"Assets/{Paths.GetAddressablesFolderName()}"; var dummyAssetPath = $"{dummyFolderPath}/Prefabs/prefab_dummy_0001.prefab"; const string dummyAssetFileName = "prefab_dummy_0001.prefab"; var rule = new EntryRule(); rule.SetAddressablePathRule(@"Prefabs/prefab_dummy_(?<id>[0-9]{4})\.prefab"); rule.SetAddressingMode(AddressingMode.AssetName); rule.SetGroupNameRule("Group_${id}"); var rules = new EntryRuleSet(); rules.Add(rule); var assetDatabaseAdapter = new FakeAssetDatabaseAdapter(); var addressableFolderGuid = assetDatabaseAdapter.CreateTestAsset(dummyFolderPath, new Object()); var service = CreateBuildService(assetDatabaseAdapter); // Test. var entryOperationInfo = service.BuildEntryCreateOrMoveInfoByRules(dummyAssetPath, rules, addressableFolderGuid); Assert.That(entryOperationInfo.AssetPath, Is.EqualTo(dummyAssetPath)); Assert.That(entryOperationInfo.Address, Is.EqualTo(dummyAssetFileName)); }
public void BuildEntryCreateOrMoveInfo_NoRulesMatched_UseDefault() { // Set up. var dummyFolderPath = $"Assets/{Paths.GetAddressablesFolderName()}"; var dummyAssetPath = $"{dummyFolderPath}/Prefabs/prefab_dummy_0001.prefab"; const string address = "prefab_dummy_0001.prefab"; var assetDatabaseAdapter = new FakeAssetDatabaseAdapter(); var addressableFolderGuid = assetDatabaseAdapter.CreateTestAsset(dummyFolderPath, new Object()); var service = CreateBuildService(assetDatabaseAdapter); var addressingMode = AddressingMode.AssetName; var packingMode = PackingMode.PackTogether; var rule = new EntryRule(); rule.SetAddressablePathRule(@"__Prefabs/prefab_dummy_(?<id>[0-9]{4})\.prefab"); rule.SetAddressingMode(AddressingMode.AssetName); rule.SetGroupNameRule("Group_${id}"); var rules = new EntryRuleSet(); rules.Add(rule); // Test. var entryOperationInfo = service.BuildEntryCreateOrMoveInfo(dummyAssetPath, addressingMode, packingMode, addressableFolderGuid, rules); Assert.That(entryOperationInfo.AssetPath, Is.EqualTo(dummyAssetPath)); Assert.That(entryOperationInfo.Address, Is.EqualTo(address)); }
/// <summary> /// Build <see cref="EntryCreateOrMoveOperationInfo" />. /// </summary> /// <param name="assetPath"></param> /// <param name="defaultAddressingMode"></param> /// <param name="defaultPackingMode"></param> /// <param name="defaultGroupTemplateGuid"></param> /// <param name="rules"></param> /// <returns></returns> public EntryCreateOrMoveOperationInfo BuildEntryCreateOrMoveInfo(string assetPath, AddressingMode defaultAddressingMode, PackingMode defaultPackingMode, string defaultGroupTemplateGuid, EntryRuleSet rules) { Assert.IsFalse(string.IsNullOrEmpty(assetPath)); Assert.IsFalse(string.IsNullOrEmpty(_assetDatabaseAdapter.GUIDToAssetPath(defaultGroupTemplateGuid))); // Do not process the folder. if (Directory.Exists(assetPath)) { return(null); } var addressablePath = _addressablePathGenerateService.GenerateFromAssetPath(assetPath); if (string.IsNullOrEmpty(addressablePath)) { return(null); } // Determine all rules. if (rules != null) { var info = BuildEntryCreateOrMoveInfoByRules(assetPath, rules, defaultGroupTemplateGuid); if (info != null) { return(info); } } // Apply the default settings if none of the rules are matched. var address = _addressGenerateDomainService.GenerateFromAddressablePath(addressablePath, defaultAddressingMode); var groupName = _groupNameGenerateService.GenerateFromAssetPath(assetPath, defaultPackingMode); var groupTemplateGuid = defaultGroupTemplateGuid; return(new EntryCreateOrMoveOperationInfo(assetPath, address, groupName, groupTemplateGuid, null)); }
/// <summary> /// Call this before you process. /// </summary> public void Setup() { _setting = _settingsRepository.Fetch(); _rules = _rulesRepository.Fetch(); }
/// <summary> /// Build <see cref="EntryCreateOrMoveOperationInfo" /> using <see cref="EntryRuleSet" />. /// </summary> /// <param name="assetPath"></param> /// <param name="rules"></param> /// <param name="defaultGroupTemplateGuid"></param> /// <returns></returns> public EntryCreateOrMoveOperationInfo BuildEntryCreateOrMoveInfoByRules(string assetPath, EntryRuleSet rules, string defaultGroupTemplateGuid) { Assert.IsNotNull(rules); Assert.IsFalse(string.IsNullOrEmpty(assetPath)); Assert.IsFalse(string.IsNullOrEmpty(_assetDatabaseAdapter.GUIDToAssetPath(defaultGroupTemplateGuid))); foreach (var rule in rules) { var info = BuildEntryCreateOrMoveInfoByRule(assetPath, rule, defaultGroupTemplateGuid); if (info != null) { return(info); } } return(null); }