Exemplo n.º 1
0
 public static void UpdateText(GameObject key, string str, Vector2 worldPos)
 {
     if (textDisplayerDic.ContainsKey(key))
     {
         var text = textDisplayerDic[key].text;
         text.text = str;
         text.rectTransform.anchoredPosition = VEasyCalc.WorldToGuiPos(worldPos);
     }
 }
Exemplo n.º 2
0
        public static void AssignNewText(GameObject root, string str, Color color,
                                         Vector2 worldPos, Vector2 guiRectSize, TextAnchor alignment)
        {
            var canvas = GUIManager.MainCanvas;
            var go     = new GameObject(root.name + " Text");
            var text   = go.AddComponent <Text>();

            text.rectTransform.SetParent(canvas.transform);

            text.rectTransform.sizeDelta        = new Vector2(guiRectSize.x, guiRectSize.y);
            text.rectTransform.localScale       = new Vector3(1, 1, 1);
            text.rectTransform.anchoredPosition = VEasyCalc.WorldToGuiPos(worldPos);

            text.font      = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;
            text.color     = color;
            text.text      = str;
            text.alignment = alignment;

            textDisplayerDic.Add(root, new TextDisplayer {
                text = text
            });
        }