public void Execute(CollisionEvent collisionEvent) { Entity entityA = collisionEvent.EntityA; Entity entityB = collisionEvent.EntityB; bool isBodyAProjectile = innerProjectileGroup.HasComponent(entityA); bool isBodyBProjectile = innerProjectileGroup.HasComponent(entityB); bool isBodyACube = innerCubeGroup.HasComponent(entityA); bool isBodyBCube = innerCubeGroup.HasComponent(entityB); Entity projectile, cube; if (isBodyAProjectile && isBodyBCube) { projectile = entityA; cube = entityB; } else if (isBodyBProjectile && isBodyACube) { projectile = entityB; cube = entityA; } else { bool isBodyAGround = innerGroundGroup.HasComponent(entityA); bool isBodyBGround = innerGroundGroup.HasComponent(entityB); bool isBodyABomb = innerBombGroup.HasComponent(entityA); bool isBodyBBomb = innerBombGroup.HasComponent(entityB); Entity bomb; if (isBodyAGround && isBodyBBomb) { bomb = entityB; } else if (isBodyBGround && isBodyABomb) { bomb = entityA; } else { return; } GooBombData bombData = innerBombGroup[bomb]; bombData.hitGround = true; innerBombGroup[bomb] = bombData; return; } ProjectileData projectileData = innerProjectileGroup[projectile]; PurpleGooCubeData cubeData = innerCubeGroup[cube]; if (projectileData.hitsLeft > 0 && cubeData.pendingDamage < cubeData.height) { cubeData.pendingDamage += 5; innerCubeGroup[cube] = cubeData; projectileData.hitsLeft -= 1; innerProjectileGroup[projectile] = projectileData; } }
void Start() { gridSize = gridSizeInspectorXZ; entityManager = World.DefaultGameObjectInjectionWorld.EntityManager; blobAssetStore = new BlobAssetStore(); GameObjectConversionSettings goConversionSettings = GameObjectConversionSettings.FromWorld(World.DefaultGameObjectInjectionWorld, blobAssetStore); cubeEntityTemplate = GameObjectConversionUtility.ConvertGameObjectHierarchy(cubePrefab, goConversionSettings); EntityCommandBuffer commandBuffer = new EntityCommandBuffer(Allocator.TempJob); gridCubeHeightMatrix = new float[gridSize.x, gridSize.z]; for (int x = 0; x < gridSize.x; ++x) { for (int z = 0; z < gridSize.z; ++z) { //Calculate POSITION with offset float3 position = new float3 { x = cubePositionOffsetXZ.x + cubeSize * x, z = cubePositionOffsetXZ.z + cubeSize * z, y = yCubePosition }; gridCubeHeightMatrix[x, z] = initialCubeHeight; PurpleGooCubeData pgc = new PurpleGooCubeData { gridIndex = { x = x, z = z, y = 0 }, //Negative height deactivates the cubes. Increasing their height beyond 0 will activate them. //By deactivate I don't mean making them actually innactive, but only positioned outside of the play area. height = gridCubeHeightMatrix[x, z] }; //SPAWN Cube entity at position Entity newCube = entityManager.Instantiate(cubeEntityTemplate); if (gridCubeHeightMatrix[x, z] < 0) { commandBuffer.AddComponent <InactiveGooCubeTag>(newCube, new InactiveGooCubeTag { }); pgc.active = false; } else { pgc.active = true; } commandBuffer.SetComponent <PurpleGooCubeData>(newCube, pgc); commandBuffer.SetComponent <Translation>(newCube, new Translation { Value = position }); } } commandBuffer.Playback(entityManager); commandBuffer.Dispose(); }