static AddressableAssetEntry CreateOrUpdateAddressableAssetEntry( AddressableAssetSettings settings, AddressableImportSettings importSettings, AddressableImportRule rule, string assetPath) { // Set group AddressableAssetGroup group; var groupName = rule.ParseGroupReplacement(assetPath); bool newGroup = false; if (!TryGetGroup(settings, groupName, out group)) { if (importSettings.allowGroupCreation) { //TODO Specify on editor which type to create. group = CreateAssetGroup <BundledAssetGroupSchema>(settings, groupName); newGroup = true; } else { Debug.LogErrorFormat("[AddressableImporter] Failed to find group {0} when importing {1}. Please check if the group exists, then reimport the asset.", rule.groupName, assetPath); return(null); } } // Set group settings from template if necessary if (rule.groupTemplate != null && (newGroup || rule.groupTemplateApplicationMode == GroupTemplateApplicationMode.AlwaysOverwriteGroupSettings)) { rule.groupTemplate.ApplyToAddressableAssetGroup(group); } var guid = AssetDatabase.AssetPathToGUID(assetPath); var entry = settings.CreateOrMoveEntry(guid, group); if (entry != null) { // Apply address replacement if address is empty or path. if (string.IsNullOrEmpty(entry.address) || entry.address.StartsWith("Assets/") || rule.simplified || !string.IsNullOrWhiteSpace(rule.addressReplacement)) { entry.address = rule.ParseAddressReplacement(assetPath); } // Add labels if (rule.LabelMode == LabelWriteMode.Replace) { entry.labels.Clear(); } foreach (var label in rule.labels) { entry.labels.Add(label); } } return(entry); }
public void AddressSimplifyTest() { AddressableImportRule rule = new AddressableImportRule(); // Test wildcard + simplify rule.matchType = AddressableImportRuleMatchType.Wildcard; rule.path = "Assets/Sprites/*/*.png"; rule.simplified = true; Assert.AreEqual("cat", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); // Test regex + simplify rule.matchType = AddressableImportRuleMatchType.Regex; rule.path = @"Assets/Sprites/(.*)/(.*)\.png"; rule.simplified = true; Assert.AreEqual("cat", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); // Test simplify + non empty address replacement rule.matchType = AddressableImportRuleMatchType.Regex; rule.addressReplacement = "somevalue"; rule.path = @"Assets/Sprites/(.*)/(.*)\.png"; rule.simplified = true; Assert.AreEqual("cat", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); }
public void ParseAddressReplacementTest() { AddressableImportRule rule = new AddressableImportRule(); // Test empty path rule.matchType = AddressableImportRuleMatchType.Regex; rule.path = ""; Assert.AreEqual("Assets/Sprites/cat/cat.png", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); rule.path = " "; Assert.AreEqual("Assets/Sprites/cat/cat.png", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); // Test empty address replacement rule.matchType = AddressableImportRuleMatchType.Regex; rule.path = @"Assets/Sprites/(.*)/(.*)\.png"; rule.addressReplacement = ""; Assert.AreEqual("Assets/Sprites/cat/cat.png", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); rule.addressReplacement = " "; Assert.AreEqual("Assets/Sprites/cat/cat.png", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); // Test regex + path elements rule.matchType = AddressableImportRuleMatchType.Regex; rule.path = @"Assets/Sprites/(.*)/(.*)\.png"; rule.addressReplacement = "${PATH[0]}"; Assert.AreEqual("Assets", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); rule.addressReplacement = "${PATH[1]}"; Assert.AreEqual("Sprites", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); rule.addressReplacement = "${PATH[-1]}"; Assert.AreEqual("cat", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); rule.addressReplacement = "${PATH[0]}:${PATH[-1]}-element"; Assert.AreEqual("Assets:cat-element", rule.ParseAddressReplacement("Assets/Sprites/cat/cat.png")); // Test regex + unnamed groups rule.matchType = AddressableImportRuleMatchType.Regex; rule.path = @"Assets/Sprites/(.*)/(.*)\.png"; rule.addressReplacement = "${PATH[0]}:$1-$2"; Assert.AreEqual("Assets:cat-foo", rule.ParseAddressReplacement("Assets/Sprites/cat/foo.png")); // Test regex + named groups rule.matchType = AddressableImportRuleMatchType.Regex; rule.path = @"Assets/Sprites/(?<category>.*)/(?<asset>.*)\.png"; rule.addressReplacement = "${PATH[0]}:${category}-${asset}"; Assert.AreEqual("Assets:cat-foo", rule.ParseAddressReplacement("Assets/Sprites/cat/foo.png")); }