mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
113 lines
No EOL
2.5 KiB
C#
113 lines
No EOL
2.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, IActivable
|
|
{
|
|
private readonly Vector3 _boxSize = new Vector3(0.5f, 0.8f, 0.5f);
|
|
|
|
private EnemyResource _enemy;
|
|
|
|
[Export]
|
|
public EnemyResource Enemy
|
|
{
|
|
get => _enemy;
|
|
set
|
|
{
|
|
_enemy = value;
|
|
if (Engine.IsEditorHint())
|
|
{
|
|
//QueueRedraw();
|
|
this.Texture = _enemy.IconSprite;
|
|
}
|
|
}
|
|
}
|
|
|
|
private bool _autoSpawn = false;
|
|
|
|
[Export]
|
|
public bool AutoSpawn
|
|
{
|
|
get => _autoSpawn;
|
|
set
|
|
{
|
|
_autoSpawn = value;
|
|
if (Engine.IsEditorHint())
|
|
{
|
|
if (_autoSpawn)
|
|
{
|
|
SetSpriteAlpha(1);
|
|
}
|
|
else
|
|
{
|
|
SetSpriteAlpha(0.5f);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
|
{
|
|
if (Engine.IsEditorHint()) return false;
|
|
Spawn(false);
|
|
return _spawnedEnemy is not null;
|
|
}
|
|
|
|
public void Toggle()
|
|
{
|
|
Activate();
|
|
}
|
|
|
|
public override void _Process(double delta)
|
|
{
|
|
if (!Engine.IsEditorHint()) return;
|
|
#if !DISABLE_DD3D
|
|
DebugDraw3D.DrawBox(this.GlobalPosition - _boxSize / 2, Quaternion.Identity, _boxSize, Colors.Red);
|
|
#endif
|
|
//DebugDraw3D.DrawSphere(this.GlobalPosition, 0.1f, Colors.Green);
|
|
}
|
|
} |