58 lines
1.6 KiB
C#
58 lines
1.6 KiB
C#
using System.Collections;
|
|
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;
|
|
|
|
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;
|
|
transform.position = new Vector3(position.x, position.y, 0);
|
|
}
|
|
|
|
// 查找时调用
|
|
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)
|
|
{
|
|
OnApplyData(ui, m_elementInfo);
|
|
}
|
|
|
|
protected virtual void OnApplyData(T1 ui, T2 elementInfo) { }
|
|
}
|
|
} |