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.

GameStateSimulationEmitterEngine.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using Unity.Jobs;
  3. using RobocraftX.SimulationModeState;
  4. using RobocraftX.StateSync;
  5. using Svelto.ECS;
  6. using GamecraftModdingAPI.Utility;
  7. namespace GamecraftModdingAPI.Events
  8. {
  9. /// <summary>
  10. /// Event emitter engine for switching to simulation mode.
  11. /// </summary>
  12. public class GameStateSimulationEmitterEngine : IEventEmitterEngine, IUnorderedInitializeOnTimeRunningModeEntered
  13. {
  14. public string Name { get; } = "GamecraftModdingAPIGameStateSimulationEventEmitter" ;
  15. public EntitiesDB entitiesDB { set; private get; }
  16. public int type { get; } = (int)EventType.SimulationSwitchedTo;
  17. public bool isRemovable { get; } = false;
  18. public IEntityFactory Factory { set; private get; }
  19. public void Dispose() { }
  20. public void Emit()
  21. {
  22. Logging.Log("Dispatching Simulation Switched To event");
  23. if (Factory == null) { return; }
  24. Factory.BuildEntity<ModEventEntityDescriptor>(ApiExclusiveGroups.eventID++, ApiExclusiveGroups.eventsExclusiveGroup)
  25. .Init(new ModEventEntityStruct { type = type });
  26. }
  27. public void EmitIfSimMode()
  28. {
  29. if (entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).nextSimulationMode == SimulationMode.TimeRunning)
  30. {
  31. Emit();
  32. }
  33. }
  34. public JobHandle OnInitializeTimeRunningMode()
  35. {
  36. Emit();
  37. return default(JobHandle);
  38. }
  39. public void Ready() { }
  40. }
  41. }