ButtonGazeEffect.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.EventSystems;
  5. using DG.Tweening;
  6. using System;
  7. using SC.InputSystem;
  8. namespace SC
  9. {
  10. public class ButtonGazeEffect : PointEffectBase
  11. {
  12. /// <summary>
  13. /// 初始值
  14. /// </summary>
  15. private float initLocalScaleValue = 0f;
  16. /// <summary>
  17. /// 目标值
  18. /// </summary>
  19. public float endLocalScaleValue = 0.1f;
  20. /// <summary>
  21. /// 初始是否显示Mesh
  22. /// </summary>
  23. private bool InitMeshRenderState=false;
  24. private MeshRenderer _meshRenderer;
  25. protected MeshRenderer meshRenderer {
  26. get {
  27. if (_meshRenderer == null) {
  28. try {
  29. _meshRenderer = GetComponent<MeshRenderer>();
  30. InitMeshRenderState = _meshRenderer.enabled;
  31. } catch (Exception e) {
  32. Debug.Log(e);
  33. }
  34. }
  35. return _meshRenderer;
  36. }
  37. }
  38. private AutoClick _autoClick;
  39. protected AutoClick autoClick {
  40. get {
  41. if (_autoClick == null) {
  42. try {
  43. _autoClick = GetComponentInParent<AutoClick>();
  44. } catch (Exception e) {
  45. Debug.Log(e);
  46. }
  47. }
  48. return _autoClick;
  49. }
  50. }
  51. public override void OnPointerEnter(PointerEventData eventData) {
  52. base.OnPointerEnter(eventData);
  53. if(!autoClick)
  54. return;
  55. if (!InitMeshRenderState && meshRenderer) {
  56. meshRenderer.enabled = true;
  57. }
  58. transform.DOScaleZ(endLocalScaleValue, autoClick.autoClickTime).SetAutoKill(true).SetId("entertween");
  59. }
  60. public override void OnPointerClick(PointerEventData eventData) {
  61. base.OnPointerClick(eventData);
  62. if(!autoClick)
  63. return;
  64. if (!InitMeshRenderState && meshRenderer) {
  65. meshRenderer.enabled = false;
  66. }
  67. DOTween.Kill("entertween");
  68. transform.DOScaleZ(initLocalScaleValue, 0).SetAutoKill(true);
  69. }
  70. public override void OnPointerExit(PointerEventData eventData) {
  71. base.OnPointerExit(eventData);
  72. if(!autoClick)
  73. return;
  74. if (!InitMeshRenderState && meshRenderer) {
  75. meshRenderer.enabled = false;
  76. }
  77. DOTween.Kill("entertween");
  78. transform.DOScaleZ(initLocalScaleValue, 0).SetAutoKill(true);
  79. }
  80. }
  81. }