YuanXiaoItem.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using FairyGUI;
  5. using UI.ActivityGetYuanXiao;
  6. namespace GFGGame
  7. {
  8. public class YuanXiaoItem
  9. {
  10. private int _type;
  11. private int _score;
  12. private GComponent _com;
  13. private GObject _catcher;
  14. private ActivityGetYuanXiaoView _baseView;
  15. private GTweener _tweener;
  16. public YuanXiaoItem CreateItem(GComponent com, GObject catcher, ActivityGetYuanXiaoView baseView)
  17. {
  18. _com = com;
  19. _catcher = catcher;
  20. _baseView = baseView;
  21. return this;
  22. }
  23. public void Init(int type)
  24. {
  25. SetVisible(true);
  26. _type = type;
  27. UI_YuanXiaoItem item = UI_YuanXiaoItem.Proxy(_com);
  28. item.m_c1.selectedIndex = _type - 1;
  29. UI_YuanXiaoItem.ProxyEnd();
  30. }
  31. public void Move(Vector3 start, Vector3 end, float time, Action action = null)
  32. {
  33. Vector3 startPos = start;
  34. Vector3 endPos = end;
  35. _com.position = startPos;
  36. Timers.inst.Remove(HandleCollider);
  37. Timers.inst.AddUpdate(HandleCollider);
  38. _tweener = _com.TweenMoveY(endPos.y, time);
  39. _tweener.SetEase(EaseType.QuadIn).OnComplete(()=>
  40. {
  41. Timers.inst.Remove(HandleCollider);
  42. action?.Invoke();
  43. });
  44. }
  45. private void HandleCollider(object param = null)
  46. {
  47. if(CheckCollider(_com, _catcher))
  48. {
  49. Timers.inst.Remove(HandleCollider);
  50. _baseView.GetYuanXiao(this);
  51. }
  52. }
  53. private bool CheckCollider(GObject obj1, GObject obj2)
  54. {
  55. Vector3 pos1 = obj1.LocalToGlobal(Vector2.zero);
  56. Vector3 pos2 = obj2.LocalToGlobal(Vector2.zero);
  57. bool collisionX = pos1.x + obj1.width >= pos2.x
  58. && pos2.x + obj2.width >= pos1.x;
  59. bool collisionY = pos1.y + obj1.height >= pos2.y
  60. && pos2.y + obj2.height >= pos1.y;
  61. return collisionX && collisionY;
  62. }
  63. public bool GetVisible()
  64. {
  65. return _com.visible;
  66. }
  67. public void SetVisible(bool visible)
  68. {
  69. _com.visible = visible;
  70. if (!visible)
  71. {
  72. _tweener.Kill(false);
  73. }
  74. }
  75. public int GetYuanXiaoType()
  76. {
  77. return _type;
  78. }
  79. public void SetScore(int score)
  80. {
  81. _score = score;
  82. }
  83. public int GetScore()
  84. {
  85. return _score;
  86. }
  87. public void Destroy()
  88. {
  89. _tweener.Kill(false);
  90. Timers.inst.Remove(HandleCollider);
  91. _com.Dispose();
  92. }
  93. public void SetPause(bool pause = true)
  94. {
  95. if (_com.visible)
  96. {
  97. _tweener.SetPaused(pause);
  98. }
  99. }
  100. }
  101. }