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); }
protected override void OnUpdate() { CityPrefab cityPrefab = GetSingleton <CityPrefab>(); var ecb = barrier.CreateCommandBuffer(); var archetype = UICityLabel.GetCreateArchetype(); Entities .WithoutBurst() .ForEach(( Entity entity, int entityInQueryIndex, in SettlerTag settlerTag, in CommandCreateCity cmdCreateCity, in HexCoordinates hexCoordinates ) => { Entity city = CityEntity.Create(ecb, cityPrefab, entity); UICityLabel.Create(ecb, archetype, hexCoordinates); }