OffsetEffect.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using UnityEngine;
  2. namespace WXB
  3. {
  4. public class OffsetEffect : IEffect
  5. {
  6. Vector2 offset = Vector2.zero;
  7. public float xMin = -5f;
  8. public float yMin = -5f;
  9. public float xMax = 5f;
  10. public float yMax = 5f;
  11. public float speed = 2f;
  12. Tweener tweener;
  13. Draw current = null;
  14. public void UpdateEffect(Draw draw, float deltaTime)
  15. {
  16. if (tweener == null)
  17. {
  18. tweener = new Tweener();
  19. tweener.method = Tweener.Method.EaseInOut;
  20. tweener.style = Tweener.Style.PingPong;
  21. tweener.duration = 1f;
  22. tweener.OnUpdate = UpdateOffset;
  23. }
  24. current = draw;
  25. tweener.Update(deltaTime);
  26. current = null;
  27. }
  28. void UpdateOffset(float val, bool isFin)
  29. {
  30. offset = Vector2.Lerp(new Vector2(xMin, yMin), new Vector2(xMax, yMax), val);
  31. Tools.UpdateRect(current.rectTransform, offset);
  32. }
  33. public void Release()
  34. {
  35. if (tweener != null)
  36. {
  37. tweener.method = Tweener.Method.EaseInOut;
  38. tweener.style = Tweener.Style.PingPong;
  39. tweener.duration = 1f;
  40. }
  41. current = null;
  42. xMin = -5f;
  43. yMin = -5f;
  44. xMax = 5f;
  45. yMax = 5f;
  46. speed = 2f;
  47. offset = Vector2.zero;
  48. }
  49. }
  50. }