Godot原生方法
GetTree().CreateTween()
.TweenProperty(@GodotObject, "属性名称", 目标值, 时间)
.SetEase(Tween.EaseType.In /* 缓动类型 */)
.SetTrans(Tween.TransitionType.Sine /* 过渡类型 */)
.Finished += () => { /* 结束回调 */ };GTweensGodot
基本用法
引入命名空间
using GTweensGodot.Extensions;部分示例
// ModulateAlpha
@CanvasItem.TweenModulateAlpha(1, 0.25f)
.Play();
// Position
@Node2D.TweenPosition(new Vector2(100, 0), 3)
.SetEasing(Easing.InOutCubic)
.Play();自定义Tween
官方未支持的类型、属性需要自定义 函数需要是公开的、静态的,写在哪都行
public static GTweens.Tweens.GTween TweenXXX(
T target /* 目标对象 */,
V to /* 目标值 */,
float duration
) {
return GTweenGodotExtensions.Tween(
() => {
// 获取值
// 可以理解成属性的getter
},
current => {
// 设置值
// 可以理解成属性的setter
},
to,
duration,
GodotObjectExtensions.GetGodotObjectValidationFunction(target)
);
}示例:Control的CustomMinimumSize属性
public static GTweens.Tweens.GTween TweenCustomMinimumSize(Control target, Vector2 to, float duration) {
return GTweenGodotExtensions.Tween(
() => target.CustomMinimumSize,
current => target.CustomMinimumSize = current,
to,
duration,
GodotObjectExtensions.GetGodotObjectValidationFunction(target)
);
}