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.

132 lines
4.5KB

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