public void Run() { if (!Input.GetMouseButtonDown(1)) { return; } var liveEntities = builds.Entities.Where(e => e.IsNotNullAndAlive()); if (liveEntities.Count() < 1) { return; } var assetsEntity = assets.Entities.First(); foreach (var e in liveEntities) { BuildingHelper.ResetBuildingSwitch(assetsEntity.Get <BuildingSwitchesComponent>() .buildingsSwitch[e.Get <BuildingCreateComponent>() .Tag .ToString()]); if (e.Get <BuildingCreateComponent>().Tag == BuildingTag.Base) { canvases.Get1[0].UserInterface.GetComponentsInChildren <Button>() .Where(b => b.name.Equals("CreateBase")) .First() .interactable = true; } e.Destroy(); } }
public void Run() { if (!Input.GetMouseButtonDown(0) || EventSystem.current.IsPointerOverGameObject()) { return; } var buildEntities = builds.Entities.Where(e => e.IsNotNullAndAlive()); if (buildEntities.Count() == 0) { return; } var buildingCreateEntity = buildEntities.First(); var assetsEntity = assets.Entities.First(); var currentBuildComponent = buildingCreateEntity.Get <BuildingCreateComponent>(); var type = currentBuildComponent.Tag.ToString(); if (!currentBuildComponent.isCanInstall) { MessageHelper.SendMessageToConsole("Тут нельзя строить здания", 8, world); return; } var resources = playerRes.Get1.First(); if (PricesKeeper.PricesFromTag[type] > resources.Cash) { MessageHelper.SendMessageToConsole("Недостаточно денег", 8, world); return; } resources.Cash -= PricesKeeper.PricesFromTag[type]; var buildingAssetsComponent = assetsEntity.Get <BuildingAssetsComponent>(); var buildEntity = BuildingHelper.CreateBuilding(world, buildingAssetsComponent.BuildingsAssets[type], buildingAssetsComponent.InBuildingCanvasesAssets[type], currentBuildComponent.Position, currentBuildComponent.Rotation, currentBuildComponent.Tag); MessageHelper.SendMessageToConsole("Строительство завершено", 8, world); BuildingHelper.ResetBuildingSwitch(assetsEntity.Get <BuildingSwitchesComponent>().buildingsSwitch[type]); buildingCreateEntity.Destroy(); }
public void Run() { var buildingEntities = buildings.Entities.Where(e => e.IsNotNullAndAlive()); foreach (var ent in buildingEntities) { var buildingComponent = ent.Get <BuildingCreateComponent>(); var buildingSwitch = buildingSwitches.Entities.First().Get <BuildingSwitchesComponent>().buildingsSwitch[buildingComponent.Tag.ToString()]; BuildingHelper.ResetBuildingSwitch(buildingSwitch); buildingComponent.Size = buildingSwitch.instancedGreenBuilding.GetComponent <Collider>().bounds.size; var currentVisualisation = buildingComponent.isCanInstall ? buildingSwitch.instancedGreenBuilding : buildingSwitch.instancedRedBuilding; currentVisualisation.transform.position = buildingComponent.Position; currentVisualisation.transform.rotation = Quaternion.Euler(buildingComponent.Rotation); } }
public void Run() { var buildingsEntities = eBuildings.Entities.Where(e => e.IsNotNullAndAlive()); if (buildingsEntities.Count() < 1) { return; } var assetsEntity = assets.Entities.First(); foreach (var e in buildingsEntities.Take(buildingsEntities.Count() - 1)) { BuildingHelper.ResetBuildingSwitch(assetsEntity.Get <BuildingSwitchesComponent>() .buildingsSwitch[e.Get <BuildingCreateComponent>() .Tag .ToString()]); e.Destroy(); } var currentBuild = buildingsEntities.Last().Get <BuildingCreateComponent>(); currentBuild.Position = new Vector3(0, 100, 0); if (EventSystem.current.IsPointerOverGameObject()) { return; } ray = cameras.Get1[0].Camera.ScreenPointToRay(Input.mousePosition); foreach (var terrain in UnityEngine.Object.FindObjectsOfType <Terrain>()) { if (terrain.GetComponent <Collider>().Raycast(ray, out hitInfo, 400)) { var buildingPosition = hitInfo.point; currentBuild.Position.x = Mathf.Round(buildingPosition.x); currentBuild.Position.z = Mathf.Round(buildingPosition.z); currentBuild.Position.y = 0; break; } } }