#if UNITY_EDITOR using System; using System.Collections; using System.Collections.Generic; using UguiToolkit; using UguiToolkit.Editor; using UnityEngine; using UnityEngine.UI; namespace UguiToolkit.Editor { public class TextEntity : BaseEntity { private Text m_previewText; protected override void OnApplyData(Text ui) { 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 override void InitPreview() { if (ElementInfo == null) return; if (!TryGetComponent(out m_previewText)) { m_previewText = gameObject.AddComponent(); } OnApplyData(m_previewText); ApplyTransform(transform); } protected override void OnApplyTransform(Transform tf) { var position = ElementInfo.Position; tf.position = StageManager.Instance.PrefabContentsRoot.transform.TransformPoint(new Vector3(position.x, position.y, 0)); tf.rotation = Quaternion.identity; } } } #endif