Changed camera no not need a direct reference to vesna
This commit is contained in:
@@ -5,26 +5,8 @@ namespace Babushka.scripts.CSharp.Common.Camera;
|
||||
|
||||
public partial class CameraController : Camera2D
|
||||
{
|
||||
#region Singleton ( Contains _EnterTree() ) // TODO: use autoload or other solution
|
||||
|
||||
public static CameraController Instance { get; private set; } = null!;
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
[Export] private Node2D _followNode;
|
||||
|
||||
public FightHappening? fightToShow;
|
||||
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
this.GlobalPosition = /*fightToShow?.camPositionNode.GlobalPosition ??*/ _followNode.GlobalPosition;
|
||||
|
||||
GlobalPosition = CameraTarget.GetActiveTarget().GlobalPosition;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Godot;
|
||||
|
||||
namespace Babushka.scripts.CSharp.Common.Camera;
|
||||
|
||||
public partial class CameraTarget : Node2D
|
||||
{
|
||||
private static readonly List<CameraTarget> AllTargets = new();
|
||||
|
||||
public static CameraTarget GetActiveTarget() // Called every frame. Maybe needs performance optimization in the future
|
||||
{
|
||||
return AllTargets
|
||||
.OrderByDescending(t => t.Priority)
|
||||
.First();
|
||||
}
|
||||
|
||||
[Export] public float Priority { get; set; }
|
||||
|
||||
public override void _EnterTree()
|
||||
{
|
||||
AllTargets.Add(this);
|
||||
}
|
||||
|
||||
public override void _ExitTree()
|
||||
{
|
||||
AllTargets.Remove(this);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
uid://ccdhx1lt4n271
|
||||
Reference in New Issue
Block a user