mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 09:55:35 +00:00
69 lines
No EOL
1.5 KiB
C#
69 lines
No EOL
1.5 KiB
C#
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;
|
|
}
|
|
} |