using UnityEngine; using DuloGames.UI.Tweens; namespace DuloGames.UI { public class Test_CompassTester : MonoBehaviour { [SerializeField] private float m_Duration = 4f; [SerializeField] private TweenEasing m_Easing = TweenEasing.Linear; // Tween controls [System.NonSerialized] private readonly TweenRunner m_FloatTweenRunner; protected Test_CompassTester() { if (this.m_FloatTweenRunner == null) this.m_FloatTweenRunner = new TweenRunner(); this.m_FloatTweenRunner.Init(this); } protected void OnEnable() { this.StartTween(360f, this.m_Duration, true); } /// /// Tweens the transform rotation. /// /// Target rotation. /// Duration. /// If set to true ignore time scale. private void StartTween(float targetRotation, float duration, bool ignoreTimeScale) { float currentRotation = this.transform.eulerAngles.y; if (currentRotation.Equals(targetRotation)) return; var floatTween = new FloatTween { duration = duration, startFloat = currentRotation, targetFloat = targetRotation }; floatTween.AddOnChangedCallback(SetRotation); floatTween.AddOnFinishCallback(OnTweenFinished); floatTween.ignoreTimeScale = ignoreTimeScale; floatTween.easing = this.m_Easing; this.m_FloatTweenRunner.StartTween(floatTween); } /// /// Sets the transform rotation. /// /// Rotation. private void SetRotation(float rotation) { this.transform.eulerAngles = new Vector3(this.transform.rotation.x, rotation, this.transform.rotation.z); } /// /// Raises the list tween finished event. /// protected virtual void OnTweenFinished() { this.StartTween(360f, this.m_Duration, true); } } }