public void Generate(BuildingPlot plots) //works for only a solitary plot, used for debugging { float height_limits = GM_.Instance.config.building_plot_values.maximum_height - GM_.Instance.config.building_plot_values.minimum_height; float building_height = GM_.Instance.config.building_plot_values.minimum_height + (height_limits * GM_.Instance.procedural.GetPoint(plots.plot_centre.x, plots.plot_centre.y)); //useing perlin noise to decide heights of buildings //reset verticies, tris and UV's indice_triangles = 0; indice_vertices = 0; indice_UV = 0; switch (plots.building_type) //what type of building is in the plot { case Youngs_BuildingType.ROUNDBUILDING: { RoundBuilding(plots, building_height); //generate a cylindrical building break; } case Youngs_BuildingType.BLOCKYBUILDING: { ModernBuilding(plots, building_height); //generate a blocky building break; } case Youngs_BuildingType.TOWERBUILDING: { TowerBuilding(plots, building_height); break; } } }
public Cylinder(BuildingPlot plot, float height, int slices, int slices_skipped, int index_of_skipped) { number_vertices = (slices + 1 - slices_skipped * 2) * 4 + 2; number_triangles = (slices - slices_skipped * 2) * 12; vertices = new Vector3[number_vertices]; triangles = new int[number_triangles]; uv = new Vector2[number_vertices]; float x; float y; float radius_x = plot.plot_dimensions.x / 2; float radius_y = plot.plot_dimensions.y / 2; for (int i = 0, j = 0; i <= slices; i++, j += 2) { x = radius_x * Mathf.Cos(2 * Mathf.PI * i / slices); y = radius_y * Mathf.Sin(2 * Mathf.PI * i / slices); uv[j] = new Vector2(1f / slices * i, 0); uv[j + ((slices + 1 - slices_skipped * 2)) * 2] = new Vector2(uv[j].x, 1); uv[j + 1] = new Vector2(1f / slices * i, 0); uv[j + 1 + ((slices + 1 - slices_skipped * 2)) * 2] = new Vector2(uv[j].x, 1); if (i == index_of_skipped || i == slices - index_of_skipped - slices_skipped) { i += slices_skipped; } vertices[j] = new Vector3(x + 0 / 2, 0, y + 0 / 2); vertices[j + ((slices + 1 - slices_skipped * 2)) * 2] = new Vector3(x + 0 / 2, height, y + 0 / 2); vertices[j + 1] = vertices[j]; vertices[j + 1 + ((slices + 1 - slices_skipped * 2)) * 2] = new Vector3(x + 0 / 2, height, y + 0 / 2); } vertices[number_vertices - 2] = new Vector3(0 / 2, 0, 0 / 2); vertices[number_vertices - 1] = new Vector3(0 / 2, height, 0 / 2); uv[number_vertices - 2] = new Vector2(0, 0); uv[number_vertices - 1] = new Vector2(1, 1); int number_triangles_body = number_triangles - ((slices - slices_skipped * 2) * 6); for (int i = 0, k = 0; i < number_triangles_body; i += 6, k += 2) { triangles[i] = triangles[i + 3] = k; triangles[i + 1] = k + ((slices + 1 - slices_skipped * 2)) * 2; triangles[i + 2] = triangles[i + 4] = k + ((slices - slices_skipped * 2) + 2) * 2; triangles[i + 5] = k + 2; } for (int i = 0, k = 0; k < ((slices - slices_skipped * 2) * 2); i += 6, k += 2) { triangles[i + number_triangles_body] = k + 1; triangles[i + number_triangles_body + 1] = k + 3; triangles[i + number_triangles_body + 2] = number_vertices - 2; triangles[i + number_triangles_body + 3] = k + (slices + 1 - slices_skipped * 2) * 2 + 3; triangles[i + number_triangles_body + 4] = k + (slices + 1 - slices_skipped * 2) * 2 + 1; triangles[i + number_triangles_body + 5] = number_vertices - 1; } }
public List <BuildingPlot> GeneratePlots(List <CityBlock> city_blocks) { List <BuildingPlot> plots = new List <BuildingPlot>(); foreach (CityBlock block in city_blocks) //loop for each city block { foreach (Plot plot in block.GetLots()) //loop for each plot in the city block { //create a building plot BuildingPlot bp = new BuildingPlot(); //set min and max x plot.vertexes = plot.vertexes.OrderBy(v => v.x).ToList(); float min_x = plot.vertexes[0].x; float max_x = plot.vertexes[plot.vertexes.Count - 1].x; //set min and max z plot.vertexes = plot.vertexes.OrderBy(v => v.z).ToList(); float min_z = plot.vertexes[0].z; float max_z = plot.vertexes[plot.vertexes.Count - 1].z; //initilise plot bp.InitPlot(new Vector3((min_x + max_x) / 2, 0.1f, (min_z + max_z) / 2), new Vector2(max_x - (min_x + max_x) / 2, max_z - (min_z + max_z) / 2) * 2, SetType(Random.Range(0, GM_.Instance.config.building_plot_values.likelihood)), GM_.Instance.config.city_transform.transform, plot.type == CityBlockType.BUILDING ? false : true); plots.Add(bp); //store the plot } } return(plots); }
public void Refresh(BuildingPlot plot) { buildingPlot = plot; buttons.ForEach((btn) => { btn.UpdateResources(); }); }
void TowerBuilding(BuildingPlot plot, float maximum_height) { int tiers = Random.Range(3, 6); //determin the maount of teirs in the towe Color colour = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1); //get a colour to make the building //set the amount of verticies, tries and UV's will be needed vertices = new Vector3[24 * tiers + 12]; triangles = new int[36 * tiers + 12]; uv = new Vector2[24 * tiers + 12]; //setup initial values for the generation of a tower building float random_distribution = Random.Range(0.5f, 0.8f); float height = Random.Range(random_distribution * maximum_height, maximum_height); float difference = height - random_distribution * maximum_height; float last_height = random_distribution * maximum_height; Vector3 lb = new Vector3(0, 0, 0); Vector3 rt = new Vector3(plot.plot_dimensions.x, last_height, plot.plot_dimensions.y); GameObject new_building = new GameObject("tower building"); new_building.transform.position = plot.plot_centre; Block block = new Block(lb, rt, window_size); GameObject building_block = new GameObject("block"); building_block.AddComponent <MeshCollider>(); CreateMesh(building_block, block.GetVertices(), block.GetTriangles(), block.GetUV(), colour); new_building.transform.parent = plot.city_transform; building_block.transform.parent = new_building.transform; building_block.transform.localPosition = new Vector3(0, 0, 0); new_building.transform.localPosition += new Vector3(-plot.plot_dimensions.x / 2, 0, -plot.plot_dimensions.y / 2); //loop for all the teirs and create blocks between the height of the last box and the hight of a new block for (int i = 1; i < tiers; i++) { lb = new Vector3(lb.x + (1 * i), last_height, lb.z + (1 * i)); rt = new Vector3(rt.x - (1 * i), last_height + (difference / i), rt.z - (1 * i)); block = new Block(lb, rt, window_size); AddVertices(block.GetVertices(), block.GetTriangles(), block.GetUV()); last_height += (difference / i); building_block = new GameObject("block"); building_block.AddComponent <MeshCollider>(); CreateMesh(building_block, block.GetVertices(), block.GetTriangles(), block.GetUV(), colour); building_block.transform.parent = new_building.transform; building_block.transform.localPosition = new Vector3(0, 0, 0); } }
public void CreateBuildingPlot(GameObject buildingPlot, RoomBlueprint roomBlueprint, Vector2 startingPoint, ObjectRotation roomRotation) { if (BuilderManager.Instance.BuildingPlots.ContainsKey(startingPoint)) { return; } BuildingPlot plot = Instantiate(buildingPlot, transform).GetComponent <BuildingPlot>(); BuilderManager.Instance.BuildingPlots.Add(startingPoint, plot); //Logger.Log("The starting points for this plot should be {0}", startingPoint); plot.Setup(roomBlueprint, startingPoint, roomRotation); }
void SelectPlot(BuildingPlot plot) { if (selectedBuildingPlot == plot) { return; } UnselectAll(); if (plot) { selectedBuildingPlot = plot; ui.SelectBuildingPlot(plot); } }
public void OnClickBuildingPlot(GameEvent gameEvent) { if (waitingOnPlayer) { BuildingPlot buildingPlotClicked = (BuildingPlot)gameEvent.GetData("buildingPlot").dataObject; waitingOnPlayer = false; HighlightAllBuildingPlots(false); //raise the event List <DataHolder> dataHoldersList = new List <DataHolder>(); dataHoldersList.Add(new DataHolder("buildingPlot", buildingPlotClicked)); response.Raise(dataHoldersList, this); } }
void RoundBuilding(BuildingPlot plot, float height) { //determine the colour Color colour = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1); //create a block to cover the base of the building GameObject base_ = new GameObject("base"); Vector3 lb = new Vector3(0, 0, 0); Vector3 rt = new Vector3(plot.plot_dimensions.x, 0.05f, plot.plot_dimensions.y); vertices = new Vector3[24]; triangles = new int[36]; uv = new Vector2[24]; Block block = new Block(lb, rt, window_size); AddVertices(block.GetVertices(), block.GetTriangles(), block.GetUV()); CreateMesh(base_, vertices, triangles, uv, colour); //now create the cylinder mesh int slices = 36; //amount of slices that make up the cylinder int slices_skipped = Random.Range(0, 12); //the amount of slices that will be skippped int index_skipped = Random.Range(3, slices / 2 - slices_skipped - 3); //the itteration at whichthey will be skipped vertices = new Vector3[(slices + 1 - slices_skipped * 2) * 4 + 50]; triangles = new int[(slices - slices_skipped * 2) * 12 + 72]; uv = new Vector2[(slices + 1 - slices_skipped * 2) * 4 + 50]; //generation of the cylinder Cylinder cylinder = new Cylinder(plot, height, slices, slices_skipped, index_skipped); AddVertices(cylinder.GetVertices(), cylinder.GetTriangles(), cylinder.GetUV()); //creating the gameobject GameObject new_building = new GameObject("round building"); CreateMesh(new_building, vertices, triangles, uv, colour); new_building.transform.parent = plot.city_transform; new_building.transform.position = plot.plot_centre; //centre the building in the middle of the plot base_.transform.parent = new_building.transform; base_.transform.localPosition = new Vector3(0, 0, 0); base_.transform.localPosition += new Vector3(-plot.plot_dimensions.x / 2, 0, -plot.plot_dimensions.y / 2); }
public void Init(BuildingPlot plot) { buttonContainerTransform = transform.Find("ButtonContainer"); plot.onDestroyed += OnPlotDestroyed; for (int i = 0; i < System.Enum.GetValues(typeof(BuildButton.Type)).Length; i++) { GameObject buildButtonGO = Instantiate(buildButtonPrefab, Vector3.zero, Quaternion.identity, buttonContainerTransform); BuildButton btn = buildButtonGO.GetComponent <BuildButton> (); btn.Init((BuildButton.Type)i); btn.button.onClick.AddListener(() => { if (onBuildButtonClicked != null) { onBuildButtonClicked(btn, plot); } }); buttons.Add(btn); } }
public override List <DataObject> Solve(List <DataObject> dataArray) { BuildingPlot nwBuildingPlot = null; int randomIndex = Random.Range(0, BuildingPlot.buildingPlots.Count); nwBuildingPlot = BuildingPlot.buildingPlots[randomIndex]; if (nwBuildingPlot == null) { Debug.Log("ProvideBuildingPlot could not be resolved, it could not find BuildingPlots"); return(dataArray); } // only do something and alter the dataArray if it is certain this entire action can be resolved! DataObject nwDataObject = new DataObject(DataObject.ObjectTypes.BuildingPlot, nwBuildingPlot.GetComponent <BuildingPlot>());//new DataObject().Setup(DataObject.ObjectTypes.BuildingPlot, nwBuildingPlot.GetComponent<BuildingPlot>()); dataArray.Add(nwDataObject); return(base.Solve(dataArray)); }
public void SelectBuildingPlot(BuildingPlot plot) { if (selectedBuildPlot && selectedBuildPlot.buildingPlot == plot) { //Do nothing if it's the same plot return; } if (selectedBuildPlot != null) { UnselectBuildingPlot(); } GameObject plotGO = Instantiate(buildPlotUIPrefab, Camera.main.WorldToScreenPoint(plot.transform.position), Quaternion.identity, canvasTransform); plotGO.name = "SelectedBuildPlotUI"; selectedBuildPlot = plotGO.GetComponent <BuildPlotUI> (); selectedBuildPlot.onBuildButtonClicked += OnBuildButtonClicked; selectedBuildPlot.onBuildPlotDestroyed += OnPlotDestroyed; selectedBuildPlot.Init(plot); }
void OnBuildButtonClicked(BuildButton btn, BuildingPlot plot) { Debug.Log("Clicked building button: " + btn.type); UnselectBuildingPlot(); plot.ChooseBuilding(btn.type); }
// Use this for initialization void Start() { buildingPlotScript = (BuildingPlot)buildingPLot.GetComponent(typeof(BuildingPlot)); Invoke("setInfo", 0.1f); }
// Use this for initialization void Start() { buildingPlotScript = (BuildingPlot)buildingPLot.GetComponent(typeof(BuildingPlot)); }
public void BuildRoom(RoomBlueprint roomBlueprint, BuildingPlot buildingPlot) { _roomBuilder.BuildRoom(roomBlueprint, _buildingTileBuilder, _buildingPlotBuilder, buildingPlot); }
public void BuildRoom(RoomBlueprint roomBlueprint, BuildingTileBuilder buildingTileBuilder, BuildingPlotBuilder buildingPlotBuilder, BuildingPlot buildingPlot) { BuildRoom(roomBlueprint, buildingTileBuilder, buildingPlotBuilder, buildingPlot.StartingPoint, buildingPlot.PlotRotation); }
public void Update() { if (Console.Instance && Console.Instance.ConsoleState == ConsoleState.Large) { return; } if (PointerImage.sprite != null) { Vector2 mousePosition = Input.mousePosition; bool isPointerOverGameObject = PointerHelper.IsPointerOverGameObject(); if (isPointerOverGameObject && BuildMenuContainer.Instance.IsOpen) { PointerImageGO.transform.position = new Vector2(mousePosition.x, mousePosition.y); } else { if (BuildMenuContainer.Instance.IsOpen) { Logger.Log(Logger.UI, "Close build menu"); BuildMenuContainer.Instance.ActivateAnimationFreeze(); BuildMenuContainer.Instance.IsOpen = false; BuildMenuContainer.Instance.RemoveBuildMenuContent(0.5f); } Vector2 mouseWorldPosition = Camera.main.ScreenToWorldPoint(mousePosition); mouseWorldPosition = new Vector2(mouseWorldPosition.x, mouseWorldPosition.y + 7.5f); float xx = Mathf.Round((mouseWorldPosition.y) / TileSizeInUnits.y + (mouseWorldPosition.x) / TileSizeInUnits.x); float yy = Mathf.Round((mouseWorldPosition.y) / TileSizeInUnits.y - (mouseWorldPosition.x) / TileSizeInUnits.x) - 1; // Calculate grid aligned position from current position float snappedX = (xx - yy) * 0.5f * TileSizeInUnits.x; float snappedY = (xx + yy) * 0.5f * TileSizeInUnits.y; if (_currentSnappedX != snappedX || _currentSnappedY != snappedY) { _currentSnappedX = snappedX; _currentSnappedY = snappedY; if (BuilderManager.Instance.BuildingPlotLocations.ContainsKey(new Vector2(_currentSnappedX, _currentSnappedY))) { Vector2 availablePlotVectorPosition = BuilderManager.Instance.BuildingPlotLocations[new Vector2(_currentSnappedX, _currentSnappedY)]; if (BuildingPlot.AvailablePlotVectorPosition == availablePlotVectorPosition && BuilderManager.PointerIsOnAvailablePlot) { return; } BuildingPlot.AvailablePlotVectorPosition = availablePlotVectorPosition; SetPointerImageOverlayColor(PointerImageOverlayState.Normal); BuilderManager.PointerIsOnAvailablePlot = true; BuildingPlot buildingPlot = BuilderManager.Instance.BuildingPlots[BuildingPlot.AvailablePlotVectorPosition]; Sprite roomIcon = GetRoomIcon(buildingPlot.RoomBlueprint.Name, buildingPlot.PlotRotation); SetPointerImage(roomIcon, buildingPlot.PlotRotation); RepositionImage(); } else { if (BuilderManager.PointerIsOnAvailablePlot) { BuilderManager.PointerIsOnAvailablePlot = false; } if (_currentPointerImageOverlayState == PointerImageOverlayState.Normal) { SetPointerImageOverlayColor(PointerImageOverlayState.Red); } RepositionImage(); } } } if (GameManager.Instance.CurrentPlatform == Platform.PC) { if (BuildMenuContainer.Instance.PanelAnimationPlaying) { return; } if (Input.GetMouseButtonDown(1)) { UnsetPointerImage(); if (!BuildMenuContainer.Instance.IsOpen) { BuildMenuContainer.Instance.ActivateAnimationFreeze(); BuilderManager.Instance.ActivateBuildMenuMode(); } } } } }
public static BuildingPlot FindBuildingPlot(Vector2 startingPoint) { BuildingPlot buildingPlot = BuilderManager.Instance.BuildingPlots[startingPoint]; return(buildingPlot); }
void ModernBuilding(BuildingPlot plot, float maximum_height) { //set the colour Color colour = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f), 1); //init variables float minHeight; Vector3 lbMain, rtMain; Vector3 lb, rt; List <int> directions = new List <int>(); directions.Add(0); directions.Add(1); directions.Add(2); directions.Add(3); int wings_limit = Random.Range(1, 5); vertices = new Vector3[24 * (wings_limit + 2)]; triangles = new int[36 * (wings_limit + 2)]; uv = new Vector2[24 * (wings_limit + 2)]; //create the base minHeight = 0.005F; lb = new Vector3(0, 0, 0); rt = new Vector3(plot.plot_dimensions.x, minHeight, plot.plot_dimensions.y); Block block = new Block(lb, rt, window_size); AddVertices(block.GetVertices(), block.GetTriangles(), block.GetUV()); //create the main tower float height = Random.Range(maximum_height * 0.7f, maximum_height); lbMain = new Vector3(Random.Range(0f, plot.plot_dimensions.x * 0.4f), minHeight, Random.Range(0f, plot.plot_dimensions.y * 0.4f)); rtMain = new Vector3(plot.plot_dimensions.x * 0.6f + Random.Range(0f, plot.plot_dimensions.x * 0.4f), height, plot.plot_dimensions.y * 0.6f + Random.Range(0f, plot.plot_dimensions.y * 0.4f)); block = new Block(lbMain, rtMain, window_size); AddVertices(block.GetVertices(), block.GetTriangles(), block.GetUV()); maximum_height = height; //create the wings GameObject new_building = new GameObject("modern building"); for (int i = 0; i < 3; i++) { height = Random.Range(maximum_height * 0.75f, maximum_height); int direction = directions[Random.Range(0, directions.Count)]; directions.Remove(direction); switch (direction) { case 0: lb = new Vector3(Random.Range(lbMain.x, 0.5f * plot.plot_dimensions.x), minHeight, Random.Range(0.5f * plot.plot_dimensions.y, lbMain.z)); rt = new Vector3(Random.Range(0.5f * plot.plot_dimensions.x, rtMain.x), height, plot.plot_dimensions.y); break; case 1: lb = new Vector3(Random.Range(lbMain.x, 0.5f * plot.plot_dimensions.x), minHeight, Random.Range(0.5f * plot.plot_dimensions.y, lbMain.z)); rt = new Vector3(plot.plot_dimensions.x, height, Random.Range(rtMain.z, plot.plot_dimensions.y * 0.5f)); break; case 2: lb = new Vector3(0f, minHeight, Random.Range(0.5f * plot.plot_dimensions.y, lbMain.z)); rt = new Vector3(Random.Range(0.5f * plot.plot_dimensions.x, rtMain.x), height, Random.Range(rtMain.z, plot.plot_dimensions.y * 0.5f)); break; case 3: lb = new Vector3(Random.Range(lbMain.x, 0.5f * plot.plot_dimensions.x), minHeight, 0f); rt = new Vector3(Random.Range(0.5f * plot.plot_dimensions.x, rtMain.x), height, Random.Range(rtMain.z, plot.plot_dimensions.y * 0.5f)); break; } //create the new block block = new Block(lb, rt, window_size); GameObject building_block = new GameObject("modern building"); building_block.AddComponent <MeshCollider>(); CreateMesh(building_block, block.GetVertices(), block.GetTriangles(), block.GetUV(), colour); building_block.transform.parent = new_building.transform; maximum_height = height; } //create the shape CreateMesh(new_building, vertices, triangles, uv, colour); //centre the block on the plot new_building.transform.parent = plot.city_transform; new_building.transform.localPosition = plot.plot_centre - new Vector3(plot.plot_dimensions.x / 2, 0, plot.plot_dimensions.y / 2); }
/// <summary> /// Construct the building class instance from the given properties. /// </summary> /// <param name="type" type="BuildingType">type</param> /// <param name="plot">The plot of land this building stands on, note it might be bigger than the /// actual buildings footprint, for example if it is part of a larger complex, limit the size of /// buildings to have a footprint of no more than 100 square meters.</param> /// <param name="flags"></param> /// <param name="owner">The owner of the building either a user, or company (group of companies) own buildings.</param> /// <param name="seed"></param> /// <param name="height">The height in floors of the building, not each floor is approximately 3 meters in size /// and thus buildings are limited to a maximum height of 100 floors.</param> public ICityBuilding(BuildingType type, BuildingPlot plot, BuildingFlags flags, UUID owner, IScene scene, string name) : base(owner, new Vector3(plot.XPos, 21, plot.YPos), Quaternion.Identity, PrimitiveBaseShape.CreateBox(), name, scene) { // Start the process of constructing a building given the parameters specified. For // truly random buildings change the following value (6) too another number, this is // used to allow for the buildings to be fairly fixed during research and development. BuildingSeed = 6; // TODO FIX ACCESS TO THE CityModule.randomValue(n) code. BuildingType = type; BuildingPlot = plot; BuildingFlags = flags; // Has a valid owner been specified, if not use the default library owner (i think) of the zero uuid. if (!owner.Equals(UUID.Zero)) { BuildingOwner = owner; } else { BuildingOwner = UUID.Zero; } // Generate a unique value for this building and it's own group if it's part of a complex, // otherwise use the zero uuid for group (perhaps it should inherit from the city?) BuildingUUID = UUID.Random(); BuildingGUID = UUID.Random(); BuildingCenter = new Vector3((plot.XPos + plot.Width / 2), 21, (plot.YPos + plot.Depth) / 2); if (name.Length > 0) { BuildingName = name; } else { BuildingName = "Building" + type.ToString(); } // Now that internal variables that are used by other methods have been set construct // the building based on the type, plot, flags and seed given in the parameters. switch (type) { case BuildingType.BUILDING_GENERAL: OpenSim.Framework.MainConsole.Instance.Output("Building Type GENERAL", log4net.Core.Level.Info); //createBlocky(); break; case BuildingType.BUILDING_LOCALE: /* * switch ( CityModule.randomValue(8) ) * { * case 0: * OpenSim.Framework.MainConsole.Instance.Output("Locale general.", log4net.Core.Level.Info); * createSimple(); * break; * case 1: * OpenSim.Framework.MainConsole.Instance.Output("locale 1", log4net.Core.Level.Info); * createBlocky(); * break; * } */ break; case BuildingType.BUILDING_CIVIL: //createTower(); break; case BuildingType.BUILDING_MILITARY: break; case BuildingType.BUILDING_HEALTHCARE: break; case BuildingType.BUILDING_SPORTS: break; case BuildingType.BUILDING_ENTERTAINMENT: break; case BuildingType.BUILDING_EDUCATION: break; case BuildingType.BUILDING_RELIGIOUS: break; case BuildingType.BUILDING_MUSEUM: break; case BuildingType.BUILDING_POWERSTATION: break; case BuildingType.BUILDING_MINEOILGAS: break; case BuildingType.BUILDING_ZOOLOGICAL: break; case BuildingType.BUILDING_CEMETARY: break; case BuildingType.BUILDING_PRISON: break; case BuildingType.BUILDING_AGRICULTURAL: break; case BuildingType.BUILDING_RECREATION: break; default: //createSimple(); break; } }
void UnselectPlot() { selectedBuildingPlot = null; ui.UnselectBuildingPlot(); }
void UpdateInput() { if (Input.GetMouseButtonDown(0)) { if (mode == Mode.Selection) { //Unselect all units and plots on left-click, always. UnselectAll(); if (!EventSystem.current.IsPointerOverGameObject()) { UnselectPlot(); } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit)) { //If a left-click hits a unit, select it. Unit hitUnit = hit.transform.GetComponent <Unit> (); if (hitUnit) { Select(hitUnit); } else { BuildingPlot plot = hit.transform.GetComponent <BuildingPlot> (); if (plot) { SelectPlot(plot); } } } } else { if (cursor) { if (cursor.CanBuild() && cursor.transform.position.y < maxBuildHeight) { Debug.Log(cursor.gameObject.transform.position); GameObject newPlot = Instantiate(buildingPlotPrefab, cursor.transform.position, Quaternion.identity); ToggleMode(); ui.SelectBuildingPlot(newPlot.gameObject.GetComponent <BuildingPlot>()); } } else { cursor = ui.GetCursor(); } } } if (Input.GetMouseButtonDown(1) && selected.Count > 0) { //On a right-click, try to give orders to selected units, if there are any. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit)) { //If a left click hits a unit, select it. Targetable hitTarget = hit.transform.gameObject.GetComponent <Targetable> (); if (hitTarget) { Debug.Log("hit target"); //Pass hit object and hit position to every unit, let them figure out what to do with it. foreach (Unit u in selected) { u.Order(hitTarget, hit.point); } } } } if (Input.GetAxis("Drop") > 0) { foreach (Unit u in selected) { u.DropItems(); } ui.ShowDropText(false); } if (Input.GetKeyDown(KeyCode.B)) { ToggleMode(); } }
void Update() { if (InBuildMode && MainCanvas.Instance.IsDraggingIcon && !BuildMenuContainer.Instance.IsOpen) { if (PointerIsOnAvailablePlot) { if (GameManager.Instance.CurrentPlatform == Platform.PC) { if (Input.GetMouseButtonDown(0)) { Logger.Warning("Let's build a {0}", SelectedRoom.Name); BuildingPlot buildingPlot = BuildingPlot.FindBuildingPlot(BuildingPlot.AvailablePlotVectorPosition); BuildRoom(SelectedRoom, buildingPlot); if (BuildMenuContainer.Instance.PanelAnimationPlaying) { ReopenBuildMenu(); } else { BuildMenuContainer.Instance.ActivateAnimationFreeze(); ActivateBuildMenuMode(); } } } } else { if (GameManager.Instance.CurrentPlatform == Platform.PC) { if (Input.GetMouseButtonDown(0)) { Logger.Warning("Cannot build here!"); GameObject notificationGO = Instantiate(MainCanvas.Instance.NotificationPrefab, MainCanvas.Instance.transform); Notification notification = notificationGO.transform.GetComponent <Notification>(); notification.Setup(NotificationType.FromPointer, "Cannot build in location"); if (BuildMenuContainer.Instance.PanelAnimationPlaying) { ReopenBuildMenu(); } else { BuildMenuContainer.Instance.ActivateAnimationFreeze(); ActivateBuildMenuMode(); } } } } } if (Input.touchCount == 1) { if (Input.touches[0].phase == TouchPhase.Ended) { if (MainCanvas.Instance.PointerImage.sprite != null && !BuildMenuContainer.Instance.IsOpen) { if (PointerIsOnAvailablePlot) { Logger.Warning("Let's build!"); BuildingPlot buildingPlot = BuildingPlot.FindBuildingPlot(BuildingPlot.AvailablePlotVectorPosition); BuildRoom(SelectedRoom, buildingPlot); } else { if (MainCanvas.Instance.IsDraggingIcon && !BuildMenuContainer.Instance.IsOpen) { GameObject notificationGO = Instantiate(MainCanvas.Instance.NotificationPrefab, MainCanvas.Instance.transform); Notification notification = notificationGO.transform.GetComponent <Notification>(); notification.Setup(NotificationType.FromPointer, "Cannot build in location"); } } if (BuildMenuContainer.Instance.PanelAnimationPlaying) { ReopenBuildMenu(); } else { BuildMenuContainer.Instance.ActivateAnimationFreeze(); ActivateBuildMenuMode(); } } else { MainCanvas.Instance.UnsetPointerImage(); } } } if (ConfirmationModal.CurrentConfirmationModal != null) { if (Input.GetMouseButtonDown(0) || (Input.touchCount == 1 && Input.touches[0].phase == TouchPhase.Began)) { bool isPointerOverGameObject = PointerHelper.IsPointerOverGameObject(); if (!isPointerOverGameObject) { ConfirmationModal.CurrentConfirmationModal.ResetDeleteTrigger(); ConfirmationModal.CurrentConfirmationModal.DestroyConfirmationModal(); } } } }