diff --git a/scripts/projectile/ISpell.cs b/scripts/projectile/ISpell.cs index dc00581..516b5cd 100644 --- a/scripts/projectile/ISpell.cs +++ b/scripts/projectile/ISpell.cs @@ -20,6 +20,12 @@ public interface ISpell /// PackedScene? GetProjectile(); + /// + /// LoadResource + /// 加载资源 + /// + void LoadResource(); + /// /// Modify Weapon /// 修改武器 @@ -50,6 +56,6 @@ public interface ISpell ///The velocity of the projectile ///抛射体的飞行速度 /// - void ModifyProjectile(int index,Projectile projectile, ref Vector2 velocity); + void ModifyProjectile(int index, Projectile projectile, ref Vector2 velocity); } \ No newline at end of file diff --git a/scripts/spell/NodeSpawnOnKillCharacterSpell.cs b/scripts/spell/NodeSpawnOnKillCharacterSpell.cs index 91ffd0f..ce83add 100644 --- a/scripts/spell/NodeSpawnOnKillCharacterSpell.cs +++ b/scripts/spell/NodeSpawnOnKillCharacterSpell.cs @@ -13,10 +13,11 @@ public partial class NodeSpawnOnKillCharacterSpell : SpellPickAble [Export] private string? _packedScenePath; private NodeSpawnOnKillCharacterDecorator? _nodeSpawnOnKillCharacterDecorator; - public override void _Ready() + + public override void LoadResource() { - base._Ready(); - if (!string.IsNullOrEmpty(_packedScenePath)) + base.LoadResource(); + if (_nodeSpawnOnKillCharacterDecorator == null && !string.IsNullOrEmpty(_packedScenePath)) { _nodeSpawnOnKillCharacterDecorator = new NodeSpawnOnKillCharacterDecorator { diff --git a/scripts/spell/SpellPickAble.cs b/scripts/spell/SpellPickAble.cs index 1c7d4ec..5c29345 100644 --- a/scripts/spell/SpellPickAble.cs +++ b/scripts/spell/SpellPickAble.cs @@ -29,13 +29,10 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell } private PackedScene? _projectileScene; - public override void _Ready() + public sealed override void _Ready() { base._Ready(); - if (!string.IsNullOrEmpty(_projectilePath)) - { - _projectileScene = ResourceLoader.Load(_projectilePath); - } + LoadResource(); } public override int ItemType @@ -48,6 +45,15 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell return _projectileScene; } + public virtual void LoadResource() + { + if (_projectileScene == null && !string.IsNullOrEmpty(_projectilePath)) + { + _projectileScene = ResourceLoader.Load(_projectilePath); + } + } + + public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon) { diff --git a/scripts/weapon/ProjectileWeapon.cs b/scripts/weapon/ProjectileWeapon.cs index 6766a1a..f6a347f 100644 --- a/scripts/weapon/ProjectileWeapon.cs +++ b/scripts/weapon/ProjectileWeapon.cs @@ -140,15 +140,17 @@ public partial class ProjectileWeapon : WeaponTemplate continue; } var item = ItemTypeManager.CreateItem(spellId, this); - if (item == null) + if (item is not ISpell spell) { continue; } + spell.LoadResource(); if (SelfItemContainer.CanAddItem(item)) { SelfItemContainer.AddItem(item); } } + UpdateSpellCache(); } }