com.soviby.unity.ui.ugui-to.../Assets/Editor/Entity/TextEntity.cs

36 lines
911 B
C#
Raw Normal View History

2024-10-23 17:30:59 +00:00
#if UNITY_EDITOR
2024-10-21 16:20:39 +00:00
using System.Collections;
using System.Collections.Generic;
using UguiToolkit.Editor;
using UnityEngine;
using UnityEngine.UI;
public class TextEntity : BaseEntity<Text, LayoutInfo.TextInfo>
{
2024-10-28 16:31:38 +00:00
private Text m_previewText;
protected override void OnApplyData(Text ui)
2024-10-21 16:20:39 +00:00
{
2024-10-28 16:31:38 +00:00
ui.text = ElementInfo.text;
ui.fontSize = (int)ElementInfo.size;
ui.color = ElementInfo.color;
ui.alignment = TextAnchor.MiddleCenter;
var rectTransform = ui.rectTransform;
rectTransform.sizeDelta = new Vector2(ElementInfo.w + 10, ElementInfo.h + 10);
}
public void InitPreviewText()
{
if (ElementInfo == null) return;
if (!TryGetComponent<Text>(out m_previewText))
{
m_previewText = gameObject.AddComponent<Text>();
}
OnApplyData(m_previewText);
ApplyTransform(transform);
2024-10-21 16:20:39 +00:00
}
2024-10-23 17:30:59 +00:00
}
#endif