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