diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs index b8a65e0..f53cac1 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject.cs @@ -113,21 +113,11 @@ public float BounceSpeed { get; set; } = 0.75f; /// - /// 投抛状态下物体碰撞器大小, 如果为 (-1, -1), 则默认使用 AnimatedSprite 的默认动画第一帧的大小 + /// 投抛状态下物体碰撞器大小, 如果 (x, y) 都小于 0, 则默认使用 AnimatedSprite 的默认动画第一帧的大小 /// public Vector2 ThrowCollisionSize { get; set; } = new Vector2(-1, -1); - - //是否是第一次下坠 - private bool _firstFall = true; - - //下坠是否已经结束 - private bool _isFallOver = true; - //下坠状态碰撞器形状 - private RectangleShape2D _throwRectangleShape; - - //投抛移动速率 - private ExternalForce _throwForce; + // -------------------------------------------------------------------------------- //组件集合 private List> _components = new List>(); @@ -162,10 +152,24 @@ //物体所在区域 private AffiliationArea _affiliationArea; + //是否是第一次下坠 + private bool _firstFall = true; + + //下坠是否已经结束 + private bool _isFallOver = true; + + //下坠状态碰撞器形状 + private RectangleShape2D _throwRectangleShape; + + //投抛移动速率 + private ExternalForce _throwForce; + //落到地上回弹的速度 private float _resilienceVerticalSpeed = 0; private bool _hasResilienceVerticalSpeed = false; + // -------------------------------------------------------------------------------- + //实例索引 private static long _instanceIndex = 0; @@ -224,6 +228,13 @@ } /// + /// 子类重写的 _Ready() 可能会比 _InitNode() 函数调用晚, 所以禁止子类重写, 如需要 _Ready() 类似的功能需重写 OnInit() + /// + public sealed override void _Ready() + { + } + + /// /// 显示阴影 /// public void ShowShadowSprite() @@ -634,7 +645,7 @@ _hasResilienceVerticalSpeed = false; _resilienceVerticalSpeed = 0; - if (ThrowCollisionSize.X == -1f && ThrowCollisionSize.Y == -1) + if (ThrowCollisionSize.X < 0 && ThrowCollisionSize.Y < 0) { _throwRectangleShape.Size = GetDefaultTexture().GetSize(); } diff --git a/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs b/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs index 2ff215f..01e9f66 100644 --- a/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs +++ b/DungeonShooting_Godot/src/framework/activity/ActivityObject_Register.cs @@ -65,11 +65,11 @@ foreach (var att in attrs) { //注册操作 - if (_activityRegisterMap.ContainsKey(att.Id)) + if (_activityRegisterMap.ContainsKey(att.ItemId)) { - throw new Exception($"Object ID: '{att.Id}' is already registered"); + throw new Exception($"Object ID: '{att.ItemId}' is already registered"); } - _activityRegisterMap.Add(att.Id, new RegisterActivityData(att, () => + _activityRegisterMap.Add(att.ItemId, new RegisterActivityData(att, () => { return (ActivityObject)Activator.CreateInstance(type); })); @@ -86,7 +86,7 @@ if (_activityRegisterMap.TryGetValue(itemId, out var item)) { var instance = item.CallBack(); - instance._InitNode(item.RegisterActivity.Id, item.RegisterActivity.PrefabPath); + instance._InitNode(item.RegisterActivity.ItemId, item.RegisterActivity.PrefabPath); item.RegisterActivity.CustomHandler(instance); return instance; } diff --git a/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs b/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs index d3247b1..4782dd1 100644 --- a/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs +++ b/DungeonShooting_Godot/src/framework/activity/RegisterActivity.cs @@ -10,16 +10,16 @@ /// /// 注册物体唯一ID, 该ID不能有重复 /// - public string Id { get; protected set; } + public string ItemId { get; protected set; } /// /// 模板 Prefab 的路径 /// public string PrefabPath { get; protected set; } - public RegisterActivity(string id, string prefabPath) + public RegisterActivity(string itemId, string prefabPath) { - Id = id; + ItemId = itemId; PrefabPath = prefabPath; } diff --git a/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs b/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs index 0ee6aad..0a1ca23 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/RegisterWeapon.cs @@ -11,7 +11,7 @@ /// private readonly WeaponAttribute _weaponAttribute; - public RegisterWeapon(string id, Type attribute) : base(id, null) + public RegisterWeapon(string itemId, Type attribute) : base(itemId, null) { _weaponAttribute = (WeaponAttribute)Activator.CreateInstance(attribute); if (_weaponAttribute != null) PrefabPath = _weaponAttribute.WeaponPrefab; diff --git a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs index 1f8d8dd..7ee7c40 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/gun/Shotgun.cs @@ -54,9 +54,9 @@ /// public PackedScene ShellPack; - public override void _Ready() + public override void OnInit() { - base._Ready(); + base.OnInit(); ShellPack = ResourceManager.Load(ResourcePath.prefab_weapon_shell_ShellCase_tscn); } diff --git a/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs b/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs index 5d329ac..3bd5f31 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/knife/Knife.cs @@ -37,9 +37,9 @@ private Area2D _hitArea; private int _attackIndex = 0; - public override void _Ready() + public override void OnInit() { - base._Ready(); + base.OnInit(); _hitArea = GetNode("HitArea"); _hitArea.Monitoring = false; diff --git a/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs b/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs index aafcb2d..24c56b8 100644 --- a/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs +++ b/DungeonShooting_Godot/src/game/item/weapon/shell/ShellCase.cs @@ -12,8 +12,9 @@ /// public AnimationPlayer AnimationPlayer { get; private set; } - public override void _Ready() + public override void OnInit() { + base.OnInit(); AnimationPlayer = GetNode("AnimationPlayer"); ShadowOffset = new Vector2(0, 1); ThrowCollisionSize = new Vector2(5, 5); diff --git a/DungeonShooting_Godot/src/game/role/Characters/CPlusPlus.cs b/DungeonShooting_Godot/src/game/role/Characters/CPlusPlus.cs index 85b216a..00e5353 100644 --- a/DungeonShooting_Godot/src/game/role/Characters/CPlusPlus.cs +++ b/DungeonShooting_Godot/src/game/role/Characters/CPlusPlus.cs @@ -18,9 +18,9 @@ { - public override void _Ready() + public override void OnInit() { - base._Ready(); + base.OnInit(); #region 初始属性 MaxHp = 55; diff --git a/DungeonShooting_Godot/src/test/TestActivity.cs b/DungeonShooting_Godot/src/test/TestActivity.cs index 0a9eb8d..21445ed 100644 --- a/DungeonShooting_Godot/src/test/TestActivity.cs +++ b/DungeonShooting_Godot/src/test/TestActivity.cs @@ -3,7 +3,7 @@ [RegisterActivity(ActivityIdPrefix.Test + "1", ResourcePath.prefab_test_TestActivity_tscn)] public partial class TestActivity : ActivityObject { - public override void _Ready() + public override void OnInit() { var externalForce = MoveController.AddConstantForce("move"); externalForce.Velocity = new Vector2(0, 60);