Ejemplo n.º 1
0
 public void Execute(CollisionEvent collisionEvent)
 {
     {
         Entity entityA = collisionEvent.Entities.EntityA;
         Entity entityB = collisionEvent.Entities.EntityB;
         if (destroyOnContactGroup.HasComponent(entityA))
         {
             entityCommandBuffer.AddComponent <ToDestroyTag>(entityA);
         }
         if (destroyOnContactGroup.HasComponent(entityB))
         {
             entityCommandBuffer.AddComponent <ToDestroyTag>(entityB);
         }
     }
 }
Ejemplo n.º 2
0
            public Entity GetEntityFromComponentGroup <T>(Entity entityA, Entity entityB,
                                                          ComponentDataFromEntity <T> componentGroup) where T : struct, IComponentData
            {
                if (componentGroup.HasComponent(entityA))
                {
                    return(entityA);
                }

                if (componentGroup.HasComponent(entityB))
                {
                    return(entityB);
                }

                return(Entity.Null);
            }
Ejemplo n.º 3
0
 public void Execute(TriggerEvent triggerEvent)
 {
     if (physicsVelocityEntities.HasComponent(triggerEvent.Entities.EntityA))
     {
         PhysicsVelocity physicsVelocity = physicsVelocityEntities[triggerEvent.Entities.EntityA];
         physicsVelocity.Linear.y = 5f;
         physicsVelocityEntities[triggerEvent.Entities.EntityA] = physicsVelocity;
     }
     if (physicsVelocityEntities.HasComponent(triggerEvent.Entities.EntityB))
     {
         PhysicsVelocity physicsVelocity = physicsVelocityEntities[triggerEvent.Entities.EntityB];
         physicsVelocity.Linear.y = 5f;
         physicsVelocityEntities[triggerEvent.Entities.EntityB] = physicsVelocity;
     }
 }
 public void Execute(TriggerEvent triggerEvent)
 {
     if (m_destroyables.HasComponent(triggerEvent.EntityA))
     {
         var destroyable = m_destroyables[triggerEvent.EntityA];
         destroyable.m_mustBeDestroyed        = true;
         m_destroyables[triggerEvent.EntityA] = destroyable;
     }
     if (m_destroyables.HasComponent(triggerEvent.EntityB))
     {
         var destroyable = m_destroyables[triggerEvent.EntityB];
         destroyable.m_mustBeDestroyed        = true;
         m_destroyables[triggerEvent.EntityB] = destroyable;
     }
 }
        public void Execute(Entity e, int index, ref PhysicsCollider collider, ref Translation translation, ref Rotation rotation)
        {
            ColliderDistanceInput distanceInput = new ColliderDistanceInput
            {
                Collider    = collider.ColliderPtr,
                MaxDistance = .01f,
                Transform   = new RigidTransform(rotation.Value, translation.Value),
            };

            NativeList <DistanceHit> hits = new NativeList <DistanceHit>(Allocator.Temp);
            var collisionWorld            = physicsWorld.CollisionWorld;

            if (collisionWorld.CalculateDistance(distanceInput, ref hits))
            {
                foreach (var hit in hits)
                {
                    var entity = collisionWorld.Bodies[hit.RigidBodyIndex].Entity;
                    if (entity != e)
                    {
                        if (consumedObjectIndex.HasComponent(entity))
                        {
                            var consumedEntity = commandBuffer.CreateEntity(index);
                            var consumedObject = consumedObjectIndex[entity];
                            commandBuffer.AddComponent(index, consumedEntity, consumedObject);
                            commandBuffer.AddComponent(index, consumedEntity, new ConsumedTag());
                            commandBuffer.DestroyEntity(index, entity);
                        }
                    }
                }
            }

            hits.Dispose();
        }
        public void Execute(TriggerEvent triggerEvent)
        {
            Entity bullet;
            Entity target;

            if (damageApplyerGroup.HasComponent(triggerEvent.Entities.EntityA) && hpGroup.HasComponent(triggerEvent.Entities.EntityB))
            {
                bullet = triggerEvent.Entities.EntityA;
                target = triggerEvent.Entities.EntityB;
            }
            else if (damageApplyerGroup.HasComponent(triggerEvent.Entities.EntityB) && hpGroup.HasComponent(triggerEvent.Entities.EntityA))
            {
                bullet = triggerEvent.Entities.EntityB;
                target = triggerEvent.Entities.EntityA;
            }
            else
            {
                return;
            }

            if (teamMemberGroup[bullet].TeamId != teamMemberGroup[target].TeamId)
            {
                Debug.Log("Hit! " + teamMemberGroup[bullet].TeamId + "  " + teamMemberGroup[target].TeamId);

                var hp = hpGroup[target];
                hp.HP          -= damageApplyerGroup[bullet].damage;
                hpGroup[target] = hp;
                if (hpGroup[target].HP <= 0)
                {
                    Debug.Log("HP<0!");
                }
            }

            collisions++;
        }
Ejemplo n.º 7
0
 private void TestEntityTrigger(Entity entity1, Entity entity2)
 {
     if (playerEntity.HasComponent(entity1) && pickableEntity.HasComponent(entity2) && !waitDeleteEntity.HasComponent(entity2))
     {
         commandBuffer.AddComponent(entity2, new DeleteTag());
     }
 }
Ejemplo n.º 8
0
    public static ActorFilterInfo GetActorFilterInfo(
        Entity entity,
        ComponentDataFromEntity <Team> Teams,
        ComponentDataFromEntity <FirstInstigator> FirstInstigators,
        ComponentDataFromEntity <TileColliderTag> TileColliderTags)
    {
        ActorFilterInfo result = new ActorFilterInfo()
        {
            Team      = Team.None,
            IsTerrain = false,
        };

        // try to get the team
        if (Teams.TryGetComponent(entity, out Team team))
        {
            result.Team = team;
        }
        else if (FirstInstigators.TryGetComponent(entity, out FirstInstigator firstInstigator))
        {
            if (Teams.TryGetComponent(firstInstigator, out Team firstInstigatorTeam))
            {
                result.Team = firstInstigatorTeam;
            }
        }

        result.IsTerrain = TileColliderTags.HasComponent(entity);

        return(result);
    }
Ejemplo n.º 9
0
        public void Execute(CollisionEvent collisionEvent)
        {
            if (ballFromEntity.HasComponent(collisionEvent.EntityA))
            {
                collidedBalls.Add(collisionEvent.EntityA);

                // Change the ball's color.
                var materialPropertyColor = colorFromEntity[collisionEvent.EntityA];
                {
                    var colorZ = materialPropertyColor.Value.z;
                    materialPropertyColor.Value.z = materialPropertyColor.Value.y;
                    materialPropertyColor.Value.y = materialPropertyColor.Value.x;
                    materialPropertyColor.Value.x = colorZ;
                }
                entityCommandBuffer.SetComponent(collisionEvent.EntityA, materialPropertyColor);

                // If it hit a block, destroy it and add its score to the UIData.
                if (blockFromEntity.HasComponent(collisionEvent.EntityB))
                {
                    entityCommandBuffer.DestroyEntity(collisionEvent.EntityB);
                    uiData.score += scoreFromEntity[collisionEvent.EntityB].score;
                    entityCommandBuffer.SetComponent(uiDataEntity, uiData);
                }
            }
        }
Ejemplo n.º 10
0
            public void Execute(Entity entity, int index, [ReadOnly] DynamicBuffer <AttributeBufferElement <TemporaryAttributeModifierTag, TAttributeTag> > attributeBuffer, ref TAttributeTag attribute)
            {
                var added      = 0f;
                var multiplied = 0f;
                var divided    = 0f;

                for (var i = 0; i < attributeBuffer.Length; i++)
                {
                    var attributeEntity = attributeBuffer[i].Value;
                    if (Add_CDFE.HasComponent(attributeEntity))
                    {
                        added += Add_CDFE[attributeEntity];
                    }

                    if (Div_CDFE.HasComponent(attributeEntity))
                    {
                        added += Div_CDFE[attributeEntity];
                    }

                    if (Mul_CDFE.HasComponent(attributeEntity))
                    {
                        added += Mul_CDFE[attributeEntity];
                    }
                }
                attribute.CurrentValue = added + attribute.BaseValue * (1 + multiplied - divided);
            }
Ejemplo n.º 11
0
 //Returns true if entity is already on location, false if it is not
 private static bool GoToLocation(Entity location, Entity movedEntity, ComponentDataFromEntity <CurrentLocationComponent> currentLocationData,
                                  ComponentDataFromEntity <ExchangeTaskLocationComponent> exchangeTaskLocationData, EntityCommandBuffer.ParallelWriter ecb, int entityInQueryIndex)
 {
     if (location == movedEntity)
     {
         return(true);
     }
     if (!currentLocationData.HasComponent(movedEntity) || !(currentLocationData[movedEntity].entity == location))
     {
         var exchangeTaskLocation = new ExchangeTaskLocationComponent {
             Entity = location
         };
         if (exchangeTaskLocationData.HasComponent(movedEntity))
         {
             exchangeTaskLocationData[movedEntity] = exchangeTaskLocation;
         }
         else
         {
             ecb.AddComponent(entityInQueryIndex, movedEntity, exchangeTaskLocation);
         }
         return(false);
     }
     else
     {
         return(true);
     }
 }
Ejemplo n.º 12
0
        public void Execute(TriggerEvent triggerEvent)
        {
            if (animalTag.HasComponent(triggerEvent.Entities.EntityA))
            {
                AnimalMovementData mvmtDataA = mvmtData[triggerEvent.Entities.EntityA];
                AnimalMovementData mvmtDataB = mvmtData[triggerEvent.Entities.EntityB];
                float3             positionA = translation[triggerEvent.Entities.EntityA].Value;

                float speedA   = mvmtDataA.movementSpeed;
                float speedB   = mvmtDataB.movementSpeed;
                float maxSpeed = math.max(speedA, speedB);

                float dotProduct = math.dot(math.normalize(mvmtDataA.targetDirection - positionA), math.normalize(mvmtDataB.targetDirection - positionA));

                float angle = 0.262f;
                angle += 1f - math.abs(dotProduct);
                angle += (1f - (maxSpeed * 0.1f));
                angle  = math.clamp(angle, 0f, StaticValues.AVOIDANCE_MIN_ANGLE);
                quaternion newRotation  = quaternion.RotateY(angle);
                float3     newDirection = math.rotate(newRotation, mvmtDataA.direction);
                newDirection = math.normalizesafe(newDirection);
                // Set EntityA's target direction
                mvmtDataA.targetDirection = newDirection;
                mvmtData[triggerEvent.Entities.EntityA] = mvmtDataA;
            }
        }
Ejemplo n.º 13
0
            public void Execute(ArchetypeChunk chunk, int chunkIndex, int firstEntityIndex)
            {
                var renders      = chunk.GetBufferAccessor(RenderType);
                var batchedSpans = chunk.GetBufferAccessor(SpanType);
                var submeshes    = chunk.GetBufferAccessor(SubMeshType);

                for (int i = 0; i < chunk.Count; i++)
                {
                    var batchedSubMesh = submeshes[i];
                    var renderer       = renders[i].AsNativeArray();
                    var span           = batchedSpans[i].AsNativeArray();

                    batchedSubMesh.Clear();

                    for (int k = 0; k < span.Length; k++)
                    {
                        var current = span[k].Value;

                        // When we build the keys - we only care about the first rendered element's material
                        // and texture, because we assume via batching that the first element's material and
                        // and texture are representative of the entire batch.
                        var element = renderer[current.x].Value;

                        var materialKey = MaterialKeys.HasComponent(element) ? MaterialKeys[element].Value : Entity.Null;
                        var textureKey  = TextureKeys.HasComponent(element) ? TextureKeys[element].Value : Entity.Null;

                        batchedSubMesh.Add(new SubmeshKeyElement {
                            TextureEntity  = textureKey,
                            MaterialEntity = materialKey
                        });
                    }
                }
            }
Ejemplo n.º 14
0
        public void Execute(TriggerEvent triggerEvent)
        {
            if (playerEntities.HasComponent(triggerEvent.Entities.EntityA))
            {
                Translation translation = translationEntities[triggerEvent.Entities.EntityA];
                translation.Value.y = yPos;
                translationEntities[triggerEvent.Entities.EntityA] = translation;
            }

            if (playerEntities.HasComponent(triggerEvent.Entities.EntityB))
            {
                Translation translation = translationEntities[triggerEvent.Entities.EntityB];
                translation.Value.y = yPos;
                translationEntities[triggerEvent.Entities.EntityB] = translation;
            }
        }
Ejemplo n.º 15
0
        public void Execute(TriggerEvent _triggerEvent)
        {
            if (m_attractedComponentDataFromEntity.HasComponent(_triggerEvent.Entities.EntityA))
            {
                var attractedBody = m_attractedComponentDataFromEntity[_triggerEvent.Entities.EntityA];
                attractedBody.m_isActive = true;
                m_attractedComponentDataFromEntity[_triggerEvent.Entities.EntityA] = attractedBody;
            }

            if (m_attractedComponentDataFromEntity.HasComponent(_triggerEvent.Entities.EntityB))
            {
                var attractedBody = m_attractedComponentDataFromEntity[_triggerEvent.Entities.EntityB];
                attractedBody.m_isActive = true;
                m_attractedComponentDataFromEntity[_triggerEvent.Entities.EntityB] = attractedBody;
            }
        }
        public void Execute(TriggerEvent triggerEvent)
        {
            Entity hitEntity, magicFireEntity;

            if (MagicFireRef.HasComponent(triggerEvent.EntityA))
            {
                hitEntity       = triggerEvent.EntityB;
                magicFireEntity = triggerEvent.EntityA;
            }
            else if (MagicFireRef.HasComponent(triggerEvent.EntityB))
            {
                hitEntity       = triggerEvent.EntityA;
                magicFireEntity = triggerEvent.EntityB;
            }
            else
            {
                return;
            }

            var magicFire = MagicFireRef[magicFireEntity];

            magicFire.Destroyed           = true;
            MagicFireRef[magicFireEntity] = magicFire;

            if (HealthRef.HasComponent(hitEntity))
            {
                var health = HealthRef[hitEntity];
                health.Value--;
                HealthRef[hitEntity] = health;
            }
        }
Ejemplo n.º 17
0
            public void Execute(int index)
            {
                var entity = Keys[index];

                // todo this occurs when all entities are destroyed, is there a better way to prevent this?
                if (!NavmeshLookup.HasComponent(entity))
                {
                    return;
                }

                var navmesh            = NavmeshLookup[entity];
                var insertions         = Operations.GetValuesForKey(entity);
                var destroyedTriangles = DestroyedLookup[entity];
                var ltwInv             = math.inverse(LocalToWorldLookup[entity].Value);

                if (navmesh.Navmesh->IsEmpty)
                {
                    navmesh.Navmesh->Load(insertions, ltwInv);
                }
                else
                {
                    var removals = Removals.GetValuesForKey(entity);
                    navmesh.Navmesh->Update(insertions, removals, ltwInv);
                }

                var tris = navmesh.Navmesh->DestroyedTriangles.GetEnumerator();

                while (tris.MoveNext())
                {
                    destroyedTriangles.Add(tris.Current);
                }
                destroyedTriangles.Reinterpret <int>().AsNativeArray().Sort();
            }
Ejemplo n.º 18
0
            public void Execute(TriggerEvent triggerEvent)
            {
                if (CollidedTagComponents.HasComponent(triggerEvent.EntityB))
                {
                    return;
                }

                if (GoldTagComponents.HasComponent(triggerEvent.EntityA))
                {
                    OnTriggerGold(triggerEvent.EntityA);
                }

                if (GoldTagComponents.HasComponent(triggerEvent.EntityB))
                {
                    OnTriggerGold(triggerEvent.EntityB);
                }



                if (TeleportTagComponents.HasComponent(triggerEvent.EntityB))
                {
                    OnTriggerTeleport(triggerEvent);
                }


                if (ColorBoxTagComponents.HasComponent(triggerEvent.EntityB))
                {
                    OnTriggerBoxColor <ColorBoxTagComponent>(triggerEvent);
                }

                if (DynamicColorBoxTagComponents.HasComponent(triggerEvent.EntityB))
                {
                    OnTriggerBoxColor <DynamicColorBoxTagComponent>(triggerEvent);
                }
            }
Ejemplo n.º 19
0
        public void Execute(TriggerEvent triggerEvent)
        {
            if (playerGroup.HasComponent(triggerEvent.EntityA))
            {
                if (pickupGroup.HasComponent(triggerEvent.EntityB))
                {
                    PickupTag pickup = pickupGroup[triggerEvent.EntityB];
                    switch (pickup.type)
                    {
                    case 0:
                        HealthData health = healthGroup[triggerEvent.EntityA];
                        health.health += 50;
                        if (health.health > 100)
                        {
                            health.health = 100;
                        }
                        health.damageCoolDown             = .3f;
                        healthGroup[triggerEvent.EntityA] = health;
                        break;

                    case 1:
                        GunData gun = gunGroup[triggerEvent.EntityB];
                        gunGroup[triggerEvent.EntityA] = gun;
                        break;

                    default:
                        break;
                    }
                    pickup.destroy = true;
                    pickupGroup[triggerEvent.EntityB] = pickup;
                }
            }
        }
        public void Execute(TriggerEvent triggerEvent)
        {
            Entity hitEntity, bulletEntity;

            if (bulletRef.HasComponent(triggerEvent.EntityA))
            {
                hitEntity    = triggerEvent.EntityB;
                bulletEntity = triggerEvent.EntityA;
            }
            else if (bulletRef.HasComponent(triggerEvent.EntityB))
            {
                hitEntity    = triggerEvent.EntityA;
                bulletEntity = triggerEvent.EntityB;
            }
            else
            {
                return;
            }

            var bullet = bulletRef[bulletEntity];

            bullet.destroyed        = true;
            bulletRef[bulletEntity] = bullet;

            if (healthRef.HasComponent(hitEntity))
            {
                var health = healthRef[hitEntity];
                health.value--;
                healthRef[hitEntity] = health;
            }
        }
Ejemplo n.º 21
0
 public static uint GetGhost(this ComponentDataFromEntity <GhostIdentifier> ghostIdentifier, Entity entity)
 {
     if (ghostIdentifier.HasComponent(entity))
     {
         return(ghostIdentifier[entity].Value);
     }
     return(0);
 }
Ejemplo n.º 22
0
            public void Execute(TriggerEvent triggerEvent)
            {
                Entity entityA = triggerEvent.EntityA;
                Entity entityB = triggerEvent.EntityB;

                // Identify which colliding bodies contain which components
                bool isBodyAScoreBox = ScoreBoxGroup.HasComponent(entityA);
                bool isBodyBScoreBox = ScoreBoxGroup.HasComponent(entityB);

                // If both colliding bodies have ScoreBox components, do nothing
                if (isBodyAScoreBox && isBodyBScoreBox)
                {
                    return;
                }

                bool isBodyAPlayer = PlayerGroup.HasComponent(entityA);
                bool isBodyBPlayer = PlayerGroup.HasComponent(entityB);

                // If both colliding bodies have Player components, do nothing
                if (isBodyAPlayer && isBodyBPlayer)
                {
                    return;
                }

                // Depending on which body is which, update the player score and destroy the ScoreBox entity
                if (isBodyAScoreBox && isBodyBPlayer)
                {
                    var scoreBoxComponent = ScoreBoxGroup[entityA];
                    var playerComponent   = PlayerGroup[entityB];

                    playerComponent.Score += scoreBoxComponent.Points;
                    PlayerGroup[entityB]   = playerComponent;

                    CommandBuffer.DestroyEntity(triggerEvent.EntityA);
                }
                else if (isBodyBScoreBox && isBodyAPlayer)
                {
                    var scoreBoxComponent = ScoreBoxGroup[entityB];
                    var playerComponent   = PlayerGroup[entityA];

                    playerComponent.Score += scoreBoxComponent.Points;
                    PlayerGroup[entityA]   = playerComponent;

                    CommandBuffer.DestroyEntity(triggerEvent.EntityB);
                }
            }
Ejemplo n.º 23
0
 private Entity GetRootCanvas(Entity current)
 {
     if (Parents.HasComponent(current))
     {
         return(GetRootCanvas(Parents[current].Value));
     }
     return(current);
 }
Ejemplo n.º 24
0
        /// Identify our spin zone and our player.
        public void Execute(TriggerEvent triggerEvent)
        {
            var a = triggerEvent.EntityA;
            var b = triggerEvent.EntityB;

            var isSpinZoneA = spinZoneGroup.HasComponent(a);
            var isSpinZoneB = spinZoneGroup.HasComponent(b);

            if (isSpinZoneA && b == player)
            {
                Spin(a);
            }
            if (isSpinZoneB && a == player)
            {
                Spin(b);
            }
        }
Ejemplo n.º 25
0
        public void Execute(TriggerEvent triggerEvent)
        {
            var entityA = triggerEvent.EntityA;
            var entityB = triggerEvent.EntityB;

            var entityAIsShop = ShopComponentGroup.HasComponent(entityA);
            var entityBIsShop = ShopComponentGroup.HasComponent(entityB);

            if (entityAIsShop || entityBIsShop)
            {
                var shop = entityAIsShop ? entityA : entityB;

                var shopComponent = ShopComponentGroup[shop];
                shopComponent.ShowingShopButton = true;
                ShopComponentGroup[shop]        = shopComponent;
            }
        }
Ejemplo n.º 26
0
        public void Execute(TriggerEvent triggerEvent)
        {
            Entity entityA = triggerEvent.Entities.EntityA;
            Entity entityB = triggerEvent.Entities.EntityB;

            Entity playerEntity = Entity.Null;
            Entity enemyEntity  = Entity.Null;
            Entity wallEntity   = Entity.Null;

            if (tagPlayerComponentDataFromEntity.HasComponent(entityA))
            {
                playerEntity = entityA;
            }
            if (tagPlayerComponentDataFromEntity.HasComponent(entityB))
            {
                playerEntity = entityB;
            }

            if (tagEnemyComponentDataFromEntity.HasComponent(entityA))
            {
                enemyEntity = entityA;
            }
            if (tagEnemyComponentDataFromEntity.HasComponent(entityB))
            {
                enemyEntity = entityB;
            }

            if (tagWallComponentDataFromEntity.HasComponent(entityA))
            {
                wallEntity = entityA;
            }
            if (tagWallComponentDataFromEntity.HasComponent(entityB))
            {
                wallEntity = entityB;
            }

            if ((playerEntity != Entity.Null && enemyEntity != Entity.Null) ||
                (playerEntity != Entity.Null && wallEntity != Entity.Null))
            {
                // Collision between Player and Enemy or Player and Wall
                entityCommandBuffer.AddComponent(playerEntity, new Tag_GameOver());
            }

            //UnityEngine.Debug.Log(entityA + " " + entityB);
        }
            public void Execute(TriggerEvent triggerEvent)
            {
                Entity ea = triggerEvent.EntityA;
                Entity eb = triggerEvent.EntityB;

                if (allPlayers.HasComponent(ea) && allBullets.HasComponent(eb))
                {
                    HealthData bulletHealth = allHealth[eb];
                    bulletHealth.value -= 1;
                    allHealth[eb]       = bulletHealth;
                }
                else if (allPlayers.HasComponent(eb) && allBullets.HasComponent(ea))
                {
                    HealthData bulletHealth = allHealth[ea];
                    bulletHealth.value -= 1;
                    allHealth[eb]       = bulletHealth;
                }
            }
Ejemplo n.º 28
0
 public void UpdateCollideable(Entity entity, Entity collider)
 {
     if (CollideableGroup.HasComponent(entity))
     {
         var collideable = CollideableGroup[entity];
         collideable.CollisionEntity = collider;
         CollideableGroup[entity]    = collideable;
     }
 }
Ejemplo n.º 29
0
 public void Execute(TriggerEvent eventTrigger)
 {
     if (finishGroup.HasComponent(eventTrigger.Entities.EntityA) && playerGroup.HasComponent(eventTrigger.Entities.EntityB) || finishGroup.HasComponent(eventTrigger.Entities.EntityB) && playerGroup.HasComponent(eventTrigger.Entities.EntityA))
     {
         EventCenter.GameStateChangeEvent.Invoke(new GameStateChangeMessage {
             Finish = true
         });
     }
 }
Ejemplo n.º 30
0
        /// <summary>
        /// Consume the item, adding its effect to the player.
        /// </summary>
        /// <param name="player">Entity designated as the player</param>
        /// <param name="item">Entity designated as the item</param>
        void Consume(Entity player, Entity item)
        {
            if (deletionGroup.HasComponent(item))
            {
                return;
            }

            buffer.AddComponent(item, typeof(DeleteTag));
        }