using UnityEngine; using UnityEngine.UI; using TMPro; using UnityEngine.Events; using AibisDream.UI; namespace AibisDream { [RequireComponent(typeof(BaseButton))] public class ShapeCreateButton : MonoBehaviour { [Header("组件索引")] [SerializeField] private Image backgroundImage; [SerializeField] private Image textBgImage; [SerializeField] private Image signImage; [SerializeField] private TMP_Text text; [SerializeField] private BaseButton button; [Header("颜色配置")] [SerializeField] private ColorTint bgColor; [SerializeField] private ColorTint textBgColor; public UnityEvent OnClicked => button.onClick; private void OnEnable() { button.onStateTransition.AddListener(OnStateTransition); } private void OnDisable() { button.onStateTransition.RemoveListener(OnStateTransition); } public void SetInfo(BlockShapeInfo blockShapeInfo) { signImage.sprite = blockShapeInfo.GetButtonImage(); text.text = blockShapeInfo.shapeName; gameObject.name = blockShapeInfo.shapeName; } private void OnStateTransition(SelectionType type, bool instant) { switch (type) { case SelectionType.Normal: backgroundImage.color = bgColor.normalColor; textBgImage.color = textBgColor.normalColor; break; case SelectionType.Highlighted: backgroundImage.color = bgColor.highlightedColor; textBgImage.color = textBgColor.highlightedColor; break; case SelectionType.Pressed: backgroundImage.color = bgColor.pressedColor; textBgImage.color = textBgColor.pressedColor; break; case SelectionType.Selected: backgroundImage.color = bgColor.selectedColor; textBgImage.color = textBgColor.selectedColor; break; case SelectionType.Disabled: backgroundImage.color = bgColor.disabledColor; textBgImage.color = textBgColor.disabledColor; break; } } } }