diff --git a/Example/Tween/EGTween.tscn b/Example/Tween/EGTween.tscn index 57a05b4..abdd0d3 100644 --- a/Example/Tween/EGTween.tscn +++ b/Example/Tween/EGTween.tscn @@ -3,7 +3,7 @@ [ext_resource type="Script" path="res://Example/Tween/Script/TweenTest.cs" id="1_jpym0"] [ext_resource type="StyleBox" uid="uid://t4prctf3uxtb" path="res://Example/Theme/StyleBox/CardFrame.tres" id="2_cbb73"] -[node name="EgTween" type="Control" node_paths=PackedStringArray("Target")] +[node name="EgTween" type="Control" node_paths=PackedStringArray("Target", "Target2D")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -11,11 +11,20 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 script = ExtResource("1_jpym0") -Target = NodePath("Card1") +Target = NodePath("CanvasLayer/Card1") +Target2D = NodePath("Polygon2D") -[node name="Card1" type="Panel" parent="."] -layout_mode = 1 +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="Card1" type="Panel" parent="CanvasLayer"] offset_right = 90.0 offset_bottom = 160.0 -pivot_offset = Vector2(45, 160) +pivot_offset = Vector2(45, 80) theme_override_styles/panel = ExtResource("2_cbb73") + +[node name="Camera2D" type="Camera2D" parent="."] +position = Vector2(146, 80) + +[node name="Polygon2D" type="Polygon2D" parent="."] +position = Vector2(146, 97) +polygon = PackedVector2Array(0, 0, 100, 0, 213.683, 76.1096, 454, 237, 0, 100, 0, 0) diff --git a/Example/Tween/Script/TweenTest.cs b/Example/Tween/Script/TweenTest.cs index 3383349..b1400d5 100644 --- a/Example/Tween/Script/TweenTest.cs +++ b/Example/Tween/Script/TweenTest.cs @@ -1,9 +1,13 @@ using Godot; using System; +using EGFramework.EGTween; + namespace EGFramework.Examples.TweenAnime{ - public partial class TweenTest : Node + public partial class TweenTest : Control { [Export] Control Target {set;get;} + + [Export] Node2D Target2D {set;get;} // Called when the node enters the scene tree for the first time. public override void _Ready() { @@ -21,14 +25,15 @@ namespace EGFramework.Examples.TweenAnime{ // tween2.TweenCallback(Callable.From(TweenOver)); // tween2.SetLoops(); - Tween tween3 = GetTree().CreateTween(); - tween3.SetEase(Tween.EaseType.InOut); - tween3.SetTrans(Tween.TransitionType.Cubic); - tween3.TweenInterval(0.5f); - tween3.TweenProperty(Target,"size",new Vector2(100,40),0.5f); - tween3.TweenProperty(Target,"size",new Vector2(40,100),0.5f); - tween3.TweenProperty(Target,"size",new Vector2(40,40),0.5f); - tween3.SetLoops(); + // Tween tween3 = this.CreateTween(); + // tween3.SetEase(Tween.EaseType.InOut); + // tween3.SetTrans(Tween.TransitionType.Cubic); + // tween3.TweenInterval(0.5f); + // tween3.TweenProperty(Target,"size",new Vector2(100,40),0.5f); + // tween3.TweenProperty(Target,"size",new Vector2(40,100),0.5f); + // tween3.TweenProperty(Target,"size",new Vector2(40,40),0.5f); + // tween3.SetLoops(); + Target2D.TweenRotationByAngle(360f,1.0f); } public void TweenOver(){ diff --git a/addons/EGFramework/Module/NodeExtension/EGTweenExtension.cs b/addons/EGFramework/Module/NodeExtension/EGTweenExtension.cs new file mode 100644 index 0000000..592d64e --- /dev/null +++ b/addons/EGFramework/Module/NodeExtension/EGTweenExtension.cs @@ -0,0 +1,87 @@ +using Godot; +using System; + +namespace EGFramework.EGTween{ + public static class EGTweenExtension + { + #region Position + public static Tween TweenPosition(this Control self,Vector2 position,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"position",position,delay); + return tween; + } + + public static Tween TweenPosition(this Node2D self,Vector2 position,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"position",position,delay); + return tween; + } + + public static Tween TweenPosition(this Node3D self,Vector3 position,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"position",position,delay); + return tween; + } + + #endregion + + #region Rotation + public static Tween TweenRotationByRad(this Control self,float rad,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"rotation",rad,delay); + return tween; + } + public static Tween TweenRotationByAngle(this Control self,float angle,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"rotation",angle*Mathf.Pi/180,delay); + return tween; + } + public static Tween TweenRotationByRad(this Node2D self,float rad,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"rotation",rad,delay); + return tween; + } + public static Tween TweenRotationByAngle(this Node2D self,float angle,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"rotation",angle*Mathf.Pi/180,delay); + return tween; + } + + #endregion + + #region Scale + public static Tween TweenScale(this Control self,Vector2 scale,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"scale",scale,delay); + return tween; + } + public static Tween TweenScale(this Control self,float scale,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"scale",new Vector2(self.Scale.X*scale,self.Scale.Y*scale),delay); + return tween; + } + + public static Tween TweenScale(this Node2D self,Vector2 scale,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"scale",scale,delay); + return tween; + } + public static Tween TweenScale(this Node2D self,float scale,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"scale",new Vector2(self.Scale.X*scale,self.Scale.Y*scale),delay); + return tween; + } + + public static Tween TweenScale(this Node3D self,Vector3 scale,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"scale",scale,delay); + return tween; + } + public static Tween TweenScale(this Node3D self,float scale,float delay){ + Tween tween = self.CreateTween(); + tween.TweenProperty(self,"scale",new Vector3(self.Scale.X*scale,self.Scale.Y*scale,self.Scale.Z*scale),delay); + return tween; + } + #endregion + } +} diff --git a/addons/EGFramework/Module/NodeExtension/Tween/EGTween.cs b/addons/EGFramework/Module/NodeExtension/Tween/EGTween.cs deleted file mode 100644 index 289e814..0000000 --- a/addons/EGFramework/Module/NodeExtension/Tween/EGTween.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Godot; -using static Godot.GD; - -namespace EGFramework{ - public static class EGTween - { - - } -} diff --git a/project.godot b/project.godot index 3954832..0780f1f 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="EGFramework" config/tags=PackedStringArray("official") -run/main_scene="res://Example/Gateway/ModbusGateway.tscn" +run/main_scene="res://Example/Tween/EGTween.tscn" config/features=PackedStringArray("4.2", "C#", "GL Compatibility") config/icon="res://icon.svg"