No way to localize UI Image?

I’m trying to localize my UI, but the example on the QuickStart mentions Raw Image, and when I try to manually set the LocalizeTextureEvent, and drop the GameObject with the Image component, I can’t seem to find which options works.

Thanks!

Is it a Sprite or a Raw Image? We have not added an option to Sprites yet but it should be simple to add. If thats what you need I can provide some code

I believe its a Sprite? Here’s a screenshot.

Trying to localize the Source Image

6098553--662988--Screen Shot 2020-07-16 at 4.39.30 PM.png

Add this script

using System;
using UnityEngine.Events;

namespace UnityEngine.Localization.Components
{
    [Serializable]
    public class UnityEventSprite : UnityEvent<Sprite> {}

    [AddComponentMenu("Localization/Asset/Localize Sprite Event")]
    public class LocalizeSpriteEvent : LocalizedAssetEvent<Sprite, LocalizedSprite, UnityEventSprite>
    {
    }
}

If you want an editor option to set up the component then add this to an editor script

[MenuItem("CONTEXT/Image/Localize")]
static void LocalizeUIImage(MenuCommand command)
{
   var target = command.context as Image;
   var comp = Undo.AddComponent(target.gameObject, typeof(LocalizeSpriteEvent)) as LocalizeSpriteEvent;
   var setTextureMethod = target.GetType().GetProperty("overrideSprite").GetSetMethod();
   var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction<Sprite>), target, setTextureMethod) as UnityAction<Sprite>;
   Events.UnityEventTools.AddPersistentListener(comp.OnUpdateAsset, methodDelegate);
}

Ill make sure we have this supported natively in the next release.

Worked like a charm!!! Thanks!!

1 Like