Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Group Name Replacement via RegEx Capture - Can't force lowercase group name with \L #56

Open
1 task done
nindim opened this issue Jun 19, 2021 · 2 comments
Open
1 task done

Comments

@nindim
Copy link

nindim commented Jun 19, 2021

Bug report

Bug category

  • Importer: issues related to the importer behaviours or UI.

Steps to reproduce

Follow the docs to setup a group name via RegEx Capture: https://github.com/favoyang/unity-addressable-importer/blob/master/Documentation~/AddressableImporter.md#group-replacement

Ensure the files making up the group name have some uppercase letters.

Set the group name to "\L${name}\E".

What is expected?

It is expected that the filename be extarcted and forced to lowercase.

What is actually happening?

The filename is being extracted but it is not lowercase and it has prefixes and suffixes as such:

"-Lbaseballcap1_Variant1-E"

Expected group name is: "baseballcap1_variant1" (note the lowercase 'v')

Other relevant information

I have files with mixed cases in different folders that I need to combine into a single Addressable group:

Example:
"Assets/Models/Baseball_Cap_Variant1.fbx"
"Assets/Prefabs/baseball_cap_variant1.prefab"

I would like both files to be stored in the same addressable group and as I can't rename the files the easiest way to achieve that seems to be to force a lowercase group name for both rules.

Without this support my groups are getting very messed up when allowing group creation as Addressables reloads from disk mid-import and it breaks all my groups!

I tracked it down to this code executing in AddressableAssetGroupSchema::AddSchema():

var assetName = pathFunc(type); if (File.Exists(assetName)) { Debug.LogWarningFormat("Schema asset already exists at path {0}, relinking.", assetName); var existingSchema = AssetDatabase.LoadAssetAtPath(assetName, type) as AddressableAssetGroupSchema; m_Schemas.Add(existingSchema); return existingSchema; }

Thank you for your help!

  • OS (Win/Mac/Linux/Others): Windows 10
  • Unity version: 2018.4.23
  • Addressables version: 1.16.10
  • Unity Addressable Importer version: 0.9.4
@favoyang
Copy link
Owner

Hi @nindim,

AFAIK, \L, \U, \E which works for Perl, are not supported in .NET regex substitutions: https://social.msdn.microsoft.com/Forums/en-US/5ae2778b-2e1a-4e3b-8471-3fe97e268f72/does-u-convert-to-uppercase-work-in-net-regex?forum=regexp

In the replacement logic, the importer also replaced the path sep (\ or /) with a dash (-) to generate a probable group name. (the method is shared for both addressable name and group name replacement parsing).

public string ParseReplacement(string assetPath, string name)
{
if (string.IsNullOrWhiteSpace(path) || string.IsNullOrWhiteSpace(name))
return null;
var cleanedName = name.Trim().Replace('/', '-').Replace('\\', '-');
// Parse path elements.
var replacement = AddressableImportRegex.ParsePath(assetPath, cleanedName);
// Parse this.path regex.
if (matchType == AddressableImportRuleMatchType.Regex)
{
string pathRegex = path;
replacement = Regex.Replace(assetPath, pathRegex, replacement);
}
return replacement;
}

I think it would be harder to achieve this unless we switch to another regex library that supports the Perl syntax or implement it ourselves. A workaround is to add a checkbox to the rule to ensure the group name are lowercase.

Thought?

@nindim
Copy link
Author

nindim commented Sep 14, 2021

Hey @favoyang,

This would definitely work for our use case!

All the best,

Niall

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants