A stable modding interface between Techblox and mods https://mod.exmods.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

119 lines
4.0KB

  1. using GamecraftModdingAPI.Players;
  2. using GamecraftModdingAPI.Utility;
  3. using RobocraftX.Physics;
  4. using Svelto.ECS.EntityStructs;
  5. using Techblox.FlyCam;
  6. using Unity.Mathematics;
  7. using UnityEngine;
  8. namespace GamecraftModdingAPI
  9. {
  10. public class FlyCam
  11. {
  12. private static FlyCamEngine Engine = new FlyCamEngine();
  13. public uint Id { get; }
  14. public FlyCam(uint id) => Id = id;
  15. /// <summary>
  16. /// The local player's camera.
  17. /// </summary>
  18. public static FlyCam LocalCamera => new FlyCam(Player.LocalPlayer.Id);
  19. /// <summary>
  20. /// The current position of the camera.
  21. /// </summary>
  22. public float3 Position
  23. {
  24. get => Engine.GetComponent<PositionEntityStruct>(Id).Get().position;
  25. set
  26. {
  27. Engine.GetComponent<PositionEntityStruct>(Id).Get().position = value;
  28. Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().position = value;
  29. }
  30. }
  31. /// <summary>
  32. /// The current rotation of the camera.
  33. /// </summary>
  34. public float3 Rotation
  35. {
  36. get => ((Quaternion) Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation).eulerAngles;
  37. set
  38. {
  39. Engine.GetComponent<RotationEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
  40. Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().rotation = Quaternion.Euler(value);
  41. }
  42. }
  43. /// <summary>
  44. /// The current direction the camera is moving.
  45. /// </summary>
  46. public float3 MovementDirection
  47. {
  48. get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection;
  49. set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().movementDirection = value;
  50. }
  51. /// <summary>
  52. /// Whether the camera (player) is sprinting.
  53. /// </summary>
  54. public bool Sprinting
  55. {
  56. get => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting;
  57. set => Engine.GetComponent<FlyCamMovementComponent>(Id).Get().sprinting = value;
  58. }
  59. /// <summary>
  60. /// The speed setting of the camera.
  61. /// </summary>
  62. public float Speed
  63. {
  64. get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed;
  65. set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speed = value;
  66. }
  67. /// <summary>
  68. /// The multiplier setting to use when sprinting.
  69. /// </summary>
  70. public float SpeedSprintMultiplier
  71. {
  72. get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier;
  73. set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().speedSprintMultiplier = value;
  74. }
  75. /// <summary>
  76. /// The acceleration setting of the camera.
  77. /// </summary>
  78. public float Acceleration
  79. {
  80. get => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration;
  81. set => Engine.GetComponent<FlyCamMovementSettingsComponent>(Id).Get().acceleration = value;
  82. }
  83. /// <summary>
  84. /// The current velocity of the camera.
  85. /// </summary>
  86. public float3 Velocity
  87. {
  88. get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity;
  89. set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().velocity = value;
  90. }
  91. /// <summary>
  92. /// The current angular velocity of the camera.
  93. /// </summary>
  94. public float3 AngularVelocity
  95. {
  96. get => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity;
  97. set => Engine.GetComponent<RigidBodyEntityStruct>(Id).Get().angularVelocity = value;
  98. }
  99. public static void Init()
  100. {
  101. GameEngineManager.AddGameEngine(Engine);
  102. }
  103. }
  104. }