#if UNITY_EDITOR 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 : MonoBehaviour, IEntity where T1 : MonoBehaviour where T2 : LayoutInfo.ElementInfo { // ElementInfo private T2 m_elementInfo; private float rotiation; private float2 scale; private bool needFillTransform; protected T2 ElementInfo => m_elementInfo; 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.localPosition = 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) { } } } #endif