12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System.Threading.Tasks;
- using Fort23.Core;
- using Fort23.UTool;
- 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 targetRT;
- public SimpleMove(RectTransform targetRT, Vector2 startingPosition, Vector2 targetPoint, float duration = 0.3f)
- {
- flyingTime = 0;
- delayTime = 0;
- this.targetRT = targetRT;
- this.startingPosition = startingPosition;
- this.targetPoint = targetPoint;
- this.duration = duration;
- targetRT.position = this.startingPosition;
- // PrintInfo(1);
- // rt.gameObject.SetActive(false);
- }
- // private void PrintInfo(byte typ)
- // {
- // LogTool.Log("【" + typ + "】startPos: " + startingPosition + " | " + "targetPos:" + targetPoint);
- // }
-
- // public void SetRectTransform(RectTransform targetRT)
- // {
- // this.targetRT = targetRT;
- // targetRT.position = this.startingPosition;
- // PrintInfo(2);
- // }
- //
- // public void Reverse()
- // {
- // // ReSharper disable once SwapViaDeconstruction
- // var temp = startingPosition;
- // startingPosition = targetPoint;
- // targetPoint = temp;
- // flyingTime = 0;
- // delayTime = 0;
- // }
- public async void Start(float delay)
- {
- // await TimerComponent.Instance.WaitAsync(1000);
- this.delay = delay;
-
- // rt.gameObject.SetActive(true);
- StaticUpdater.Instance.AddRenderUpdateCallBack(Move);
- }
-
-
- private void Move()
- {
- delayTime += Time.deltaTime;
- if (delayTime < delay)
- {
- return;
- }
-
- flyingTime += Time.deltaTime;
-
- if (duration >= flyingTime)
- {
- targetRT.position = Vector2.Lerp(startingPosition, targetPoint, flyingTime / duration);
- }
- else
- {
- targetRT.position = targetPoint;
- StaticUpdater.Instance.RemoveRenderUpdateCallBack(Move);
- }
- }
- }
- }
|