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.

CameraEngine.cs 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using GamecraftModdingAPI.Engines;
  2. using GamecraftModdingAPI.Tasks;
  3. using RobocraftX.Character;
  4. using RobocraftX.Character.Movement;
  5. using Svelto.DataStructures;
  6. using Svelto.ECS;
  7. using Techblox.Camera;
  8. namespace NScript
  9. {
  10. class CameraEngine: IApiEngine
  11. {
  12. private Repeatable task;
  13. private bool isDisposed = false;
  14. public static bool useDefaultBehaviour = true;
  15. public void Ready()
  16. {
  17. task = new Repeatable(
  18. Tick,
  19. () => !(isDisposed && entitiesDB != null)
  20. );
  21. Scheduler.Schedule(task);
  22. }
  23. public EntitiesDB entitiesDB { get; set; }
  24. public void Dispose()
  25. {
  26. isDisposed = true;
  27. }
  28. public string Name { get; } = "NScriptModCameraEngine";
  29. public bool isRemovable { get; } = true;
  30. private void Tick()
  31. {
  32. if (useDefaultBehaviour) return;
  33. entitiesDB.QueryEntities<CharacterTagEntityStruct>(CharacterExclusiveGroups.OnFootGroup)
  34. .Deconstruct(out NB<CharacterTagEntityStruct> tags, out int count);
  35. for (int i = 0; i < count; i++)
  36. {
  37. if (entitiesDB.TryQueryEntitiesAndIndex(tags[i].ID.entityID, CameraExclusiveGroups.CameraGroup,
  38. out uint index, out NB<CharacterCameraEntityStruct> cams))
  39. {
  40. ref var ccses = ref entitiesDB.QueryEntity<CameraTargetEntityStruct>(tags[i].ID.entityID,
  41. CameraExclusiveGroups.CameraGroup);
  42. ccses.targetPosition.y += 1;
  43. cams[index].targetPosition.y += 1;
  44. cams[index].position.y += 1;
  45. cams[index].smoothedDistance = 0;
  46. }
  47. }
  48. entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup)
  49. .Deconstruct(out NB<CharacterCameraEntityStruct> cces, out int count2);
  50. for (int i = 0; i < count; i++)
  51. {
  52. cces[i].position.y += 1;
  53. cces[i].targetPosition.y += 1;
  54. }
  55. GamecraftModdingAPI.Utility.Logging.MetaLog($"Ticked on {count+count2} cameras ({count} C & {count2} VC)");
  56. }
  57. }
  58. }