Example #1
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);
        }
Example #2
0
            public void ExecuteEach(EntityManager entityManager, ComponentGroup phaseEnablerGroup)
            {
                NativeArray <Entity> entities = phaseEnablerGroup.ToEntityArray(Allocator.TempJob);

                for (int entityIndex = 0, numEntities = entities.Length; entityIndex < numEntities; ++entityIndex)
                {
                    Entity            entity            = entities[entityIndex];
                    PhaseEnabler      phaseEnabler      = entityManager.GetComponentData <PhaseEnabler>(entity);
                    ActivatableObject activatableObject = entityManager.GetSharedComponentData <ActivatableObject>(entity);
                    if (!TryActivateObjectByPhase(ref phaseEnabler, ref activatableObject))
                    {
                        continue;
                    }

                    entityManager.SetSharedComponentData <ActivatableObject>(entity, activatableObject);
                }
                entities.Dispose();
            }
Example #3
0
        protected override void OnStartRunning()
        {
            GetConstructBuildingEntity();

            // Preview Mesh Scale
            RenderMesh rmesh = EntityManager.GetSharedComponentData <RenderMesh>(task.previewPrefab);

            previewMesh     = rmesh.mesh;
            previewMaterial = rmesh.material;

            // Can place
            previewMaterialGreen = new Material(previewMaterial);
            previewMaterialGreen.SetColor("_BaseColor", Color.green); // _Color without Lit?

            // Can't place
            previewMaterialRed = new Material(previewMaterial);
            previewMaterialRed.SetColor("_BaseColor", Color.red);
        }