mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
70 lines
No EOL
1.7 KiB
C#
70 lines
No EOL
1.7 KiB
C#
using Cirno.Scripts.Components.FSM;
|
|
using Cirno.Scripts.Components.FSM._3DPlayer;
|
|
using Cirno.Scripts.Components.FSM.Player;
|
|
using Cirno.Scripts.Utils;
|
|
using Godot;
|
|
|
|
namespace Cirno.Scripts.Components.Actors._3D;
|
|
|
|
public partial class PlayerCrosshairModule3D : ModuleBase<PlayerState, CharacterBody3D>
|
|
{
|
|
[Export] public IsoPlayerStorageModule Storage { get; set; }
|
|
[Export]
|
|
public AnimatedSprite3D AnimatedSprite { get; private set; }
|
|
|
|
[Export]
|
|
public float CrosshairDistance { get; private set; }
|
|
|
|
public bool Enabled { get; set; } = false;
|
|
|
|
private IStateMachine<PlayerState, CharacterBody3D> _machine;
|
|
|
|
public void UpdatePosition(Vector2 facingDirection)
|
|
{
|
|
AnimatedSprite.Position = CalculateCrosshairPosition(facingDirection);
|
|
}
|
|
|
|
private Vector3 CalculateCrosshairPosition(Vector2 facingDirection)
|
|
{
|
|
var pos2d = facingDirection * CrosshairDistance;
|
|
|
|
var pos3d = pos2d.ToVector3(0);
|
|
|
|
return pos3d;
|
|
}
|
|
|
|
public override void EnterState(PlayerState state)
|
|
{
|
|
Enabled = true;
|
|
AnimatedSprite.Show();
|
|
}
|
|
|
|
public override void ExitState(PlayerState state)
|
|
{
|
|
Enabled = false;
|
|
AnimatedSprite.Hide();
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
AnimatedSprite.Hide();
|
|
}
|
|
|
|
public override void Init(IStateMachine<PlayerState, CharacterBody3D> machine)
|
|
{
|
|
_machine = machine;
|
|
AnimatedSprite.Hide();
|
|
}
|
|
|
|
public override void Process(double delta)
|
|
{
|
|
if (!Enabled) return;
|
|
|
|
}
|
|
|
|
public override void PhysicsProcess(double delta)
|
|
{
|
|
if (!Enabled) return;
|
|
AnimatedSprite.Position = CalculateCrosshairPosition(Storage.FacingDirection);
|
|
}
|
|
} |