Bug Using custom Addressable Name in "Google.Android.PerformanceTuner.AddressablesScenesEnumInfo.ConvertScenePathToProtoEnumEntry()"
Hey
I find having a scene called "System_Audio" fail when I'm trying to update the Addressables Settings scenes in ATP tab
here some images:
Issue Happens because method assumes addresable item contains extension file in their name
instead of doing this
// Use this function to get the protobuf Scene Enum entry corresponding to a scene.
public static string ConvertScenePathToProtoEnumEntry(string scenePath, bool isAddressableScene)
{
string sceneName = scenePath
.Replace(Path.DirectorySeparatorChar, '_')
.Replace(Path.AltDirectorySeparatorChar, '_')
.Replace(Path.GetExtension(scenePath), "")
.Replace(" ", "_")
.ToUpper();
sceneName = k_SceneFieldRegex.Replace(sceneName, "");
string prefix = isAddressableScene ? "ADDR_" : "";
return prefix + sceneName;
}
do this
// Use this function to get the protobuf Scene Enum entry corresponding to a scene.
public static string ConvertScenePathToProtoEnumEntry(string scenePath, bool isAddressableScene)
{
string sceneName = scenePath
.Replace(Path.DirectorySeparatorChar, '_')
.Replace(Path.AltDirectorySeparatorChar, '_')
.Replace(" ", "_")
.ToUpper();
// parche, en caso de que el item posea extension se la quitamos
if(Path.GetExtension(scenePath)?.Length > 0)
{
sceneName = sceneName.Replace(Path.GetExtension(scenePath), "");
}
else
{
// Fino mi pana 👍
}
sceneName = k_SceneFieldRegex.Replace(sceneName, "");
string prefix = isAddressableScene ? "ADDR_" : "";
return prefix + sceneName;
}
in this case, if addressable item does not have an extension it does not give you a zero lenght string, causing a false positive error
hope it helps :) !😎
Update:
better approach
public static class AddressablesScenesEnumInfoExtension
{
public static string PatchReplacer(this string _value, in char finder, in char replacer)
=> _value.Contains(finder)
? _value.Replace(finder, replacer)
: _value
;
public static string PatchReplacer(this string _value, in string finder, in string replacer = "")
=> _value.Contains(finder)
? _value.Replace(finder, replacer)
: _value
;
}
// Use this function to get the protobuf Scene Enum entry corresponding to a scene.
public static string ConvertScenePathToProtoEnumEntry(string scenePath, bool isAddressableScene)
{
// string sceneName = scenePath
// .Replace(Path.DirectorySeparatorChar, '_')
// .Replace(Path.AltDirectorySeparatorChar, '_')
// .Replace(" ", "_")
// .ToUpper();
string sceneName = scenePath
.PatchReplacer(Path.DirectorySeparatorChar, '_')
.PatchReplacer(Path.AltDirectorySeparatorChar, '_')
.PatchReplacer(Path.GetExtension(scenePath), "")
.PatchReplacer(" ", "_")
.ToUpper();
sceneName = k_SceneFieldRegex.Replace(sceneName, "");
string prefix = isAddressableScene ? "ADDR_" : "";
return prefix + sceneName;
}
Fix for ConvertScenePathToProtoEnumEntry Function
The ConvertScenePathToProtoEnumEntry function was failing due to an ArgumentException when trying to replace a string of zero length. This was happening because the Path.GetExtension(scenePath) was returning an empty string if the scenePath did not have an extension.
To fix this issue, a check was added to ensure that the extension is not an empty string before attempting to replace it. Here's the modified function:
public static string ConvertScenePathToProtoEnumEntry(string scenePath, bool isAddressableScene)
{
Debug.Log("ConvertScenePathToProtoEnumEntry" + scenePath + " " + isAddressableScene);
string sceneName = scenePath
.Replace(Path.DirectorySeparatorChar, '_')
.Replace(Path.AltDirectorySeparatorChar, '_')
.Replace(" ", "_")
.ToUpper();
// Check if the scenePath has an extension before trying to replace it
string extension = Path.GetExtension(scenePath);
if (!string.IsNullOrEmpty(extension))
{
sceneName = sceneName.Replace(extension, "");
}
Debug.Log("ConvertScenePathToProtoEnumEntry sceneName: " + sceneName);
sceneName = k_SceneFieldRegex.Replace(sceneName, "");
string prefix = isAddressableScene ? "ADDR_" : "";
return prefix + sceneName;
}