2021-04-26 01:12:22 +00:00
|
|
|
using GamecraftModdingAPI.Players;
|
2021-04-26 23:52:54 +00:00
|
|
|
using GamecraftModdingAPI.Utility;
|
|
|
|
|
|
|
|
using RobocraftX.Physics;
|
2021-04-26 01:12:22 +00:00
|
|
|
using Svelto.ECS.EntityStructs;
|
2021-04-26 23:52:54 +00:00
|
|
|
using Techblox.FlyCam;
|
2021-04-26 01:12:22 +00:00
|
|
|
using Unity.Mathematics;
|
2021-04-26 23:52:54 +00:00
|
|
|
using UnityEngine;
|
2021-04-26 01:12:22 +00:00
|
|
|
|
|
|
|
namespace GamecraftModdingAPI
|
|
|
|
{
|
|
|
|
public class FlyCam
|
|
|
|
{
|
2021-04-26 23:52:54 +00:00
|
|
|
private static FlyCamEngine Engine = new FlyCamEngine();
|
2021-04-26 01:12:22 +00:00
|
|
|
|
|
|
|
public uint Id { get; }
|
|
|
|
|
|
|
|
public FlyCam(uint id) => Id = id;
|
|
|
|
|
2021-04-26 23:52:54 +00:00
|
|
|
/// <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
|
2021-04-26 01:12:22 +00:00
|
|
|
{
|
2021-04-26 23:52:54 +00:00
|
|
|
get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity;
|
|
|
|
set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity = value;
|
2021-04-26 01:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static void Init()
|
|
|
|
{
|
2021-04-26 23:52:54 +00:00
|
|
|
GameEngineManager.AddGameEngine(Engine);
|
2021-04-26 01:12:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|