docs.unity3d.com
    Show / Hide Table of Contents

    Creating a custom source

    You can create custom sources using the ISource interface.

    The following example shows how to create a source that generates a random number. This could then be combined with a choose Formatter to produce different random responses.

    [Serializable]
    public class RandomValueSource : ISource
    {
        public int min = 1;
        public int max = 5;
    
        public string selector = "random";
    
        public bool TryEvaluateSelector(ISelectorInfo selectorInfo)
        {
            if (selectorInfo.SelectorText != selector)
                return false;
    
            selectorInfo.Result = Random.Range(min, max);
            return true;
        }
    }
    
    Example Smart String Result
    {random:choose(1|2|3}:Hello|Greetings|Welcome|Hi}! Welcome!
    Back to top
    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