private void SelectedUnits() { // On parcours toutes les unitées Entities.WithAll <UnitComponent>().ForEach((Entity entity, ref Translation translation) => { var viewportBounds = UnitControlHelpers.GetViewportBounds(Camera.main, this.startPositionScreen, Input.mousePosition); if (viewportBounds.Contains(Camera.main.WorldToViewportPoint(translation.Value))) { // Entity inside selection area PostUpdateCommands.AddComponent(entity, new UnitSelectedComponent()); this.selectedEntityCount++; if (EntityManager.HasComponent <CityHallComponent>(entity)) { SelectionMesh.AddEntitySelectionMesh(entity, true); } else { SelectionMesh.AddEntitySelectionMesh(entity, false); } if (!this.hasWorkerSelected) { this.hasWorkerSelected = EntityManager.HasComponent <WorkerComponent>(entity); } if (!this.hasHubSelected) { this.hasHubSelected = EntityManager.HasComponent <CityHallComponent>(entity); } } }); }
// Start is called before the first frame update private void Start() { DefaultWorldInitialization.Initialize("SwarmOfIron", false); World w = World.DefaultGameObjectInjectionWorld; //Init entityManager entityManager = w.EntityManager; updateMoveToSystem = w.GetOrCreateSystem <UpdateMoveToSystem>(); //create selection Mesh unitSelectedCircleMesh = SelectionMesh.CreateMesh(1.0f, 1.0f); //spawn some woods // Wood.SpawnWood(spawnWoodAmount); CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Wood), spawnWoodAmount); CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Rock), spawnRockAmount); //spawn some workers CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Worker), spawnWorkerAmount); //spawn some soldiers Soldier.init(); CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Soldier), spawnSoldierAmount); //spawn Enemie soldiers E_Soldier.init(); CustomEntity.SpawnEntitiesAtRandomPosition(typeof(E_Soldier), EspawnSoldierAmount); MiniMap.SpawnMiniMap(); //CityHall.SpawnCityHall(new float3(0.0f, 0.0f, 0.0f)); }