|
- using GamecraftModdingAPI.Engines;
- using GamecraftModdingAPI.Tasks;
- using RobocraftX.Character;
- using RobocraftX.Character.Movement;
- using Svelto.DataStructures;
- using Svelto.ECS;
- using Techblox.Camera;
-
- namespace NScript
- {
- class CameraEngine: IApiEngine
- {
- private Repeatable task;
-
- private bool isDisposed = false;
-
- public static bool useDefaultBehaviour = true;
-
- public void Ready()
- {
- task = new Repeatable(
- Tick,
- () => !(isDisposed && entitiesDB != null)
- );
- Scheduler.Schedule(task);
- }
-
- public EntitiesDB entitiesDB { get; set; }
-
- public void Dispose()
- {
- isDisposed = true;
- }
-
- public string Name { get; } = "NScriptModCameraEngine";
- public bool isRemovable { get; } = true;
-
- private void Tick()
- {
- if (useDefaultBehaviour) return;
- entitiesDB.QueryEntities<CharacterTagEntityStruct>(CharacterExclusiveGroups.OnFootGroup)
- .Deconstruct(out NB<CharacterTagEntityStruct> tags, out int count);
- for (int i = 0; i < count; i++)
- {
- if (entitiesDB.TryQueryEntitiesAndIndex(tags[i].ID.entityID, CameraExclusiveGroups.CameraGroup,
- out uint index, out NB<CharacterCameraEntityStruct> cams))
- {
- ref var ccses = ref entitiesDB.QueryEntity<CameraTargetEntityStruct>(tags[i].ID.entityID,
- CameraExclusiveGroups.CameraGroup);
- ccses.targetPosition.y += 1;
- cams[index].targetPosition.y += 1;
- cams[index].position.y += 1;
- cams[index].smoothedDistance = 0;
- }
- }
- entitiesDB.QueryEntities<CharacterCameraEntityStruct>(CameraExclusiveGroups.VisualCameraGroup)
- .Deconstruct(out NB<CharacterCameraEntityStruct> cces, out int count2);
- for (int i = 0; i < count; i++)
- {
- cces[i].position.y += 1;
- cces[i].targetPosition.y += 1;
- }
- GamecraftModdingAPI.Utility.Logging.MetaLog($"Ticked on {count+count2} cameras ({count} C & {count2} VC)");
- }
- }
- }
|