mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-11 01:25:54 +00:00
Enemy spawning
This commit is contained in:
parent
ede8f2028a
commit
29dc9bebe0
20 changed files with 564 additions and 105 deletions
69
Scripts/Actors/EnemyMarker3D.cs
Normal file
69
Scripts/Actors/EnemyMarker3D.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using Cirno.Scripts.Components.FSM.Enemy._3D;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
using Godot;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
[Tool]
|
||||
public partial class EnemyMarker3D : PreviewMarker3D
|
||||
{
|
||||
private EnemyResource _enemy;
|
||||
|
||||
[Export]
|
||||
public EnemyResource Enemy
|
||||
{
|
||||
get => _enemy;
|
||||
set
|
||||
{
|
||||
_enemy = value;
|
||||
if (Engine.IsEditorHint())
|
||||
{
|
||||
//QueueRedraw();
|
||||
this.Texture = _enemy.IconSprite;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Export] public bool AutoSpawn { get; set; } = false;
|
||||
|
||||
private EnemyProxy3D _spawnedEnemy;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
base._Ready();
|
||||
|
||||
if (AutoSpawn)
|
||||
{
|
||||
Spawn(false);
|
||||
}
|
||||
}
|
||||
|
||||
public EnemyProxy3D Spawn(bool deleteMarker)
|
||||
{
|
||||
if (Engine.IsEditorHint()) return null ;
|
||||
if (Enemy is null) return null;
|
||||
if (_spawnedEnemy is not null) return _spawnedEnemy;
|
||||
|
||||
if (deleteMarker)
|
||||
{
|
||||
this.QueueFree();
|
||||
}
|
||||
|
||||
var enemyScene = GD.Load<PackedScene>(Enemy.PrefabPath);
|
||||
|
||||
_spawnedEnemy = this.CreateSibling<EnemyProxy3D>(enemyScene);
|
||||
_spawnedEnemy.Init(Enemy);
|
||||
//Spawned = true;
|
||||
|
||||
_spawnedEnemy.Death += SpawnedEnemyOnDeath;
|
||||
return _spawnedEnemy;
|
||||
}
|
||||
|
||||
private void SpawnedEnemyOnDeath(EnemyProxy3D enemy)
|
||||
{
|
||||
_spawnedEnemy.Death -= SpawnedEnemyOnDeath;
|
||||
_spawnedEnemy = null;
|
||||
//Spawned = false;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue