Search Unity

Resolved No way to localize UI Image?

Discussion in 'Localization Tools' started by bottledgalaxy, Jul 16, 2020.

  1. bottledgalaxy

    bottledgalaxy

    Joined:
    Jul 19, 2019
    Posts:
    85
    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!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    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
     
  3. bottledgalaxy

    bottledgalaxy

    Joined:
    Jul 19, 2019
    Posts:
    85
    I believe its a Sprite? Here's a screenshot.

    Trying to localize the Source Image
     

    Attached Files:

  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,297
    Add this script
    Code (csharp):
    1.  
    2. using System;
    3. using UnityEngine.Events;
    4.  
    5. namespace UnityEngine.Localization.Components
    6. {
    7.     [Serializable]
    8.     public class UnityEventSprite : UnityEvent<Sprite> {}
    9.  
    10.     [AddComponentMenu("Localization/Asset/Localize Sprite Event")]
    11.     public class LocalizeSpriteEvent : LocalizedAssetEvent<Sprite, LocalizedSprite, UnityEventSprite>
    12.     {
    13.     }
    14. }
    If you want an editor option to set up the component then add this to an editor script

    Code (csharp):
    1.  
    2. [MenuItem("CONTEXT/Image/Localize")]
    3. static void LocalizeUIImage(MenuCommand command)
    4. {
    5.    var target = command.context as Image;
    6.    var comp = Undo.AddComponent(target.gameObject, typeof(LocalizeSpriteEvent)) as LocalizeSpriteEvent;
    7.    var setTextureMethod = target.GetType().GetProperty("overrideSprite").GetSetMethod();
    8.    var methodDelegate = System.Delegate.CreateDelegate(typeof(UnityAction<Sprite>), target, setTextureMethod) as UnityAction<Sprite>;
    9.    Events.UnityEventTools.AddPersistentListener(comp.OnUpdateAsset, methodDelegate);
    10. }
    11.  
    Ill make sure we have this supported natively in the next release.
     
  5. bottledgalaxy

    bottledgalaxy

    Joined:
    Jul 19, 2019
    Posts:
    85
    Worked like a charm!!! Thanks!!
     
    karl_jones likes this.