Hi, I want to make gameobject localizer support the sprite in sprite renderer component.
Also, when I change the variant in the component, the locazlied component can’t follow the change correctly (it will lose the last digit) until reload it. Is it a bug?
And how can I fix this code? (Just imitate the code in document)sorry.
[Serializable]
[DisplayName("Sprite Renderer")]
[CustomTrackedObject(typeof(SpriteRenderer), false)]
public class TrackedSpriteRenderer : TrackedObject
{
public override AsyncOperationHandle ApplyLocale(Locale variantLocale, Locale defaultLocale)
{
var spriteProperty = GetTrackedProperty("m_Sprite");
if (spriteProperty == null)
return default;
// Check if the Asset is stored in an Asset Table
if (spriteProperty is LocalizedAssetProperty localizedAssetProperty &&
localizedAssetProperty.LocalizedObject is LocalizedSprite localizedSprite)
{
localizedSprite.LocaleOverride = variantLocale;
var loadHandle = localizedSprite.LoadAssetAsync();
if (loadHandle.IsDone)
SpriteLoaded(loadHandle);
else
{
loadHandle.Completed += SpriteLoaded;
return loadHandle;
}
}
// Check if the Asset is stored locally
else if (spriteProperty is UnityObjectProperty localAssetProperty)
{
if (localAssetProperty.GetValue(variantLocale.Identifier, defaultLocale.Identifier, out var sprite))
SetSprite(sprite as Sprite);
}
return default;
}
void SpriteLoaded(AsyncOperationHandle<Sprite> loadHandle)
{
SetSprite(loadHandle.Result);
}
void SetSprite(Sprite sprite)
{
var source = (SpriteRenderer)Target;
if (sprite != null)
source.sprite = sprite;
}
public override bool CanTrackProperty(string propertyPath)
{
return propertyPath == "m_Sprite";
}
}
I dont think the type will be LocalizedSprite, it will be LocalizedAsset<Object>. You need to use LoadAssetAsync<Sprite> instead.
Take a look at how TrackedMeshFilter works.
Sorry, I mean the localized asset reference in the localize sprite event component at right. I only can find the ‘Letter’ entry to reference. The entries before missing. The reference assigned can still work, but if I
set it to None, I can’t reference it again.
And I have added a new french locale recently.
Also, I tried to run analyse or build group , but no luck.
Ah sorry I missed the window in the corner. Im not sure why it would do that, we would need to debug the project.
Its also worth upgrading to the latest version of the package 1.5.3. If its not visible in the package manager you can force an upgrade by editing the manifest.json file in the projects Packages folder.