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
コード例 #1
0
        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;
            }
        }
コード例 #2
0
    public virtual void LayoutText(string content)
    {
        this.content = content.Trim();
        Canvas.ForceUpdateCanvases();

        TextGenerator generator = new TextGenerator();
        TextGenerationSettings settings = text.GetGenerationSettings(new Vector2(rectTransform.sizeDelta.x, 0));
        settings.updateBounds = true;
        settings.scaleFactor = 1;
        generator.Populate(content, settings);
        layoutElement.preferredHeight = generator.rectExtents.height;
    }
コード例 #3
0
 static int Populate(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 3);
         UnityEngine.TextGenerator obj = (UnityEngine.TextGenerator)ToLua.CheckObject(L, 1, typeof(UnityEngine.TextGenerator));
         string arg0 = ToLua.CheckString(L, 2);
         UnityEngine.TextGenerationSettings arg1 = (UnityEngine.TextGenerationSettings)ToLua.CheckObject(L, 3, typeof(UnityEngine.TextGenerationSettings));
         bool o = obj.Populate(arg0, arg1);
         LuaDLL.lua_pushboolean(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
コード例 #4
0
ファイル: ExampleClass.cs プロジェクト: pass86/Unity
 void Start()
 {
     TextGenerationSettings settings = new TextGenerationSettings();
     settings.textAnchor = TextAnchor.MiddleCenter;
     settings.color = Color.red;
     settings.generationExtents = extents;
     settings.pivot = Vector2.zero;
     settings.richText = true;
     settings.font = font;
     settings.fontSize = 32;
     settings.resizeTextMinSize = resizeTextMinSize;
     settings.resizeTextMaxSize = resizeTextMaxSize;
     settings.fontStyle = FontStyle.Normal;
     settings.verticalOverflow = VerticalWrapMode.Overflow;
     TextGenerator generator = new TextGenerator();
     generator.Populate("I am a string", settings);
     Debug.Log("I generated: " + generator.vertexCount + " verts!");
 }
コード例 #5
0
ファイル: DialogueBox.cs プロジェクト: luigivieira/Ze-do-Rego
    /// <summary>
    /// Calculates the text height with generator.
    /// 
    /// Usage example, the 0.6 is a default good value:		
    /// CalculateTextHeightWithGenerator(textContainerSize.rect.width,
    //                                         choice.dialogue,
    //                                         0.6f,
    //                                         btnText.font,
    //                                         btnText.fontSize,
    //                                         btnText.fontStyle);
    /// </summary>
    /// <returns>The text height with generator.</returns>
    /// <param name="maxWidth">Max width.</param>
    /// <param name="text">Text.</param>
    /// <param name="reducePercentage">Reduce percentage.</param>
    /// <param name="font">Font.</param>
    /// <param name="fontSize">Font size.</param>
    /// <param name="fontStyle">Font style.</param>
    private float CalculateTextHeightWithGenerator(float maxWidth, string text, 
	                                               float reducePercentage, Font font, 
	                                               int fontSize, FontStyle fontStyle)
    {
        TextGenerationSettings settings = new TextGenerationSettings();
        settings.textAnchor = TextAnchor.UpperLeft;
        settings.generationExtents = new Vector2(maxWidth, 0);
        settings.pivot = Vector2.zero;
        settings.richText = true;
        settings.lineSpacing = 0.1f;
        settings.font = font;
        settings.fontSize = fontSize;
        settings.fontStyle = fontStyle;
        settings.verticalOverflow = VerticalWrapMode.Overflow;
        TextGenerator generator = new TextGenerator();
        generator.Populate(text, settings);
        float height = generator.GetPreferredHeight(text, settings);

        return height * reducePercentage;
    }