public static void Create(EntityCommandBuffer ecb, SettlerPrefab settlerPrefab, HexCoordinates coordinates)
        {
            Entity settler = ecb.Instantiate(settlerPrefab.Value);

            float3 position = HexCellService.GetTranslationComponentByHexCoordinates(coordinates);

            position.y += 10f;

            BlobAssetReference <Unity.Physics.Collider> collider = Unity.Physics.BoxCollider.Create(
                new BoxGeometry
            {
                Center      = float3.zero,
                Orientation = quaternion.identity,
                Size        = new float3(10f, 10f, 10f),
                BevelRadius = 0.05f
            }
                );

            ecb.AddComponent <HexCoordinates>(settler, coordinates);
            ecb.AddComponent <PhysicsCollider>(settler, new PhysicsCollider {
                Value = collider
            });
            ecb.AddComponent <SettlerTag>(settler, new SettlerTag {
            });
            ecb.AddComponent <Selectable>(settler, new Selectable {
            });
            ecb.SetComponent <Translation>(settler, new Translation {
                Value = position
            });
            ecb.AddSharedComponent <CivIdSharedComponent>(settler, new CivIdSharedComponent {
                Value = 1
            });
        }
Beispiel #2
0
        public static Entity Create(EntityCommandBuffer ecb, CityPrefab cityPrefab, Entity settlerEntity)
        {
            Entity        city          = ecb.Instantiate(cityPrefab.Value);
            EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            HexCoordinates settlerHexCoordinates = entityManager.GetComponentData <HexCoordinates>(settlerEntity);

            CivIdSharedComponent settlerCivId = entityManager.GetSharedComponentData <CivIdSharedComponent>(settlerEntity);

            float3 position = HexCellService.GetTranslationComponentByHexCoordinates(settlerHexCoordinates);

            ecb.SetComponent <Translation>(
                city,
                new Translation {
                Value = position
            }
                );

            ecb.AddSharedComponent <CivIdSharedComponent>(
                city,
                new CivIdSharedComponent {
                Value = settlerCivId.Value
            }
                );

            ecb.DestroyEntity(settlerEntity);

            return(city);
        }
Beispiel #3
0
        public static float3 GetWorldPosition(Entity cityLabel)
        {
            EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            HexCoordinates hexCoordinates = entityManager.GetComponentData <HexCoordinates>(cityLabel);
            float3         pos            = HexCellService.GetTranslationComponentByHexCoordinates(hexCoordinates);

            return(pos);
        }
Beispiel #4
0
        protected override void OnUpdate()
        {
            Entity hitEntity;

            Entities
            .WithoutBurst()
            .WithStructuralChanges()
            .ForEach((
                         Entity entity,
                         int entityInQueryIndex,
                         ref MouseInput mouseInput
                         ) => {
                if (mouseInput.primaryAction == 0)
                {
                    return;
                }

                hitEntity = RaycastUtils.Raycast(
                    mouseInput.mousePosition,
                    out RaycastHit hit,
                    buildPhysicsWorldSystem
                    );

                if (hitEntity == Entity.Null)
                {
                    return;
                }

                if (EntityManager.HasComponent <SettlerTag>(hitEntity))
                {
                    SelectUnit.Create(hitEntity);
                    // EntityManager.AddComponentData<Selected>(hitEntity, new Selected {});
                    mouseInput.primaryAction = 0;

                    return;
                }

                HexCoordinates coordinates = CoordinatesService.GetCoordinatesFromPosition(hit.Position);
                Entity selectedEntity      = HexCellService.FindBy(coordinates);

                if (EntityManager.HasComponent <Selected>(selectedEntity))
                {
                    SelectCommand.Remove(coordinates);
                }
                else
                {
                    SelectCommand.Create(coordinates);
                }

                mouseInput.primaryAction = 0;
            })
            .Run();
        }
        public static void Create(EntityCommandBuffer ecb, HighlightCellPrefab highlightPrefab, HexCoordinates coordinates)
        {
            Entity highlight = ecb.Instantiate(highlightPrefab.Value);
            float3 position  = HexCellService.GetTranslationComponentByHexCoordinates(coordinates);

            ecb.SetComponent <Translation>(highlight, new Translation {
                Value = position
            });
            ecb.AddComponent <HexCoordinates>(highlight, coordinates);
            ecb.AddComponent <HighlightTag>(highlight, new HighlightTag {
            });
        }
        protected override void OnUpdate()
        {
            EntityCommandBuffer ecb       = barrier.CreateCommandBuffer();
            EntityArchetype     archetype = UISettlerPanel.GetArchetype();

            Entities
            .WithoutBurst()
            .ForEach((
                         Entity entity,
                         in CommandSelectUnit commandSelectUnit,
                         in HexCoordinates hexCoordinates
                         ) => {
                Entity selectedCell = HexCellService.FindBy(hexCoordinates);
                ecb.AddComponent <Selected>(commandSelectUnit.entity, new Selected {
                });

                UISettlerPanel.Show(ecb, archetype, hexCoordinates);

                ecb.DestroyEntity(entity);
            }).Run();