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.

GameStateBuildEmitterEngine.cs 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 to build mode.
  11. /// </summary>
  12. public class GameStateBuildEmitterEngine : IEventEmitterEngine, IUnorderedInitializeOnTimeStoppedModeEntered
  13. {
  14. public string Name { get; } = "GamecraftModdingAPIGameStateBuildEventEmitter" ;
  15. public EntitiesDB entitiesDB { set; private get; }
  16. public int type { get; } = (int)EventType.BuildSwitchedTo;
  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 Build 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 EmitIfBuildMode()
  28. {
  29. //Logging.MetaDebugLog($"nextSimulationMode: {entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).nextSimulationMode}");
  30. if (entitiesDB.QueryUniqueEntity<SimulationModeStateEntityStruct>(SimulationModeStateExclusiveGroups.GAME_STATE_GROUP).nextSimulationMode == SimulationMode.TimeStopped)
  31. {
  32. Emit();
  33. }
  34. }
  35. public JobHandle OnInitializeTimeStoppedMode()
  36. {
  37. Emit();
  38. return default(JobHandle);
  39. }
  40. public void Ready() { }
  41. }
  42. }