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

61 lines
1.6 KiB
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 Unity.Mathematics;
using UnityEngine;
namespace UguiToolkit.Editor
{
public interface IEntity
{
void SetTransform(float rotiation, float2 scale);
void ApplyTransform(Transform transform);
}
public abstract class BaseEntity<T1,T2> : MonoBehaviour, IEntity where T1 : MonoBehaviour where T2 : LayoutInfo.ElementInfo
{
// ElementInfo
private T2 m_elementInfo;
private float rotiation;
private float2 scale;
private bool needFillTransform;
2024-10-23 17:30:59 +00:00
protected T2 ElementInfo => m_elementInfo;
2024-10-21 16:20:39 +00:00
public void ApplyTransform(Transform transform)
{
if (needFillTransform)
{
transform.rotation = Quaternion.Euler(0, 0, rotiation);
transform.localScale = new Vector3(scale.x, scale.y, 0);
}
var position = m_elementInfo.Position;
2024-10-23 17:30:59 +00:00
transform.localPosition = new Vector3(position.x, position.y, 0);
2024-10-21 16:20:39 +00:00
}
// 查找时调用
public void SetTransform(float rotiation, float2 scale)
{
this.rotiation = rotiation;
this.scale = scale;
this.needFillTransform = true;
}
// 查找时调用
public void ClearFillTransform() => this.needFillTransform = false;
// 创建时调用
public void SetData(T2 elementInfo)
{
this.m_elementInfo = elementInfo;
}
public void ApplyData(T1 ui)
{
2024-10-28 16:31:38 +00:00
OnApplyData(ui);
2024-10-21 16:20:39 +00:00
}
2024-10-28 16:31:38 +00:00
protected virtual void OnApplyData(T1 ui) { }
2024-10-21 16:20:39 +00:00
}
2024-10-23 17:30:59 +00:00
}
#endif