diff --git a/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs b/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs
index b313c36..7253865 100644
--- a/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs
+++ b/DungeonShooting_Godot/src/framework/generator/ResourcePathGenerator.cs
@@ -60,7 +60,7 @@
try
{
resultStr = "/// \n" +
- "/// 编辑器下所有资源路径, 该类为 Automation 面板下自动生成的, 请不要手动编辑!\n" +
+ "/// 编辑器下所有资源路径, 该类为 Tools 面板下自动生成的, 请不要手动编辑!\n" +
"/// \n" +
"public class ResourcePath\n" +
"{\n";
diff --git a/DungeonShooting_Godot/src/game/AnimatorNames.cs b/DungeonShooting_Godot/src/game/AnimatorNames.cs
index a4c641c..42e0b18 100644
--- a/DungeonShooting_Godot/src/game/AnimatorNames.cs
+++ b/DungeonShooting_Godot/src/game/AnimatorNames.cs
@@ -36,5 +36,12 @@
/// 关门动画
///
public const string CloseDoor = "closeDoor";
-
+ ///
+ /// 开火
+ ///
+ public const string Fire = "fire";
+ ///
+ /// 换弹
+ ///
+ public const string Reload = "reload";
}
\ No newline at end of file
diff --git a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs
index 72893fe..82ec681 100644
--- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs
+++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs
@@ -1,6 +1,5 @@
using Godot;
using System;
-using System.Collections.Generic;
///
/// 武器的基类
@@ -109,6 +108,10 @@
///
public AnimationPlayer AnimationPlayer { get; private set; }
+ ///
+ /// 是否自动播放 SpriteFrames 的动画
+ ///
+ public bool IsAutoPlaySpriteFrames { get; set; } = true;
//--------------------------------------------------------------------------------------------
@@ -172,9 +175,12 @@
FirePoint = GetNode("FirePoint");
OriginPoint = GetNode("OriginPoint");
ShellPoint = GetNode("ShellPoint");
-
- //图标
- SetDefaultTexture(ResourceLoader.Load(Attribute.Sprite2D));
+
+ //设置动画
+ if (attribute.SpriteFrames != null)
+ {
+ AnimatedSprite.SpriteFrames = ResourceManager.Load(attribute.SpriteFrames);
+ }
AnimatedSprite.Position = Attribute.CenterPosition;
//开火位置
@@ -630,6 +636,11 @@
//攻击冷却
_attackTimer += _fireInterval;
+ //播放开火动画
+ if (IsAutoPlaySpriteFrames)
+ {
+ PlaySpriteAnimation(AnimatorNames.Fire);
+ }
//触发开火函数
OnFire();
@@ -775,6 +786,11 @@
{
Reloading = true;
ReloadTimer = Attribute.ReloadTime;
+ //播放换弹动画
+ if (IsAutoPlaySpriteFrames)
+ {
+ PlaySpriteAnimation(AnimatorNames.Reload);
+ }
OnReload();
}
}
@@ -824,6 +840,11 @@
else
{
ReloadTimer = Attribute.ReloadTime;
+ //播放换弹动画
+ if (IsAutoPlaySpriteFrames)
+ {
+ PlaySpriteAnimation(AnimatorNames.Reload);
+ }
OnReload();
}
}
@@ -845,6 +866,16 @@
OnReloadFinish();
}
}
+
+ //播放动画
+ private void PlaySpriteAnimation(string name)
+ {
+ var spriteFrames = AnimatedSprite.SpriteFrames;
+ if (spriteFrames != null && spriteFrames.HasAnimation(name))
+ {
+ AnimatedSprite.Play(name);
+ }
+ }
public override CheckInteractiveResult CheckInteractive(ActivityObject master)
{
diff --git a/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs b/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs
index 0b65411..6c58a92 100644
--- a/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs
+++ b/DungeonShooting_Godot/src/game/item/weapon/WeaponAttribute.cs
@@ -19,9 +19,13 @@
///
public WeaponWeightType WeightType = WeaponWeightType.MainWeapon;
///
- /// 武器的图片
+ /// 武器的图标
///
- public string Sprite2D = ResourcePath.resource_sprite_gun_gun1_png;
+ public string Icon = ResourcePath.resource_sprite_gun_gun1_png;
+ ///
+ /// 动画序列帧
+ ///
+ public string SpriteFrames;
///
/// 是否连续发射, 如果为false, 则每次发射都需要扣动扳机
///
@@ -170,6 +174,10 @@
/// 默认射出的子弹
///
public string BulletId = ActivityIdPrefix.Bullet + "0001";
+ ///
+ /// 投抛状态下物体碰撞器大小
+ ///
+ public Vector2 ThrowCollisionSize = new Vector2(20, 15);
///
/// 克隆一份新的属性配置
@@ -191,7 +199,8 @@
attr.Name = Name;
attr.WeaponPrefab = WeaponPrefab;
attr.WeightType = WeightType;
- attr.Sprite2D = Sprite2D;
+ attr.Icon = Icon;
+ attr.SpriteFrames = SpriteFrames;
attr.ContinuousShoot = ContinuousShoot;
attr.AmmoCapacity = AmmoCapacity;
attr.MaxAmmoCapacity = MaxAmmoCapacity;
@@ -230,6 +239,7 @@
attr.UpliftAngleRestore = UpliftAngleRestore;
attr.AiTargetLockingTime = AiTargetLockingTime;
attr.BulletId = BulletId;
+ attr.ThrowCollisionSize = ThrowCollisionSize;
return attr;
}
diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs
index a78e169..836315d 100644
--- a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs
+++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs
@@ -13,7 +13,7 @@
public RifleAttribute()
{
Name = "步枪";
- Sprite2D = ResourcePath.resource_sprite_gun_gun4_png;
+ Icon = ResourcePath.resource_sprite_gun_gun4_png;
Weight = 40;
CenterPosition = new Vector2(0.4f, -2.6f);
StartFiringSpeed = 480;
@@ -57,7 +57,7 @@
public PistolAttribute()
{
Name = "手枪";
- Sprite2D = ResourcePath.resource_sprite_gun_gun3_png;
+ Icon = ResourcePath.resource_sprite_gun_gun3_png;
Weight = 20;
CenterPosition = new Vector2(0.4f, -2.6f);
WeightType = WeaponWeightType.DeputyWeapon;
diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs
index f5362d2..c6330b9 100644
--- a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs
+++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs
@@ -9,7 +9,7 @@
public ShotgunAttribute()
{
Name = "霰弹枪";
- Sprite2D = ResourcePath.resource_sprite_gun_gun2_png;
+ Icon = ResourcePath.resource_sprite_gun_gun2_png;
Weight = 40;
CenterPosition = new Vector2(0.4f, -2.6f);
StartFiringSpeed = 400;
diff --git a/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs b/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs
index 9452888..c6a328b 100644
--- a/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs
+++ b/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs
@@ -8,7 +8,7 @@
{
public KnifeAttribute()
{
- Sprite2D = ResourcePath.resource_sprite_gun_knife1_png;
+ Icon = ResourcePath.resource_sprite_gun_knife1_png;
WeaponPrefab = ResourcePath.prefab_weapon_Knife_tscn;
//攻速设置
StartFiringSpeed = 180;
@@ -44,8 +44,9 @@
_hitArea = GetNode("HitArea");
_hitArea.Monitoring = false;
_hitArea.Monitorable = false;
-
_hitArea.BodyEntered += OnBodyEntered;
+ //禁用自动播放动画
+ IsAutoPlaySpriteFrames = false;
}
protected override void Process(float delta)
diff --git a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs
index 9d02d1f..2177bda 100644
--- a/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs
+++ b/DungeonShooting_Godot/src/game/role/enemy/Enemy.cs
@@ -11,7 +11,6 @@
#endregion
-using System.Collections.Generic;
using Godot;
///