Advertisement
Guest User

Untitled

a guest
May 19th, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5.  
  6. public class MoveAction : ActionMethod
  7. {
  8. public GameObject MovingObject;
  9. public MoveMethod MoveMode;
  10. public Vector2 MoveVector;
  11. public GameObject TargetPosition;
  12. public Vector2 Offset;
  13. public float Duration;
  14.  
  15. private static Dictionary<GameObject, Tweener> s_ongoingTweeners = new Dictionary<GameObject, Tweener>();
  16.  
  17. public override void Perform()
  18. {
  19. if (s_ongoingTweeners.ContainsKey(MovingObject) && !s_ongoingTweeners[MovingObject].IsComplete())
  20. {
  21. s_ongoingTweeners[MovingObject].Kill();
  22. }
  23.  
  24. Vector3 targetPosition = MovingObject.transform.position;
  25. switch (MoveMode)
  26. {
  27. case MoveMethod.Relative:
  28. targetPosition = MovingObject.transform.position + (Vector3) (MoveVector + Offset);
  29. s_ongoingTweeners[MovingObject] = DOTween.To(() => MovingObject.transform.position, (f) => MovingObject.transform.position = f, targetPosition, Duration);
  30. break;
  31. case MoveMethod.Absolute:
  32. targetPosition = LevelSceneManager.Instance.GetSceneLocalToGlobal(MoveVector + Offset);
  33. s_ongoingTweeners[MovingObject] = DOTween.To(() => MovingObject.transform.position, (f) => MovingObject.transform.position = f, targetPosition, Duration);
  34. break;
  35. case MoveMethod.ToObject:
  36. s_ongoingTweeners[MovingObject] = DOTween.To(() => MovingObject.transform.position, (f) => MovingObject.transform.position = f, TargetPosition.transform.position + (Vector3) Offset, Duration);
  37. break;
  38. }
  39.  
  40. }
  41.  
  42.  
  43. public enum MoveMethod
  44. {
  45. Relative,
  46. Absolute,
  47. ToObject
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement