Made selector 3D

This commit is contained in:
Marco 2025-08-07 15:09:02 +02:00
commit 0a7b1614a9
8 changed files with 113 additions and 45 deletions

View file

@ -48,12 +48,8 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
StateMachine = machine;
_selectorController.Hide();
if (Hud.Instance is not null)
{
Hud.Instance.CreateSelector(_selectorController);
}
SpawnSelector();
// if (SelectorScene is not null && _selector is null)
// {
@ -62,6 +58,43 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
// }
}
private void SpawnSelector()
{
var sel = SelectorScene.Instantiate<Node3D>();
StateMachine.MainObject.GetParent().AddChild(sel);
sel.GlobalPosition = StateMachine.MainObject.GlobalPosition;
_selectorController.ShowSelector += () =>
{
sel.Show();
};
_selectorController.HideSelector += () =>
{
sel.Reparent(this);
sel.Hide();
};
_selectorController.ChangeParent3D += parent =>
{
if (parent is not null)
{
sel.Reparent(parent);
}
else
{
sel.Reparent(this);
sel.Hide();
}
sel.Position = Vector3.Zero;
};
// if (Hud.Instance is not null)
// {
// Hud.Instance.CreateSelector(_selectorController);
// }
}
public void Process(double delta)
{
@ -69,7 +102,7 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
public void PhysicsProcess(double delta)
{
_selectorController.PhysicsProcess(delta);
//_selectorController.PhysicsProcess(delta);
HandleInteraction();
}
@ -110,6 +143,7 @@ public partial class IsoActivationProvider: Area3D, IModule<PlayerState, Charact
if (success)
{
// Deselect and scan for next
_selectorController.RemoveInteractable(selected);
_selectorController.SelectNext();
//_selector.RemoveInteractable(selected);
}

View file

@ -10,6 +10,8 @@ public partial class SelectorController : Node
[Signal] public delegate void HideSelectorEventHandler();
[Signal] public delegate void ChangePositionEventHandler(Vector2 position);
[Signal] public delegate void ChangeParent3DEventHandler(Node3D node);
private Interactable _lastInteractable;
private List<IInteractable> _interactables = [];
@ -100,10 +102,7 @@ public partial class SelectorController : Node
public void RemoveInteractable(IInteractable interactable)
{
if (_interactables.Contains(interactable))
{
_interactables.Remove(interactable);
}
_interactables.Remove(interactable);
UpdatePosition();
}
@ -119,6 +118,8 @@ public partial class SelectorController : Node
if (SelectedInteractable != null)
{
EmitSignalChangePosition(SelectedInteractable.GetScreenPosition());
//EmitSignalChangePosition3D();
EmitSignalChangeParent3D(SelectedInteractable as Node3D);
EmitSignalShowSelector();
}
else
@ -137,9 +138,9 @@ public partial class SelectorController : Node
EmitSignalHideSelector();
}
public void PhysicsProcess(double delta)
{
if (SelectedInteractable is null) return;
EmitSignalChangePosition(SelectedInteractable.GetScreenPosition());
}
// public void PhysicsProcess(double delta)
// {
// if (SelectedInteractable is null) return;
// //EmitSignalChangePosition(SelectedInteractable.GetScreenPosition());
// }
}