Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Intercept sprite names in atlas

Discussion in 'UGUI & TextMesh Pro' started by maltakereuz, Dec 7, 2023.

  1. maltakereuz


    Mar 29, 2015
    I have multiple gui screen in my game whith TextMeshPro for texts, that all use same sprite atlas. I have very many different places in code where I add some string with sprites. Pretty often these sprites are icons of xbox controller A B X Y. Like "Press <sprite name="B" to open the treasure chest".

    Now I want to support Playstaion gamepad icons. Instead of adding IF-s each time I construct such string, it would be really tame-saving just to continue using A B X Y and well... force sprite atlas to return cross circle square and triangle if my bool variable playstationIcons == true.

    Or maybe I can somehow intercept the way it goes from TextMeshPROUGUText.text field into actual sprite. Can I add some string replace like this only in one single place to make it always work?

    Code (CSharp):
    1.             str = str.Replace("\"A\"", "\"cross\"");
    2.             str = str.Replace("\"B\"", "\"circle\"");
    3.             str = str.Replace("\"X\"", "\"square\"");
    4.             str = str.Replace("\"Y\"", "\"triangle\"");
    Otherwise I need to wrap it with method Adjust and call it 100+ times, what I would like to avoid.