|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using System.Reflection;
-
- using HarmonyLib;
- using RobocraftX.Common;
- using RobocraftX.UECS;
- using Svelto.ECS;
- using Unity.Entities;
-
- using GamecraftModdingAPI.Engines;
- using GamecraftModdingAPI.Utility;
-
- namespace GamecraftModdingAPI.Blocks
- {
- public class ScalingEngine : IApiEngine
- {
- private static IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> physicsEngine;
-
- public void Ready()
- {
- }
-
- public EntitiesDB entitiesDB { get; set; }
- public void Dispose()
- {
- }
-
- public string Name { get; } = "GamecraftModdingAPIScalingEngine";
- public bool isRemovable { get; } = false;
-
- private static EntityManager _entityManager; //Unity entity manager
-
- public void UpdateCollision(EGID egid)
- {
- //Assuming the block exists
- var entity = entitiesDB.QueryEntity<UECSPhysicsEntityStruct>(egid).uecsEntity;
- var pes = new UECSPhysicsEntityCreationStruct();
- physicsEngine.Add(ref pes, egid); //Create new UECS entity
- _entityManager.DestroyEntity(entity);
- }
-
- internal void Setup(EntityManager entityManager)
- {
- _entityManager = entityManager;
- }
-
- [HarmonyPatch]
- public class PhysicsEnginePatch
- {
- static void Postfix(IReactOnAddAndRemove<UECSPhysicsEntityCreationStruct> __instance)
- {
- physicsEngine = __instance;
- Logging.MetaDebugLog("Physics engine injected.");
- }
-
- static MethodBase TargetMethod(Harmony instance)
- {
- return AccessTools.Method("RobocraftX.StateSync.HandleUECSPhysicEntitiesWithPrefabCreationEngine" +
- ":Ready");
- }
- }
- }
- }
|