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.

ScalingEngine.cs 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using System.Reflection;
  2. using HarmonyLib;
  3. using RobocraftX.Common;
  4. using RobocraftX.UECS;
  5. using Svelto.ECS;
  6. using Unity.Entities;
  7. using GamecraftModdingAPI.Engines;
  8. using GamecraftModdingAPI.Utility;
  9. namespace GamecraftModdingAPI.Blocks
  10. {
  11. public class ScalingEngine : IApiEngine
  12. {
  13. private static IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> physicsEngine;
  14. public void Ready()
  15. {
  16. }
  17. public EntitiesDB entitiesDB { get; set; }
  18. public void Dispose()
  19. {
  20. }
  21. public string Name { get; } = "GamecraftModdingAPIScalingEngine";
  22. public bool isRemovable { get; } = false;
  23. private EntityManager _entityManager; //Unity entity manager
  24. public void UpdateCollision(EGID egid)
  25. {
  26. if (_entityManager == default)
  27. _entityManager = FullGameFields._physicsWorld.EntityManager;
  28. //Assuming the block exists
  29. var entity = entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(egid).uecsEntity;
  30. var pes = new UECSPhysicsEntityCreationStruct();
  31. physicsEngine.Add(ref pes, egid); //Create new UECS entity
  32. _entityManager.DestroyEntity(entity);
  33. }
  34. [HarmonyPatch]
  35. public class PhysicsEnginePatch
  36. {
  37. static void Postfix(IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> __instance)
  38. {
  39. physicsEngine = __instance;
  40. Logging.MetaDebugLog("Physics engine injected.");
  41. }
  42. static MethodBase TargetMethod(Harmony instance)
  43. {
  44. return AccessTools.Method("RobocraftX.StateSync.HandleUECSPhysicEntitiesWithPrefabCreationEngine" +
  45. ":Ready");
  46. }
  47. }
  48. }
  49. }