123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- using System.Threading.Tasks;
- using Fort23.Core;
- using UnityEngine;
- namespace Fort23.Mono
- {
- public class SimpleMove
- {
- private float flyingTime;
- private float delayTime;
-
- private float duration;
-
- private float delay;
- private Vector2 startingPosition;
- private Vector2 targetPoint;
- private RectTransform rt;
- public SimpleMove(RectTransform rt, Vector2 startingPosition, Vector2 targetPoint, float duration = 0.3f)
- {
- flyingTime = 0;
- this.rt = rt;
- this.startingPosition = startingPosition;
- this.targetPoint = targetPoint;
- this.duration = duration;
- rt.position = this.startingPosition;
- }
- public async void Start(float delay)
- {
- // await TimerComponent.Instance.WaitAsync(1000);
- this.delay = delay;
- StaticUpdater.Instance.AddRenderUpdateCallBack(Move);
- }
-
-
- private void Move()
- {
- delayTime += Time.deltaTime;
- if (delayTime < delay)
- {
- return;
- }
-
- flyingTime += Time.deltaTime;
-
- if (duration >= flyingTime)
- {
- rt.position = Vector2.Lerp(startingPosition, targetPoint, flyingTime / duration);
- }
- else
- {
- rt.position = targetPoint;
- StaticUpdater.Instance.RemoveRenderUpdateCallBack(Move);
- }
- }
- }
- }
|