Adjust when to load resources.
调整加载资源的时机。
This commit is contained in:
parent
e21d37edce
commit
1fee1cce86
|
@ -55,6 +55,7 @@ shape = SubResource("RectangleShape2D_7tsse")
|
||||||
[node name="Marker2D" type="Marker2D" parent="."]
|
[node name="Marker2D" type="Marker2D" parent="."]
|
||||||
position = Vector2(260, 87)
|
position = Vector2(260, 87)
|
||||||
script = ExtResource("1_y2vgj")
|
script = ExtResource("1_y2vgj")
|
||||||
|
_resPathArray = null
|
||||||
|
|
||||||
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
|
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="."]
|
||||||
navigation_polygon = SubResource("NavigationPolygon_rh1gx")
|
navigation_polygon = SubResource("NavigationPolygon_rh1gx")
|
||||||
|
|
|
@ -432,7 +432,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
//您可以在这里补充更多类型对象的捡起状态处理。
|
//您可以在这里补充更多类型对象的捡起状态处理。
|
||||||
if (pickAbleItemNode2D is PickAbleTemplate pickAbleTemplate)
|
if (pickAbleItemNode2D is PickAbleTemplate pickAbleTemplate)
|
||||||
{
|
{
|
||||||
pickAbleTemplate.LoadingResource();
|
pickAbleTemplate.LoadResource();
|
||||||
pickAbleTemplate.Owner = this;
|
pickAbleTemplate.Owner = this;
|
||||||
pickAbleTemplate.Picked = true;
|
pickAbleTemplate.Picked = true;
|
||||||
pickAbleTemplate.Freeze = true;
|
pickAbleTemplate.Freeze = true;
|
||||||
|
@ -797,7 +797,7 @@ public partial class CharacterTemplate : CharacterBody2D
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pickAbleTemplate.LoadingResource();
|
pickAbleTemplate.LoadResource();
|
||||||
pickAbleTemplate.Owner = this;
|
pickAbleTemplate.Owner = this;
|
||||||
pickAbleTemplate.Picked = false;
|
pickAbleTemplate.Picked = false;
|
||||||
//Setting an initial speed of 0 for items here prevents the problem of throwing items too fast.
|
//Setting an initial speed of 0 for items here prevents the problem of throwing items too fast.
|
||||||
|
|
|
@ -49,9 +49,9 @@ public partial class Packsack : PickAbleTemplate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public override void _Ready()
|
public override void LoadResource()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base.LoadResource();
|
||||||
if (SelfItemContainer == null)
|
if (SelfItemContainer == null)
|
||||||
{
|
{
|
||||||
var universalItemContainer = new UniversalItemContainer(NumberSlots);
|
var universalItemContainer = new UniversalItemContainer(NumberSlots);
|
||||||
|
|
|
@ -18,9 +18,9 @@ public partial class ResignationCertificate : WeaponTemplate
|
||||||
Type = Config.DamageType.Magic
|
Type = Config.DamageType.Magic
|
||||||
};
|
};
|
||||||
|
|
||||||
public override void _Ready()
|
public override void LoadResource()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base.LoadResource();
|
||||||
_damage.CreateDamage();
|
_damage.CreateDamage();
|
||||||
_damage.Attacker = this;
|
_damage.Attacker = this;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using ColdMint.scripts.camp;
|
|
||||||
using ColdMint.scripts.character;
|
|
||||||
using ColdMint.scripts.damage;
|
|
||||||
using ColdMint.scripts.debug;
|
|
||||||
using ColdMint.scripts.inventory;
|
using ColdMint.scripts.inventory;
|
||||||
using ColdMint.scripts.utils;
|
using ColdMint.scripts.utils;
|
||||||
using Godot;
|
using Godot;
|
||||||
|
@ -172,20 +168,20 @@ public partial class PickAbleTemplate : RigidBody2D, IItem
|
||||||
}
|
}
|
||||||
|
|
||||||
private CollisionShape2D? _collisionShape2D;
|
private CollisionShape2D? _collisionShape2D;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// <para>Whether the resource has been loaded</para>
|
/// <para>Whether the resource has been loaded</para>
|
||||||
/// <para>是否已加载过资源了</para>
|
/// <para>是否已加载过资源了</para>
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool _loadedResource;
|
private bool _loadedResource;
|
||||||
|
|
||||||
public override void _Ready()
|
public sealed override void _Ready()
|
||||||
{
|
{
|
||||||
LoadingResource();
|
LoadResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void LoadingResource()
|
public virtual void LoadResource()
|
||||||
{
|
{
|
||||||
if (_loadedResource)
|
if (_loadedResource)
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,11 +19,6 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell
|
||||||
private string? _projectilePath;
|
private string? _projectilePath;
|
||||||
|
|
||||||
private PackedScene? _projectileScene;
|
private PackedScene? _projectileScene;
|
||||||
public sealed override void _Ready()
|
|
||||||
{
|
|
||||||
base._Ready();
|
|
||||||
LoadResource();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override int ItemType
|
public override int ItemType
|
||||||
{
|
{
|
||||||
|
@ -35,14 +30,17 @@ public partial class SpellPickAble : PickAbleTemplate, ISpell
|
||||||
return _projectileScene;
|
return _projectileScene;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void LoadResource()
|
|
||||||
|
|
||||||
|
public override void LoadResource()
|
||||||
{
|
{
|
||||||
|
base.LoadResource();
|
||||||
if (_projectileScene == null && !string.IsNullOrEmpty(_projectilePath))
|
if (_projectileScene == null && !string.IsNullOrEmpty(_projectilePath))
|
||||||
{
|
{
|
||||||
_projectileScene = ResourceLoader.Load<PackedScene>(_projectilePath);
|
_projectileScene = ResourceLoader.Load<PackedScene>(_projectilePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon)
|
public virtual void ModifyWeapon(ProjectileWeapon projectileWeapon)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,10 +28,10 @@ public partial class MeleeWeapon : WeaponTemplate
|
||||||
private readonly List<CharacterTemplate> _characterTemplates =
|
private readonly List<CharacterTemplate> _characterTemplates =
|
||||||
[
|
[
|
||||||
];
|
];
|
||||||
public override void _Ready()
|
|
||||||
|
public override void LoadResource()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base.LoadResource();
|
||||||
LogCat.Log("ready", LogCat.LogLabel.MeleeWeapon);
|
|
||||||
_weaponDamageArea = GetNode<Area2D>("WeaponDamageArea");
|
_weaponDamageArea = GetNode<Area2D>("WeaponDamageArea");
|
||||||
_weaponDamageArea.InputPickable = false;
|
_weaponDamageArea.InputPickable = false;
|
||||||
_weaponDamageArea.SetCollisionMaskValue(Config.LayerNumber.Player, true);
|
_weaponDamageArea.SetCollisionMaskValue(Config.LayerNumber.Player, true);
|
||||||
|
@ -45,7 +45,6 @@ public partial class MeleeWeapon : WeaponTemplate
|
||||||
_damageTemplate.MaxDamage = _maxDamage;
|
_damageTemplate.MaxDamage = _maxDamage;
|
||||||
_damageTemplate.MinDamage = _minDamage;
|
_damageTemplate.MinDamage = _minDamage;
|
||||||
_damageTemplate.Type = Config.DamageType.Physical;
|
_damageTemplate.Type = Config.DamageType.Physical;
|
||||||
LogCat.Log("success", LogCat.LogLabel.MeleeWeapon);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AreaExited(Node2D node2D)
|
private void AreaExited(Node2D node2D)
|
||||||
|
|
|
@ -122,9 +122,9 @@ public partial class ProjectileWeapon : WeaponTemplate
|
||||||
get => Config.ItemType.ProjectileWeapon;
|
get => Config.ItemType.ProjectileWeapon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void LoadResource()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base.LoadResource();
|
||||||
_marker2D = GetNode<Marker2D>("Marker2D");
|
_marker2D = GetNode<Marker2D>("Marker2D");
|
||||||
if (SelfItemContainer == null)
|
if (SelfItemContainer == null)
|
||||||
{
|
{
|
||||||
|
@ -144,6 +144,8 @@ public partial class ProjectileWeapon : WeaponTemplate
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
//The spell is stored in memory and has not yet been loaded into the node tree. So we call the InvokeLoadResource method to initialize the resource.
|
||||||
|
//法术保存在内存中,尚未加载到节点树。所以我们调用InvokeLoadResource方法来初始化资源。
|
||||||
spell.LoadResource();
|
spell.LoadResource();
|
||||||
if (SelfItemContainer.CanAddItem(item))
|
if (SelfItemContainer.CanAddItem(item))
|
||||||
{
|
{
|
||||||
|
|
|
@ -19,10 +19,10 @@ public abstract partial class WeaponTemplate : PickAbleTemplate
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private AudioStreamPlayer2D? _audioStreamPlayer2D;
|
private AudioStreamPlayer2D? _audioStreamPlayer2D;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void LoadResource()
|
||||||
{
|
{
|
||||||
base._Ready();
|
base.LoadResource();
|
||||||
_audioStreamPlayer2D = GetNodeOrNull<AudioStreamPlayer2D>("Marker2D/AudioStreamPlayer2D");
|
_audioStreamPlayer2D = GetNode<AudioStreamPlayer2D>("Marker2D/AudioStreamPlayer2D");
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Use(Node2D? owner, Vector2 targetGlobalPosition)
|
public override bool Use(Node2D? owner, Vector2 targetGlobalPosition)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user