using DG.Tweening;
using UnityEngine;
public static class DOTweenExtensions {
public static Tweener DORotateAround2D(this Transform transform, Vector3 pivot, float angle, float duration) {
Vector3 startPos = transform.position;
float startAngle = Vector2.SignedAngle(Vector2.right, startPos - pivot);
float endAngle = startAngle + angle;
float startZRotation = transform.eulerAngles.z;
return DOTween.To(() => startAngle, x => startAngle = x, endAngle, duration)
.OnUpdate(() => {
float radian = startAngle * Mathf.Deg2Rad;
float radius = Vector2.Distance(pivot, startPos);
float x = pivot.x + radius * Mathf.Cos(radian);
float y = pivot.y + radius * Mathf.Sin(radian);
transform.position = new Vector3(x, y, transform.position.z);
transform.eulerAngles = new Vector3(0, 0, startZRotation + (startAngle - Vector2.SignedAngle(Vector2.right, startPos - pivot)));
});
}
}