using System.Collections.Generic;
using System.Linq;
using Godot;
namespace BITKit;
///
/// 摄像头服务,该服务需要加载到Camera3D节点中
///
public partial class CameraService:Camera3D
{
public static CameraService Singleton { get; private set; }
///
/// 场景中所有的摄像头
///
private static readonly List _cameras=new();
///
/// 当前已激活的摄像头
///
public static IVirtualCamera ActiveCamera { get; private set; }
///
/// 注册摄像头
///
/// 摄像头
///
public static bool Register(IVirtualCamera camera) => _cameras.TryAdd(camera);
///
/// 注销摄像头
///
/// 摄像头
///
public static bool UnRegister(IVirtualCamera camera) => _cameras.TryRemove(camera);
public override void _Ready()
{
Singleton = this;
}
///
/// 处理摄像头的位置
///
///
public override void _Process(double delta)
{
//获取所有已启用的相机并加载一个虚拟相机的数据
foreach (var x in _cameras.Where(x => x.IsEnabled))
{
//应用相机坐标
Position = x.Position;
//应用相机角度
Rotation = x.Rotation;
//已加载相机位置,退出循环
break;
}
}
}