MouseButton.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using FancyScrollView.FocusOn;
  6. using UnityEngine.Events;
  7. public class MouseButton : MonoBehaviour
  8. {
  9. [SerializeField] RectTransform targetRTF;
  10. [SerializeField] Graphic targetGraphic;
  11. [SerializeField] Color selectedColor = new Color(1, 1, 1, 0.6f);
  12. Vector3 _scale;
  13. Color _color;
  14. [SerializeField] public Button targetButton;
  15. [SerializeField] public GameObject cellObj;
  16. [SerializeField]
  17. UnityEvent OnStartEvent;
  18. [SerializeField]
  19. UnityEvent OnEndEvent;
  20. public void OnSelect() {
  21. if (targetGraphic) {
  22. _color = targetGraphic.color;
  23. targetGraphic.color = selectedColor;
  24. }
  25. if (targetRTF) {
  26. _scale = targetRTF.localScale;
  27. targetRTF.localScale = _scale * 1.15f;
  28. }
  29. if (targetButton) {
  30. targetButton.image.sprite = targetButton.spriteState.highlightedSprite;
  31. }
  32. if (cellObj) {
  33. cellObj.GetComponent<Cell>().onCellClickedEvent();
  34. }
  35. }
  36. public void OnExit() {
  37. if (targetGraphic) targetGraphic.color = _color;
  38. if (targetRTF) targetRTF.localScale = _scale;
  39. if (targetButton)
  40. {
  41. targetButton.image.sprite = targetButton.spriteState.disabledSprite;
  42. }
  43. //if (cellObj)
  44. //{
  45. // cellObj.SetActive(false);
  46. //}
  47. }
  48. public void OnSendStart() {
  49. OnStartEvent.Invoke();
  50. }
  51. public void OnSendEnd() {
  52. OnEndEvent.Invoke();
  53. }
  54. }