docs.unity3d.com
    Show / Hide Table of Contents

    Choose Formatter

    Use the Choose Formatter to add logic to a Smart String by selecting an output, using a provided set of choices. To invoke the Choose Formatter explicitly, use the name "choose" or "c".

    Diagram showing the breakdown of the Smart String when using a Choose formatter.

    Example Smart String Argument Result
    {0:choose(1|2|3):one|two|three|other} 2 two
    {0:choose(1|2|3):one|two|three|other} 1 one
    {0:choose(1|2|3):one|two|three|other} 5 other
    {0:choose(True|False):yes|no} true yes
    {0:choose(null): NULL | {} } null NULL
    {0:choose(null): NULL | {} } "Hello World" Hello World
    How {0:choose(Male|Female):is he|is she|are they}? "Male" How is he?
    • The value can be anything. It will be converted to string (using ToString), and then matched against the choices. This works great for numbers, booleans, strings, enums, and most simple types.
    • Choices are case-sensitive by default.
    • null is supported too: {0:choose(null): NULL | NOT NULL }
    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023