Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using TripleG.ClientAndServer;
  2. using Unity.Entities;
  3. using Unity.Jobs;
  4. using Unity.NetCode;
  5. using UnityEngine;
  6.  
  7. namespace TripleG.Client
  8. {
  9.     [UpdateInWorld(UpdateInWorld.TargetWorld.Client)]
  10.     [UpdateInGroup(typeof(GhostPredictionSystemGroup))]
  11.     [UpdateAfter(typeof(ResetControllablesCommandsSystem))]
  12.     [UpdateBefore(typeof(CharacterMovementSystem))]
  13.     [UpdateBefore(typeof(SpaceShipMovementSystem))]
  14.     public class SetControllablesCommandsSystem : JobComponentSystem
  15.     {
  16.         private GhostPredictionSystemGroup m_predictionGroup;
  17.         protected override void OnCreate()
  18.         {
  19.             base.OnCreate();
  20.             m_predictionGroup = World.GetOrCreateSystem<GhostPredictionSystemGroup>();
  21.         }
  22.        
  23.         protected override JobHandle OnUpdate(JobHandle inputDeps)
  24.         {
  25.             var controllableDataFromEntity = GetComponentDataFromEntity<ControllableData>(false);
  26.  
  27.             var inputEntity = GetSingletonEntity<LocalInputData>();
  28.             var clientCommandBufferFromEntity = GetBufferFromEntity<ClientCommand>();
  29.  
  30.             var tick = m_predictionGroup.PredictingTick;
  31.            
  32.             // Here we only care of our own, so we can either go over input, or local client
  33.             inputDeps = Entities.WithNativeDisableParallelForRestriction(controllableDataFromEntity).WithNativeDisableParallelForRestriction(clientCommandBufferFromEntity).WithAll<LocalClientTag>().ForEach((ControllingData controllingData) =>
  34.             {
  35.                 if (controllingData.controlledEntity != Entity.Null)
  36.                 {
  37.                     var clientCommandBuffer = clientCommandBufferFromEntity[inputEntity];
  38.                    
  39.                     // Get controlledData
  40.                     if(clientCommandBuffer.GetDataAtTick(tick, out ClientCommand commandData))
  41.                     {
  42.                         var data = controllableDataFromEntity[controllingData.controlledEntity];
  43.                         data.currentCommand = commandData;
  44.                         controllableDataFromEntity[controllingData.controlledEntity] = data;
  45.                     }
  46.                 }
  47.             }).Schedule(inputDeps);
  48.            
  49.             return inputDeps;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement