public void Execute(CollisionEvent collisionEvent)
        {
            if (dealDamageGroup.HasComponent(collisionEvent.Entities.EntityA))
            {
                if (damageGroup.Exists(collisionEvent.Entities.EntityB))
                {
                    damageGroup[collisionEvent.Entities.EntityB].Add(new Damage
                    {
                        Value = dealDamageGroup[collisionEvent.Entities.EntityA].Value
                    });
                    if (fmodGroup.Exists(collisionEvent.Entities.EntityB) && translationGroup.Exists(collisionEvent.Entities.EntityB))
                    {
                        SoundManager.GetInstance().PlayOneShotSound(fmodGroup[collisionEvent.Entities.EntityB].DiePath.ToString(), translationGroup[collisionEvent.Entities.EntityB].Value);
                    }
                }
            }

            if (dealDamageGroup.HasComponent(collisionEvent.Entities.EntityB))
            {
                if (damageGroup.Exists(collisionEvent.Entities.EntityA))
                {
                    damageGroup[collisionEvent.Entities.EntityA].Add(new Damage
                    {
                        Value = dealDamageGroup[collisionEvent.Entities.EntityB].Value
                    });
                    if (fmodGroup.Exists(collisionEvent.Entities.EntityA) && translationGroup.Exists(collisionEvent.Entities.EntityA))
                    {
                        SoundManager.GetInstance().PlayOneShotSound(fmodGroup[collisionEvent.Entities.EntityA].DiePath.ToString(), translationGroup[collisionEvent.Entities.EntityA].Value);
                    }
                }
            }
        }
            public void Execute(TriggerEvent triggerEvent)
            {
                if (dealDamageGroup.HasComponent(triggerEvent.Entities.EntityA))
                {
                    if (damageGroup.Exists(triggerEvent.Entities.EntityB))
                    {
                        DealDamage dealDamage = dealDamageGroup[triggerEvent.Entities.EntityA];

                        damageGroup[triggerEvent.Entities.EntityB].Add(new Damage
                        {
                            DamageTypeId = dealDamage.DamageTypeId,
                            Value        = dealDamage.Value
                        });
                    }
                }

                if (dealDamageGroup.HasComponent(triggerEvent.Entities.EntityB))
                {
                    if (damageGroup.Exists(triggerEvent.Entities.EntityA))
                    {
                        DealDamage dealDamage = dealDamageGroup[triggerEvent.Entities.EntityB];

                        damageGroup[triggerEvent.Entities.EntityA].Add(new Damage
                        {
                            DamageTypeId = dealDamage.DamageTypeId,
                            Value        = dealDamage.Value
                        });
                    }
                }
            }
        private void MakeDamage(Entity bomb, Entity enemy)
        {
            var explosionComponent = explosionGroup[bomb];

            if (explosionComponent.explode)
            {
                if (damageGroup.Exists(enemy) &&
                    enemiesGroup.Exists(enemy))
                {
                    var damage = (int)(explosionComponent.damage *
                                       (1 - min(1,
                                                (distance(translationGroup[bomb].Value, translationGroup[enemy].Value) -
                                                 2) / 6)));
                    damageGroup[enemy].Add(new Damage
                    {
                        Value = damage
                    });
                }
            }
            else
            {
                if (damageGroup.Exists(enemy) &&
                    enemiesGroup.Exists(enemy))
                {
                    if (distance(translationGroup[bomb].Value,
                                 translationGroup[enemy].Value) < 2f)
                    {
                        explosionComponent.timer = explosionComponent.ttl;
                        explosionGroup[bomb]     = explosionComponent;
                    }
                }
            }
        }
            public void Execute(TriggerEvent triggerEvent)
            {
                Entity entityA = triggerEvent.Entities.EntityA;
                Entity entityB = triggerEvent.Entities.EntityB;

                //The wind will never affect itself
                if (entityA != entityB)
                {
                    bool isAWindController      = WindControllerGroup.Exists(entityA);
                    bool isBWindController      = WindControllerGroup.Exists(entityB);
                    bool isAVelocityCurveBuffer = VelocityCurveBufferGroup.Exists(entityA);
                    bool isBVelocityCurveBuffer = VelocityCurveBufferGroup.Exists(entityB);

                    //Entity A is a WindController and
                    //Entity B is a VelocityCurveBuffer
                    if (isAWindController && isBVelocityCurveBuffer)
                    {
                        ApplyWind(entityA,
                                  entityB);
                    }

                    //Entity B is a WindController and
                    //Entity A is a VelocityCurveBuffer
                    if (isBWindController && isAVelocityCurveBuffer)
                    {
                        ApplyWind(entityB,
                                  entityA);
                    }
                }
            }
Esempio n. 5
0
            /// <summary>
            /// This will be called after input has been sampled and applied to this job data structure;
            /// more specifically, at the ScheduleSingle() call down at the bottom of OnUpdate()
            /// </summary>
            public void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent state)
            {
                // If this CTC doesn't have an entity, that means it is a connected client with no
                // existing ship entity. So, we spawn one!
                if (state.targetEntity == Entity.Null)
                {
                    // Spawn the player once they press the spacebar (i.e. the shoot button)
                    if (shoot != 0)
                    {
                        // Create an empty entity for the player...
                        var req = commandBuffer.CreateEntity(index);
                        // PlayerSpawnRequest is processed in SpawnSystem.cs, which is server-side.
                        commandBuffer.AddComponent <PlayerSpawnRequest>(index, req);
                        // Attach a component that can take RPC commands intended for this entity (this player)
                        commandBuffer.AddComponent(index, req, new SendRpcCommandRequestComponent {
                            TargetConnection = entity
                        });
                    }
                }

                // This CTC does have a ship entity, so we want to send command data for it
                else
                {
                    // If ship present, store commands in network command buffer
                    // Honestly no clue what "Exists()" means. At all. Documentation is all
                    // auto-generated, there's no comments about this.
                    if (inputFromEntity.Exists(state.targetEntity))
                    {
                        var input = inputFromEntity[state.targetEntity];
                        input.AddCommandData(new ShipCommandData {
                            tick = inputTargetTick, left = left, right = right, thrust = thrust, shoot = shoot
                        });
                    }
                }
            }
Esempio n. 6
0
            public void Execute(Entity laserEntity, int index,
                                [ReadOnly, ChangedFilter] DynamicBuffer <PhysicsRaycastResults> raycastResults,
                                [ReadOnly] ref Laser laser, [ReadOnly] ref ActorAttribute3Offset <_HP> hpOffset, [ReadOnly] ref Translation laserTranslation,
                                [ReadOnly] ref ActorOwner actorOwner, [ReadOnly] ref Actor actor)
            {
                for (var i = 0; i < raycastResults.Length; ++i)
                {
                    var raycastResult = raycastResults[i];

                    var distance = math.distance(laserTranslation.Value, raycastResult.point);
                    var percent  = 1f - distance / laser.distance;
                    var hp       = hpOffset.GetValue(percent);


                    var targetEntity = raycastResult.entity;

                    if (hpModifyFromEntity.Exists(targetEntity))
                    {
                        hpModifyFromEntity[targetEntity].Add(new ActorAttribute3Modifys <_HP>
                        {
                            player = actorOwner.playerEntity,
                            type   = actor.actorType,
                            value  = hp,
                            attribute3ModifyType = Attribute3SubModifyType.ValueOffset
                        });
                    }

                    //
                    var translation = new Translation {
                        Value = raycastResult.point
                    };
                    AttributeModifyFxSpawner.createInServer(endCommandBuffer, index, actor.actorType, translation, hp, 0f, default);
                }
            }
Esempio n. 7
0
            public void Execute(Entity entity, int index, [ReadOnly] ref SendRpcCommandRequestComponent dest,
                                [ReadOnly] ref TActionRequest action)
            {
                commandBuffer.DestroyEntity(index, entity);
                if (connections.Length > 0)
                {
                    if (dest.TargetConnection != Entity.Null)
                    {
                        if (!rpcFromEntity.Exists(dest.TargetConnection))
                        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                            throw new InvalidOperationException("Cannot send RPC with no remote connection.");
#else
                            return;
#endif
                        }
                        var buffer = rpcFromEntity[dest.TargetConnection];
                        rpcQueue.Schedule(buffer, action);
                    }
                    else
                    {
                        for (var i = 0; i < connections.Length; ++i)
                        {
                            var buffer = rpcFromEntity[connections[i]];
                            rpcQueue.Schedule(buffer, action);
                        }
                    }
                }
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                else
                {
                    throw new InvalidOperationException("Cannot send RPC with no remote connection.");
                }
#endif
            }
            public void Execute(Entity entity, int index,
                                [ReadOnly, ChangedFilter] DynamicBuffer <PhysicsTriggerResults> physicsTriggerResults,
                                [ReadOnly] ref ActorAttribute3Offset <_HP> hpOffset,
                                [ReadOnly] ref ActorOwner actorOwner, [ReadOnly] ref Actor actor)
            {
                for (var i = 0; i < physicsTriggerResults.Length; ++i)
                {
                    var targetEntity = physicsTriggerResults[i].entity;

                    var hp = hpOffset.GetValue(random.NextFloat(0f, 1f));

                    if (hpModifyFromEntity.Exists(targetEntity))
                    {
                        hpModifyFromEntity[targetEntity].Add(new ActorAttribute3Modifys <_HP>
                        {
                            player = actorOwner.playerEntity,
                            type   = actor.actorType,
                            value  = hp,
                            attribute3ModifyType = Attribute3SubModifyType.ValueOffset
                        });
                    }

                    //
                    var translation = translationFromEntity[targetEntity];
                    AttributeModifyFxSpawner.createInServer(endCommandBuffer, index, actor.actorType, translation, hp, 0f, default);
                }
            }
            void ChildLocalToWorld(float4x4 parentLocalToWorld, Entity entity, bool updateChildrenTransform)
            {
                bool transformChanged = LocalToParentFromEntity.DidChange(entity, LastSystemVersion);

                updateChildrenTransform = updateChildrenTransform || transformChanged;

                float4x4 localToWorldMatrix;

                if (updateChildrenTransform && LocalToWorldWriteGroupMask.Matches(entity))
                {
                    var localToParent = LocalToParentFromEntity[entity];
                    localToWorldMatrix             = math.mul(parentLocalToWorld, localToParent.Value);
                    LocalToWorldFromEntity[entity] = new LocalToWorld {
                        Value = localToWorldMatrix
                    };
                }
                else //This entity has a component with the WriteGroup(LocalToWorld)
                {
                    localToWorldMatrix = LocalToWorldFromEntity[entity].Value;
                }

                if (ChildFromEntity.Exists(entity))
                {
                    var children = ChildFromEntity[entity];
                    for (int i = 0; i < children.Length; i++)
                    {
                        ChildLocalToWorld(localToWorldMatrix, children[i].Value, updateChildrenTransform);
                    }
                }
            }
Esempio n. 10
0
        public void UpdateTransformRecursive(ref WorldSpaceRect parentLocalToWorldSpaceRect, WorldSpaceMask currentMask, Entity entity, float2 scale)
        {
            if (DisabledFromEntity.Exists(entity))
            {
                return;
            }
            var childTransform    = RectTransformFromEntity[entity];
            var childLocalToWorld = RectTransformUtils.CalculateWorldSpaceRect(parentLocalToWorldSpaceRect, scale, childTransform);

            WorldSpaceRectFromEntity[entity] = childLocalToWorld;
            ElementScaleFromEntity[entity]   = new ElementScale()
            {
                Value = scale
            };
            UpdateRectMask(entity, childLocalToWorld, ref currentMask);
            WorldSpaceMaskFromEntity[entity] = currentMask;

            if (RebuildFlagFromEntity.Exists(entity))
            {
                RebuildFlagFromEntity[entity] = new RebuildElementMeshFlag()
                {
                    Rebuild = true
                }
            }
            ;
            if (ChildrenFromEntity.Exists(entity))
            {
                var children = ChildrenFromEntity[entity];
                for (int i = 0; i < children.Length; i++)
                {
                    UpdateTransformRecursive(ref childLocalToWorld, currentMask, children[i].Value, scale);
                }
            }
        }
Esempio n. 11
0
 public void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent state)
 {
     if (state.targetEntity == Entity.Null)
     {
         if (shoot != 0)
         {
             rpcQueue.Schedule(rpcBuffer[entity], new RpcSpawn());
         }
     }
     else
     {
         // If ship, store commands in network command buffer
         // FIXME: when destroying the ship is in a command buffer this no longer works
         if (shipState.Exists(state.targetEntity)) // There might be a pending set to null
         {
             shipState[state.targetEntity] = new ShipStateComponentData(thrust, true);
         }
         if (inputFromEntity.Exists(state.targetEntity))
         {
             var input = inputFromEntity[state.targetEntity];
             input.AddCommandData(new ShipCommandData {
                 tick = inputTargetTick, left = left, right = right, thrust = thrust, shoot = shoot
             });
         }
     }
 }
Esempio n. 12
0
        public void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent state)
        {
            if (shoot != 0)
            {
                var req = commandBuffer.CreateEntity(index);
                commandBuffer.AddComponent <FireBulletRequest>(index, req);
                commandBuffer.AddComponent(index, req, new SendRpcCommandRequestComponent {
                    TargetConnection = entity
                });
            }

            if (state.targetEntity == Entity.Null)
            {
            }
            else
            {
                // If ship, store commands in network command buffer
                if (inputFromEntity.Exists(state.targetEntity))
                {
                    Debug.Log("Does this get called");

                    var input = inputFromEntity[state.targetEntity];
                    input.AddCommandData(new TestCommandData {
                        tick = inputTargetTick, shoot = shoot
                    });
                }
            }
        }
Esempio n. 13
0
 public void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent state)
 {
     if (state.targetEntity == Entity.Null)
     {
         if (shoot != 0)
         {
             var req = commandBuffer.CreateEntity(index);
             commandBuffer.AddComponent <PlayerSpawnRequest>(index, req);
             commandBuffer.AddComponent(index, req, new SendRpcCommandRequestComponent {
                 TargetConnection = entity
             });
         }
     }
     else
     {
         // If ship, store commands in network command buffer
         if (inputFromEntity.Exists(state.targetEntity))
         {
             var input = inputFromEntity[state.targetEntity];
             input.AddCommandData(new ShipCommandData {
                 tick = inputTargetTick, left = left, right = right, thrust = thrust, shoot = shoot
             });
         }
     }
 }
Esempio n. 14
0
        public void Execute(TriggerEvent triggerEvent)
        {
            var entityA = triggerEvent.Entities.EntityA;
            var entityB = triggerEvent.Entities.EntityB;


            if (agentData.Exists(entityA) && agentData.Exists(entityB))
            {
                AgentData adA = agentData[entityA];
                AgentData adB = agentData[entityB];

                if (TriggerStayRefsFromEntity.Exists(entityA))
                {
                    TriggerStayRefsFromEntity[entityA].Add(new TriggerStayRef {
                        pos = adB.position, vel = adB.direction * adB.speed
                    });
                }
                //if (TriggerStayRefsFromEntity.Exists(entityB))
                //TriggerStayRefsFromEntity[entityB].Add(new TriggerStayRef { pos = adA.position, vel = adA.direction * adA.speed });
            }

            //Planned to be used for wall/obstacle detection (WIP)
            if (agentData.Exists(entityA) && !agentData.Exists(entityB) && translationData.Exists(entityB))
            {
                AgentData   adA = agentData[entityA];
                Translation trB = translationData[entityB];

                float3 origin = adA.position;
                float3 offset = trB.Value - origin;
            }
        }
Esempio n. 15
0
            void ChildLocalToWorld(float4x4 parentLocalToWorld, Entity entity)
            {
                var localToParent = LocalToParentFromEntity[entity];

                float4x4 localToWorldMatrix;

                if (LocalToWorldWriteGroupMask.Matches(entity))
                {
                    localToWorldMatrix             = math.mul(parentLocalToWorld, localToParent.Value);
                    LocalToWorldFromEntity[entity] = new LocalToWorld {
                        Value = localToWorldMatrix
                    };
                }
                else //This entity has a component with the WriteGroup(LocalToWorld)
                {
                    localToWorldMatrix = LocalToWorldFromEntity[entity].Value;
                }

                if (ChildFromEntity.Exists(entity))
                {
                    var children = ChildFromEntity[entity];
                    for (int i = 0; i < children.Length; i++)
                    {
                        ChildLocalToWorld(localToWorldMatrix, children[i].Value);
                    }
                }
            }
Esempio n. 16
0
 public void Execute()
 {
     for (int index = 0; index < TriggerEntitiesCount[0]; index++)
     {
         var entities = TriggerEntites[index];
         // Increment the frame count only for those entities that are
         // still in the TriggerEvent list.
         // TODO: this assumes overlapping of only one TriggerVolume at a time.
         // TODO: we should really compare the entities.VolumeEntity is the
         //       same as that saved in the component. The OverlappingEntity
         //       may have jumped from inside one TriggerVolume to another in
         //       a single frame
         if (OverlappingGroup.Exists(entities.OverlappingEntity))
         {
             var component = OverlappingGroup[entities.OverlappingEntity];
             //component.CurrentFrame++;
             //OverlappingGroup[entities.OverlappingEntity] = component;
             for (int i = 0; i < component.Length; i++)
             {
                 var a = component[i];
                 a.CurrentFrame++;
                 component[i] = a;
             }
         }
     }
 }
Esempio n. 17
0
        private void ProcessForEntity(Entity entity, Entity otherEntity)
        {
            if (TriggerEventBufferFromEntity.Exists(entity))
            {
                DynamicBuffer <TriggerEventBufferElement> triggerEventBuffer = TriggerEventBufferFromEntity[entity];

                bool foundMatch = false;
                for (int i = 0; i < triggerEventBuffer.Length; i++)
                {
                    TriggerEventBufferElement triggerEvent = triggerEventBuffer[i];

                    // If entity is already there, update to Stay
                    if (triggerEvent.Entity == otherEntity)
                    {
                        foundMatch            = true;
                        triggerEvent.State    = PhysicsEventState.Stay;
                        triggerEvent._isStale = false;
                        triggerEventBuffer[i] = triggerEvent;

                        break;
                    }
                }

                // If it's a new entity, add as Enter
                if (!foundMatch)
                {
                    triggerEventBuffer.Add(new TriggerEventBufferElement {
                        Entity   = otherEntity,
                        State    = PhysicsEventState.Enter,
                        _isStale = false,
                    });
                }
            }
        }
Esempio n. 18
0
 public void Execute(Entity entity, int index, ref DamageEvent c0)
 {
     if (DamageStackBuffer.Exists(c0.Receiver))
     {
         DamageStackBuffer[c0.Receiver].Add(c0);
     }
     ECB.DestroyEntity(index, entity);
 }
Esempio n. 19
0
 public void Execute(CollisionEvent collisionEvent)
 {
     if (collisions.Exists(collisionEvent.Entities.EntityA))
     {
         collisions[collisionEvent.Entities.EntityA].Add(new CollisionBufferData()
         {
             entity = collisionEvent.Entities.EntityB
         });
     }
     if (collisions.Exists(collisionEvent.Entities.EntityB))
     {
         collisions[collisionEvent.Entities.EntityB].Add(new CollisionBufferData()
         {
             entity = collisionEvent.Entities.EntityA
         });
     }
 }
Esempio n. 20
0
 public void Execute(TriggerEvent triggerEvent)
 {
     if (triggers.Exists(triggerEvent.Entities.EntityA))
     {
         triggers[triggerEvent.Entities.EntityA].Add(new TriggerBufferData()
         {
             entity = triggerEvent.Entities.EntityB
         });
     }
     if (triggers.Exists(triggerEvent.Entities.EntityB))
     {
         triggers[triggerEvent.Entities.EntityB].Add(new TriggerBufferData()
         {
             entity = triggerEvent.Entities.EntityA
         });
     }
 }
 void RecursiveChildsDestroy(Entity entity, int index)
 {
     EntityCommandBuffer.DestroyEntity(index, entity);
     if (ChildFromEntity.Exists(entity))
     {
         var children = ChildFromEntity[entity];
         for (int i = 0; i < children.Length; i++)
         {
             RecursiveChildsDestroy(children[i].Value, index);
         }
     }
 }
Esempio n. 22
0
            public void Execute([ReadOnly] ref NetworkStreamConnection connection,
                                [ReadOnly] ref NetworkSnapshotAckComponent ack, [ReadOnly] ref CommandTargetComponent state)
            {
                if (isNullCommandData && state.targetEntity != Entity.Null)
                {
                    return;
                }
                if (!isNullCommandData && !inputFromEntity.Exists(state.targetEntity))
                {
                    return;
                }
                DataStreamWriter writer = driver.BeginSend(unreliablePipeline, connection.Value);

                if (!writer.IsCreated)
                {
                    return;
                }
                writer.WriteByte((byte)NetworkStreamProtocol.Command);
                writer.WriteUInt(ack.LastReceivedSnapshotByLocal);
                writer.WriteUInt(ack.ReceivedSnapshotByLocalMask);
                writer.WriteUInt(localTime);
                uint returnTime = ack.LastReceivedRemoteTime;

                if (returnTime != 0)
                {
                    returnTime -= (localTime - ack.LastReceiveTimestamp);
                }
                writer.WriteUInt(returnTime);
                writer.WriteUInt(interpolationDelay);
                writer.WriteUInt(inputTargetTick);
                if (state.targetEntity != Entity.Null)
                {
                    var          input = inputFromEntity[state.targetEntity];
                    TCommandData baselineInputData;
                    input.GetDataAtTick(inputTargetTick, out baselineInputData);
                    baselineInputData.Serialize(ref writer);
                    for (uint inputIndex = 1; inputIndex < k_InputBufferSendSize; ++inputIndex)
                    {
                        TCommandData inputData;
                        input.GetDataAtTick(inputTargetTick - inputIndex, out inputData);
                        inputData.Serialize(ref writer, baselineInputData, compressionModel);
                    }

                    writer.Flush();
                }
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                netStats[0] = inputTargetTick;
                netStats[1] = (uint)writer.Length;
#endif

                driver.EndSend(writer);
            }
Esempio n. 23
0
 private void MakeDamage(Entity entityA, Entity entityB)
 {
     if (!explosionComponent[entityA].explode)
     {
         if (damageGroup.Exists(entityB) &&
             enemiesGroup.Exists(entityB))
         {
             var movementData = movementGroup[entityA];
             movementData.speed     = 0;
             movementGroup[entityA] = movementData;
         }
     }
 }
 void RecursiveChildsDisable(Entity entity, int index)
 {
     if (ChildFromEntity.Exists(entity))
     {
         var children = ChildFromEntity[entity];
         for (int i = 0; i < children.Length; i++)
         {
             RecursiveChildsDisable(children[i].Value, index);
         }
     }
     EntityCommandBuffer.AddComponent <Disabled>(index, entity);
     EntityCommandBuffer.RemoveComponent <DisableHierarchy>(index, entity);
 }
Esempio n. 25
0
 public void Execute()
 {
     foreach (TriggerEvent collisionEvent in CollisionEvents)
     {
         Entity entityA = PhysicsWorld.Bodies[collisionEvent.BodyIndices.BodyAIndex].Entity;
         Entity entityB = PhysicsWorld.Bodies[collisionEvent.BodyIndices.BodyBIndex].Entity;
         if (CollisionInfoBuffer.Exists(entityA))
         {
             CollisionInfoBuffer[entityA].Add(new CollisionInfo()
             {
                 other = entityB
             });
         }
         if (CollisionInfoBuffer.Exists(entityB))
         {
             CollisionInfoBuffer[entityB].Add(new CollisionInfo()
             {
                 other = entityA
             });
         }
     }
 }
 public static Entity GetRootEntity <T>(
     Entity entity, ComponentDataFromEntity <Parent> parentFromEntity, BufferFromEntity <T> bufferFromEntity)
     where T : struct, IBufferElementData
 {
     if (!parentFromEntity.Exists(entity) || bufferFromEntity.Exists(entity))
     {
         return(entity);
     }
     else
     {
         return(GetRootEntity(parentFromEntity[entity].Value, parentFromEntity, bufferFromEntity));
     }
 }
Esempio n. 27
0
            public void Execute()
            {
                var parents = UniqueParents.GetKeyArray(Allocator.Temp);

                for (int i = 0; i < parents.Length; i++)
                {
                    var parent = parents[i];
                    if (!ChildFromEntity.Exists(parent))
                    {
                        ParentsMissingChild.Add(parent);
                    }
                }
            }
Esempio n. 28
0
        void DestroyHierarchy(EntityCommandBuffer.Concurrent cmdBuffer, Entity entity, int index, BufferFromEntity <Child> childrenFromEntity)
        {
            cmdBuffer.DestroyEntity(index, entity);
            if (!childrenFromEntity.Exists(entity))
            {
                return;
            }
            var children = childrenFromEntity[entity];

            for (var i = 0; i < children.Length; ++i)
            {
                DestroyHierarchy(cmdBuffer, children[i].Value, index, childrenFromEntity);
            }
        }
            public unsafe void Execute(Entity entity, int index, [ReadOnly] ref CommandTargetComponent commandTarget,
                                       ref NetworkSnapshotAckComponent snapshotAck)
            {
                if (typeof(TCommandData) == typeof(NullCommandData) && commandTarget.targetEntity != Entity.Null)
                {
                    return;
                }
                if (typeof(TCommandData) != typeof(NullCommandData) && !commandData.Exists(commandTarget.targetEntity))
                {
                    return;
                }

                var buffer = cmdBuffer[entity];

                if (buffer.Length < 4)
                {
                    return;
                }
                DataStreamReader reader =
                    DataStreamUnsafeUtility.CreateReaderFromExistingData((byte *)buffer.GetUnsafePtr(), buffer.Length);
                var ctx  = default(DataStreamReader.Context);
                var tick = reader.ReadUInt(ref ctx);

                int age = (int)(serverTick - tick);

                age *= 256;
                snapshotAck.ServerCommandAge = (snapshotAck.ServerCommandAge * 7 + age) / 8;

                if (commandTarget.targetEntity != Entity.Null && buffer.Length > 4)
                {
                    var command = commandData[commandTarget.targetEntity];
                    var baselineReceivedCommand = default(TCommandData);
                    baselineReceivedCommand.Deserialize(tick, reader, ref ctx);
                    // Store received commands in the network command buffer
                    command.AddCommandData(baselineReceivedCommand);
                    for (uint i = 1; i < CommandSendSystem <TCommandData> .k_InputBufferSendSize; ++i)
                    {
                        var receivedCommand = default(TCommandData);
                        receivedCommand.Deserialize(tick - i, reader, ref ctx, baselineReceivedCommand,
                                                    compressionModel);
                        // Store received commands in the network command buffer
                        command.AddCommandData(receivedCommand);
                    }
                }
#if UNITY_EDITOR || DEVELOPMENT_BUILD
                netStats[0]  = serverTick;
                netStats[1] += (uint)buffer.Length + 16u; // 16 is the ack fields which are already processed
#endif
                buffer.Clear();
            }
Esempio n. 30
0
            void ChildTimeScale(float parentTimeScale, Entity entity, bool updateChildrenTimeScale, int depth)
            {
                if (depth++ > recursiveDepthLimit)
                {
                    LogError(entity);
                    return;
                }

                bool IsWritingByParentAndLocal = timeScaleWriteGroupMaskLocalParent.Matches(entity);

                updateChildrenTimeScale = updateChildrenTimeScale || (IsWritingByParentAndLocal && LocalTimeScaleFromEntity.DidChange(entity, LastSystemVersion));

                bool needUpdate = true;

                if (updateChildrenTimeScale)
                {
                    if (IsWritingByParentAndLocal)
                    {
                        if (TimeScaleFromEntity[entity].KeepTimeScaleOnParentChange)
                        {
                            LocalTimeScaleFromEntity[entity] = parentTimeScale != 0 ? TimeScaleFromEntity[entity].value / parentTimeScale : TimeScaleFromEntity[entity].value;
                        }

                        parentTimeScale            *= LocalTimeScaleFromEntity[entity].KeepTimeScale ? -LocalTimeScaleFromEntity[entity].value : LocalTimeScaleFromEntity[entity].value;
                        TimeScaleFromEntity[entity] = new TimeScale(parentTimeScale, TimeScaleFromEntity[entity].KeepTimeScaleOnParentChange);
                        needUpdate = false;
                    }
                    else if (timeScaleWriteGroupMaskParent.Matches(entity))
                    {
                        TimeScaleFromEntity[entity] = new TimeScale(parentTimeScale, TimeScaleFromEntity[entity].KeepTimeScaleOnParentChange);
                        needUpdate = false;
                    }
                }


                if (needUpdate)//This entity has a component with the WriteGroup(TimeScale)
                {
                    parentTimeScale = LocalTimeScaleFromEntity[entity].KeepTimeScale ? -TimeScaleFromEntity[entity].value: TimeScaleFromEntity[entity].value;
                }
                LocalTimeScaleFromEntity[entity] = LocalTimeScaleFromEntity[entity].KeepTimeScale ? -LocalTimeScaleFromEntity[entity].value : LocalTimeScaleFromEntity[entity].value;
                if (ChildFromEntity.Exists(entity))
                {
                    var children = ChildFromEntity[entity];
                    for (int i = 0; i < children.Length; i++)
                    {
                        ChildTimeScale(parentTimeScale, children[i].Value, updateChildrenTimeScale, depth);
                    }
                }
            }