TechbloxModdingAPI/GamecraftModdingAPI/FlyCam.cs
Norbi Peti 6e03847ab0
FlyCam additions, improve struct
Added property to get the camera from the player
Removed pointer magic
2021-04-27 01:52:54 +02:00

119 lines
4 KiB
C#

using GamecraftModdingAPI.Players;
using GamecraftModdingAPI.Utility;
using RobocraftX.Physics;
using Svelto.ECS.EntityStructs;
using Techblox.FlyCam;
using Unity.Mathematics;
using UnityEngine;
namespace GamecraftModdingAPI
{
public class FlyCam
{
private static FlyCamEngine Engine = new FlyCamEngine();
public uint Id { get; }
public FlyCam(uint id) => Id = id;
/// <summary>
/// The local player's camera.
/// </summary>
public static FlyCam LocalCamera => new FlyCam(Player.LocalPlayer.Id);
/// <summary>
/// The current position of the camera.
/// </summary>
public float3 Position
{
get => Engine.GetComponent<PositionEntityStruct>(Id).Get().position;
set
{
Engine.GetComponent<PositionEntityStruct>(Id).Get().position = value;
Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().position = value;
}
}
/// <summary>
/// The current rotation of the camera.
/// </summary>
public float3 Rotation
{
get => ((Quaternion) Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation).eulerAngles;
set
{
Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
}
}
/// <summary>
/// The current direction the camera is moving.
/// </summary>
public float3 MovementDirection
{
get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection;
set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection = value;
}
/// <summary>
/// Whether the camera (player) is sprinting.
/// </summary>
public bool Sprinting
{
get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting;
set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting = value;
}
/// <summary>
/// The speed setting of the camera.
/// </summary>
public float Speed
{
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed = value;
}
/// <summary>
/// The multiplier setting to use when sprinting.
/// </summary>
public float SpeedSprintMultiplier
{
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier = value;
}
/// <summary>
/// The acceleration setting of the camera.
/// </summary>
public float Acceleration
{
get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration;
set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration = value;
}
/// <summary>
/// The current velocity of the camera.
/// </summary>
public float3 Velocity
{
get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity;
set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity = value;
}
/// <summary>
/// The current angular velocity of the camera.
/// </summary>
public float3 AngularVelocity
{
get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity;
set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity = value;
}
public static void Init()
{
GameEngineManager.AddGameEngine(Engine);
}
}
}