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.

88 lines
2.3KB

  1. using RobocraftX.Common;
  2. using RobocraftX.Physics;
  3. using Svelto.ECS;
  4. using Unity.Mathematics;
  5. using Unity.Physics;
  6. using UnityEngine;
  7. namespace GamecraftModdingAPI
  8. {
  9. /// <summary>
  10. /// A rigid body (like a cluster of connected blocks) during simulation.
  11. /// </summary>
  12. public class SimBody
  13. {
  14. public EGID Id { get; }
  15. public SimBody(EGID id)
  16. {
  17. Id = id;
  18. }
  19. public SimBody(uint id) : this(new EGID(id, CommonExclusiveGroups.SIMULATION_BODIES_GROUP))
  20. {
  21. }
  22. public float3 Position
  23. {
  24. get => GetStruct().position;
  25. set => GetStruct().position = value;
  26. }
  27. public float3 Velocity
  28. {
  29. get => GetStruct().velocity;
  30. set => GetStruct().velocity = value;
  31. }
  32. public float3 AngularVelocity
  33. {
  34. get => GetStruct().angularVelocity;
  35. set => GetStruct().angularVelocity = value;
  36. }
  37. public float3 DeltaVelocity
  38. {
  39. get => GetStruct().deltaVelocity;
  40. set => GetStruct().deltaVelocity = value;
  41. }
  42. public float3 DeltaAngularVelocity
  43. {
  44. get => GetStruct().deltaAngularVelocity;
  45. set => GetStruct().deltaAngularVelocity = value;
  46. }
  47. public float3 Rotation
  48. {
  49. get => ((Quaternion) GetStruct().rotation).eulerAngles;
  50. set
  51. {
  52. ref var str = ref GetStruct();
  53. Quaternion quaternion = str.rotation;
  54. quaternion.eulerAngles = value;
  55. str.rotation = quaternion;
  56. }
  57. }
  58. public float Mass
  59. {
  60. get => math.rcp(GetStruct().physicsMass.InverseMass);
  61. set => GetStruct().physicsMass.InverseMass = math.rcp(value);
  62. }
  63. /// <summary>
  64. /// Whether the body can be moved or static
  65. /// </summary>
  66. public bool Static
  67. {
  68. get => Block.BlockEngine.GetBlockInfo<MassEntityStruct>(Id).isStatic;
  69. set => Block.BlockEngine.GetBlockInfo<MassEntityStruct>(Id).isStatic = value;
  70. }
  71. private ref RigidBodyEntityStruct GetStruct()
  72. {
  73. return ref Block.BlockEngine.GetBlockInfo<RigidBodyEntityStruct>(Id);
  74. }
  75. }
  76. }