Files
SVSimServer/SVSim.BattleEngine/Engine/Wizard/TweenPositionWithUpdate.cs

46 lines
1.4 KiB
C#

using System;
using Cute;
using UnityEngine;
namespace Wizard;
public class TweenPositionWithUpdate : TweenPosition
{
private Action<float> _onUpdate;
public static TweenPosition Begin(GameObject go, float duration, Vector3 pos, Action<float> onUpdate)
{
TweenPositionWithUpdate tweenPositionWithUpdate = UITweener.Begin<TweenPositionWithUpdate>(go, duration);
tweenPositionWithUpdate.from = tweenPositionWithUpdate.value;
tweenPositionWithUpdate.to = pos;
if (duration <= 0f)
{
tweenPositionWithUpdate.Sample(1f, isFinished: true);
tweenPositionWithUpdate.enabled = false;
}
tweenPositionWithUpdate._onUpdate = onUpdate;
return tweenPositionWithUpdate;
}
public static TweenPosition Begin(GameObject go, float duration, Vector3 pos, bool worldSpace, Action<float> onUpdate)
{
TweenPositionWithUpdate tweenPositionWithUpdate = UITweener.Begin<TweenPositionWithUpdate>(go, duration);
tweenPositionWithUpdate.worldSpace = worldSpace;
tweenPositionWithUpdate.from = tweenPositionWithUpdate.value;
tweenPositionWithUpdate.to = pos;
if (duration <= 0f)
{
tweenPositionWithUpdate.Sample(1f, isFinished: true);
tweenPositionWithUpdate.enabled = false;
}
tweenPositionWithUpdate._onUpdate = onUpdate;
return tweenPositionWithUpdate;
}
protected override void OnUpdate(float factor, bool isFinished)
{
base.value = from * (1f - factor) + to * factor;
_onUpdate.Call(factor);
}
}