UnityEngine.TextGenerator.Populate C# (CSharp) Method

Populate() public method

Will generate the vertices and other data for the given string with the given settings.

public Populate ( string str, TextGenerationSettings settings ) : bool
str string String to generate.
settings TextGenerationSettings Settings.
return bool
        public bool Populate(string str, TextGenerationSettings settings)
        {
            return (this.PopulateWithError(str, settings) == TextGenerationError.None);
        }

Usage Example

        public void RecalculateTextSizes()
        {
            var minimumSize = int.MaxValue;
            var textGenerator = new TextGenerator();
            foreach (var text in TextComponents)
            {
                //get current text generation settings
                var textGenerationSettings = text.GetGenerationSettings(text.rectTransform.rect.size);

                //update to best fit settings so we can best fit size
                textGenerationSettings.resizeTextForBestFit = true;
                textGenerationSettings.resizeTextMinSize = MinSize;
                textGenerationSettings.resizeTextMaxSize = MaxSize;

                //populate to calculate the new size
                textGenerator.Populate(text.text, textGenerationSettings);

                //set new bestFit if new calculation is smaller than current bestFit
                minimumSize = textGenerator.fontSizeUsedForBestFit < minimumSize
                    ? textGenerator.fontSizeUsedForBestFit
                    : minimumSize;
            }

            // update all text components with new calculated size
            foreach (var text in TextComponents)
            {
                text.fontSize = minimumSize*(int) text.canvas.scaleFactor;
            }
        }
All Usage Examples Of UnityEngine.TextGenerator::Populate