diff --git a/DungeonShooting_Godot/src/framework/ActivityObject.cs b/DungeonShooting_Godot/src/framework/ActivityObject.cs index 98de12b..6416fd1 100644 --- a/DungeonShooting_Godot/src/framework/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/ActivityObject.cs @@ -49,6 +49,7 @@ /// public Vector2 ShadowOffset { get; protected set; } = new Vector2(0, 2); + //组件集合 private List> _components = new List>(); private bool initShadow; private string _prevAnimation; @@ -63,7 +64,7 @@ var tempPrefab = ResourceManager.Load(scenePath); if (tempPrefab == null) { - throw new Exception("创建 ActivityObject 的参数 scenePath 为 null !"); + throw new Exception("创建 ActivityObject 没有找到指定挂载的预制体: " + scenePath); } var tempNode = tempPrefab.Instance(); @@ -129,6 +130,10 @@ ShadowSprite.Visible = false; } + /// + /// 设置默认序列帧动画的第一帧, 即将删除, 请直接设置 AnimatedSprite.Frames + /// + [Obsolete] public void SetDefaultTexture(Texture texture) { if (AnimatedSprite.Frames == null) @@ -147,10 +152,17 @@ AnimatedSprite.Playing = true; } - public void GetCurrentTexture() + /// + /// 获取当前序列帧动画的 Texture + /// + public Texture GetCurrentTexture() { + return AnimatedSprite.Frames.GetFrame(AnimatedSprite.Name, AnimatedSprite.Frame); } + /// + /// 获取默认序列帧动画的第一帧 + /// public Texture GetDefaultTexture() { return AnimatedSprite.Frames.GetFrame("default", 0); @@ -176,35 +188,35 @@ /// /// 投抛该物体达到最高点时调用 /// - public virtual void OnThrowMaxHeight(float height) + protected virtual void OnThrowMaxHeight(float height) { } /// /// 投抛状态下第一次接触地面时调用, 之后的回弹落地将不会调用该函数 /// - public virtual void OnFirstFallToGround() + protected virtual void OnFirstFallToGround() { } /// /// 投抛状态下每次接触地面时调用 /// - public virtual void OnFallToGround() + protected virtual void OnFallToGround() { } /// /// 投抛结束时调用 /// - public virtual void OnThrowOver() + protected virtual void OnThrowOver() { } /// /// 当前物体销毁时调用, 销毁物体请调用 Destroy() 函数 /// - public virtual void OnDestroy() + protected virtual void OnDestroy() { } @@ -647,4 +659,12 @@ OnThrowOver(); } + + /// + /// 通过 ItemId 实例化 ActivityObject 对象 + /// + public static T Create(string itemId) where T : ActivityObject + { + return null; + } } \ 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 ec7e051..7680055 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/Weapon.cs @@ -166,16 +166,6 @@ } /// - /// 当按下扳机时调用 - /// - protected abstract void OnDownTrigger(); - - /// - /// 当松开扳机时调用 - /// - protected abstract void OnUpTrigger(); - - /// /// 单次开火时调用的函数 /// protected abstract void OnFire(); @@ -186,37 +176,63 @@ /// /// 开火时枪口旋转角度 protected abstract void OnShoot(float fireRotation); + + /// + /// 当按下扳机时调用 + /// + protected virtual void OnDownTrigger() + { + } + + /// + /// 当松开扳机时调用 + /// + protected virtual void OnUpTrigger() + { + } /// /// 当开始换弹时调用 /// - protected abstract void OnReload(); + protected virtual void OnReload() + { + } /// /// 当换弹完成时调用 /// - protected abstract void OnReloadFinish(); + protected virtual void OnReloadFinish() + { + } /// /// 当武器被拾起时调用 /// /// 拾起该武器的角色 - protected abstract void OnPickUp(Role master); + protected virtual void OnPickUp(Role master) + { + } /// /// 当武器从武器袋中移除时调用 /// - protected abstract void OnRemove(); + protected virtual void OnRemove() + { + } /// - /// 当武器被激活时调用, 也就是使用当武器是调用 + /// 当武器被激活时调用, 也就是使用当武器时调用 /// - protected abstract void OnActive(); + protected virtual void OnActive() + { + } /// /// 当武器被收起时调用 /// - protected abstract void OnConceal(); + protected virtual void OnConceal() + { + } public override void _Process(float delta) { @@ -746,7 +762,7 @@ Throw(new Vector2(30, 15), master.MountPoint.GlobalPosition, startHeight, direction, xf, yf, rotate, true); } - public override void OnThrowOver() + protected override void OnThrowOver() { //启用碰撞 CollisionShape2D.Disabled = false; @@ -806,42 +822,4 @@ HideShadowSprite(); OnConceal(); } - // - // /// - // /// 实例化并返回子弹对象 - // /// - // /// 子弹的预制体 - // protected T CreateBullet(PackedScene bulletPack, Vector2 globalPostion, float globalRotation, Node parent = null) - // where T : Node2D, IBullet - // { - // return (T)CreateBullet(bulletPack, globalPostion, globalRotation, parent); - // } - // - // /// - // /// 实例化并返回子弹对象 - // /// - // /// 子弹的预制体 - // protected IBullet CreateBullet(PackedScene bulletPack, Vector2 globalPostion, float globalRotation, - // Node parent = null) - // { - // // 实例化子弹 - // Node2D bullet = bulletPack.Instance(); - // // 设置坐标 - // bullet.GlobalPosition = globalPostion; - // // 旋转角度 - // bullet.GlobalRotation = globalRotation; - // if (parent == null) - // { - // GameApplication.Instance.Room.GetRoot(true).AddChild(bullet); - // } - // else - // { - // parent.AddChild(bullet); - // } - // - // // 调用初始化 - // IBullet result = (IBullet)bullet; - // result.Init(TargetCamp, this, null); - // return result; - // } } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs index 00c5337..b1162a5 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Gun.cs @@ -122,45 +122,4 @@ ); bullet.PutDown(); } - - protected override void OnReload() - { - - } - - protected override void OnReloadFinish() - { - - } - - protected override void OnDownTrigger() - { - - } - - protected override void OnUpTrigger() - { - - } - - protected override void OnPickUp(Role master) - { - - } - - protected override void OnRemove() - { - - } - - protected override void OnActive() - { - - } - - protected override void OnConceal() - { - - } - } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs index f22ec6b..8d04498 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs @@ -92,44 +92,4 @@ bullet.PutDown(); } } - - protected override void OnReload() - { - - } - - protected override void OnReloadFinish() - { - - } - - protected override void OnDownTrigger() - { - - } - - protected override void OnUpTrigger() - { - - } - - protected override void OnPickUp(Role master) - { - - } - - protected override void OnRemove() - { - - } - - protected override void OnActive() - { - - } - - protected override void OnConceal() - { - - } } diff --git a/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs b/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs index 749d494..cf520ef 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs @@ -1,6 +1,9 @@  using Godot; +/// +/// 弹壳类 +/// public class ShellCase : ActivityObject { public ShellCase() : base(ResourcePath.prefab_weapon_shell_ShellCase_tscn) @@ -8,7 +11,7 @@ ShadowOffset = new Vector2(0, 1); } - public override void OnThrowOver() + protected override void OnThrowOver() { AwaitDestroy(); } diff --git a/DungeonShooting_Godot/src/game/role/AnimatorNames.cs b/DungeonShooting_Godot/src/game/role/AnimatorNames.cs index 95aa0ad..2084a1f 100644 --- a/DungeonShooting_Godot/src/game/role/AnimatorNames.cs +++ b/DungeonShooting_Godot/src/game/role/AnimatorNames.cs @@ -4,7 +4,20 @@ /// public static class AnimatorNames { - public static readonly string Idle = "idle"; - public static readonly string Run = "run"; - public static readonly string ReverseRun = "reverseRun"; + /// + /// 静止不动 + /// + public const string Idle = "idle"; + /// + /// 奔跑 + /// + public const string Run = "run"; + /// + /// 倒退奔跑 + /// + public const string ReverseRun = "reverseRun"; + /// + /// 翻滚 + /// + public const string Roll = "roll"; } \ No newline at end of file diff --git a/DungeonShooting_Godot/src/game/role/Role.cs b/DungeonShooting_Godot/src/game/role/Role.cs index 1cdbe2b..51e9377 100644 --- a/DungeonShooting_Godot/src/game/role/Role.cs +++ b/DungeonShooting_Godot/src/game/role/Role.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Godot; @@ -17,8 +18,9 @@ public AnimationPlayer AnimationPlayer { get; private set; } /// - /// 重写的纹理 + /// 重写的纹理, 即将删除, 请直接更改 AnimatedSprite.Frames /// + [Obsolete] public Texture OverrideTexture { get; protected set; } /// @@ -131,7 +133,7 @@ /// 当受伤时调用 /// /// 受到的伤害 - public virtual void OnHit(int damage) + protected virtual void OnHit(int damage) { } @@ -143,6 +145,13 @@ { } + /// + /// 死亡时调用 + /// + protected virtual void OnDie() + { + } + public Role() : this(ResourcePath.prefab_role_Role_tscn) { } @@ -160,13 +169,13 @@ MountPoint = GetNode("MountPoint"); MountPoint.Master = this; BackMountPoint = GetNode("BackMountPoint"); - //即将弃用 + //即将删除 if (OverrideTexture != null) { // 更改纹理 - ChangeFrameTexture(AnimatorNames.Idle, AnimatedSprite, OverrideTexture); - ChangeFrameTexture(AnimatorNames.Run, AnimatedSprite, OverrideTexture); - ChangeFrameTexture(AnimatorNames.ReverseRun, AnimatedSprite, OverrideTexture); + ChangeFrameTexture(AnimatorNames.Idle, AnimatedSprite); + ChangeFrameTexture(AnimatorNames.Run, AnimatedSprite); + ChangeFrameTexture(AnimatorNames.ReverseRun, AnimatedSprite); } Face = FaceDirection.Right; @@ -358,9 +367,10 @@ } /// - /// 更改指定动画的纹理 + /// 更改指定动画的纹理, 即将删除 /// - private void ChangeFrameTexture(string anim, AnimatedSprite animatedSprite, Texture texture) + [Obsolete] + private void ChangeFrameTexture(string anim, AnimatedSprite animatedSprite) { SpriteFrames spriteFrames = animatedSprite.Frames; if (spriteFrames != null)