public abstract GameObject Render(Renderer renderer);
public override GameObject Render(Renderer renderer) { var go = CreateUIGameObject(renderer); var rect = go.GetComponent <RectTransform>(); rect.anchoredPosition = renderer.CalcPosition(canvasPosition, sizeDelta); rect.sizeDelta = sizeDelta; //var raw = go.AddComponent<RawData>(); //raw.Info["font_size"] = fontSize; //raw.Info["align"] = align; var text = go.AddComponent <Text>(); text.text = message; var fontRes = renderer.GetFont(font); if (fontRes) { text.font = fontRes; } text.color = fontColor; bool middle = true; if (type == "point") { text.horizontalOverflow = HorizontalWrapMode.Overflow; text.verticalOverflow = VerticalWrapMode.Overflow; } else if (type == "paragraph") { text.horizontalOverflow = HorizontalWrapMode.Wrap; text.verticalOverflow = VerticalWrapMode.Overflow; middle = !message.Contains("\n"); } else { Debug.LogError("unknown type " + type); } var fixedPos = rect.anchoredPosition; switch (align) { case "left": text.alignment = middle ? TextAnchor.MiddleLeft : TextAnchor.UpperLeft; rect.pivot = new Vector2(0.0f, 0.5f); fixedPos.x -= sizeDelta.x / 2.0f; break; case "center": text.alignment = middle ? TextAnchor.MiddleCenter : TextAnchor.UpperCenter; rect.pivot = new Vector2(0.5f, 0.5f); break; case "right": text.alignment = middle ? TextAnchor.MiddleRight : TextAnchor.UpperRight; rect.pivot = new Vector2(1.0f, 0.5f); fixedPos.x += sizeDelta.x / 2.0f; break; } rect.anchoredPosition = fixedPos; var d = rect.sizeDelta; d.y = virtualHeight; rect.sizeDelta = d; if (enableStroke) { var outline = go.AddComponent <Outline>(); outline.effectColor = strokeColor; outline.effectDistance = new Vector2(strokeSize / 2.0f, -strokeSize / 2.0f); outline.useGraphicAlpha = false; } SetStretch(go, renderer); SetPivot(go, renderer); return(go); }