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

47 lines
1.4 KiB
C#
Raw Normal View History

2024-10-23 17:30:59 +00:00
#if UNITY_EDITOR
2024-12-06 10:46:00 +00:00
using System;
2024-10-21 16:20:39 +00:00
using System.Collections;
using System.Collections.Generic;
2024-11-06 17:45:57 +00:00
using UguiToolkit;
2024-10-21 16:20:39 +00:00
using UguiToolkit.Editor;
using UnityEngine;
using UnityEngine.UI;
2024-11-06 17:45:57 +00:00
namespace UguiToolkit.Editor
2024-10-21 16:20:39 +00:00
{
2024-11-06 17:45:57 +00:00
public class TextEntity : BaseEntity<Text, LayoutInfo.TextInfo>
2024-10-21 16:20:39 +00:00
{
2024-11-06 17:45:57 +00:00
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;
2024-10-28 16:31:38 +00:00
2024-11-06 17:45:57 +00:00
var rectTransform = ui.rectTransform;
rectTransform.sizeDelta = new Vector2(ElementInfo.w + 10, ElementInfo.h + 10);
}
2024-10-28 16:31:38 +00:00
2024-12-01 16:33:27 +00:00
public override void InitPreview()
2024-10-28 16:31:38 +00:00
{
2024-11-06 17:45:57 +00:00
if (ElementInfo == null) return;
if (!TryGetComponent<Text>(out m_previewText))
{
m_previewText = gameObject.AddComponent<Text>();
}
OnApplyData(m_previewText);
ApplyTransform(transform);
2024-10-28 16:31:38 +00:00
}
2024-12-10 10:14:38 +00:00
protected override void OnApplyTransform(Transform tf)
2024-11-06 17:45:57 +00:00
{
var position = ElementInfo.Position;
tf.position = StageManager.Instance.PrefabContentsRoot.transform.TransformPoint(new Vector3(position.x, position.y, 0));
tf.rotation = Quaternion.identity;
}
2024-10-21 16:20:39 +00:00
}
2024-10-23 17:30:59 +00:00
}
#endif