源战役客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
2.2 KiB

  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine.UI;
  5. using LuaInterface;
  6. using LuaFramework;
  7. using System;
  8. using UnityEngine.EventSystems;
  9. public class VHScrollRect : ScrollRect
  10. {
  11. public ScrollRect parentScroll;
  12. public bool isVertical = false;
  13. private bool isSelf = false;
  14. public override void OnBeginDrag(PointerEventData eventData)
  15. {
  16. Vector2 touchDeltaPosition;
  17. #if (UNITY_ANDROID || UNITY_IPHONE) && !UNITY_EDITOR
  18. touchDeltaPosition = Input.GetTouch(0).deltaPosition;
  19. #else
  20. float delta_x = Input.GetAxis("Mouse X");
  21. float delta_y = Input.GetAxis("Mouse Y");
  22. touchDeltaPosition = new Vector2(delta_x, delta_y);
  23. #endif
  24. if (isVertical)
  25. {
  26. if (Mathf.Abs(touchDeltaPosition.x) < Mathf.Abs(touchDeltaPosition.y))
  27. {
  28. isSelf = true;
  29. base.OnBeginDrag(eventData);
  30. }
  31. else
  32. {
  33. isSelf = false;
  34. if(parentScroll){
  35. parentScroll.OnBeginDrag(eventData);
  36. }
  37. }
  38. }
  39. else
  40. {
  41. if (Mathf.Abs(touchDeltaPosition.x) > Mathf.Abs(touchDeltaPosition.y))
  42. {
  43. isSelf = true;
  44. base.OnBeginDrag(eventData);
  45. }
  46. else
  47. {
  48. isSelf = false;
  49. if(parentScroll){
  50. parentScroll.OnBeginDrag(eventData);
  51. }
  52. }
  53. }
  54. }
  55. public override void OnDrag(PointerEventData eventData)
  56. {
  57. if (isSelf)
  58. {
  59. base.OnDrag(eventData);
  60. }
  61. else
  62. {
  63. if(parentScroll){
  64. parentScroll.OnDrag(eventData);
  65. }
  66. }
  67. }
  68. public override void OnEndDrag(PointerEventData eventData)
  69. {
  70. if (isSelf)
  71. {
  72. base.OnEndDrag(eventData);
  73. }
  74. else
  75. {
  76. if(parentScroll){
  77. parentScroll.OnEndDrag(eventData);
  78. }
  79. }
  80. }
  81. }