//------------------------------Mouse Button Handler------------------------------ private void MouseClickedHandler(MouseClickEventArgs e) { SelectedManager selectedManager = SelectedManager.main; DragManager dragManager = DragManager.main; HoverManager hoverManager = HoverManager.main; RTSGameObject hoverRTS = hoverManager.getHoverRTSGameObject(); //Place building if (e.buttonType == ButtonType.LeftButton && e.buttonEventType == ButtonEventType.Up) { if (gameMode == GameMode.PlaceBuilding) { if (!readyToPlaceBuilding) //Ready to place the building { readyToPlaceBuilding = true; } else if (canPlaceBuilding) //Place the building //Debug.Log("Building placed"); { readyToPlaceBuilding = false; gameMode = GameMode.Normal; buildingReadyToPlace.GetComponent <Building>().buildingMode = BuildingMode.Construction; buildingReadyToPlace.GetComponent <Building>().objectBase.GetComponent <MeshRenderer>().material = TeamManager.main.player1.matColor; //Set building base to team material color foreach (RTSGameObject rtsGameObject in selectedManager.GetSelectedObjects()) { Worker worker = rtsGameObject.GetComponent <Worker>(); if (worker) { //worker.TravelToPath(buildingReadyToPlace.transform.position); worker.BuildBuilding(buildingReadyToPlace.GetComponent <Building>()); } } } else { Debug.Log("Cant place building here"); } } } //Drag select the RTSGameObjects if (dragManager.isDragging) { if (e.buttonType == ButtonType.LeftButton && e.buttonEventType == ButtonEventType.Down) { //Note: This will never run because you can start dragging on the first click. There is a threshold. } if (e.buttonType == ButtonType.LeftButton && e.buttonEventType == ButtonEventType.Holding) { selectedManager.DeselectAllObjects(); foreach (RTSGameObject rtsGameObject in RTSGameObject.allRTSGameObjects) { if (TeamManager.main.player1.IsRTSAlly(rtsGameObject)) { if (rtsGameObject.unitType == UnitType.Unit) { if (dragManager.IsWithinDragBox(rtsGameObject.transform.position)) { dragManager.SelectObject(rtsGameObject); //selectedManager.SelectObject(rtsGameObject); rtsGameObject.OnHoverDrag(); } else { dragManager.DeselectObject(rtsGameObject); //selectedManager.DeselectObject(rtsGameObject); } } } } } if (e.buttonType == ButtonType.LeftButton && e.buttonEventType == ButtonEventType.Up) { //Note: This will never run because dragManager.isDragging will be false when the button is up. } } else if (dragManager.selectedObjects.Count > 0) { //Select the drag group and clear the drag selection SelectedManager.main.SelectObject(dragManager.selectedObjects); dragManager.selectedObjects.Clear(); } //Select the RTSGameObjects else if (e.buttonType == ButtonType.LeftButton && e.buttonEventType == ButtonEventType.Up) { if (gameMode == GameMode.Normal) //Make sure not to deselect the RTSGameObject while in any other mode (ex. HUD clicking) { if (hoverManager.isHoverRTSObject) //If you are hovering over a RTSGameObject { if (TeamManager.main.player1.IsRTSAlly(hoverRTS)) //Is this RTS friendly { if (hoverRTS.unitType == UnitType.Unit) //Is this RTS a Unit { if (IsShiftDown) { selectedManager.SelectObject(hoverRTS); } else { selectedManager.DeselectAllObjects(); selectedManager.SelectObject(hoverRTS); } } else if (hoverRTS.unitType == UnitType.Building) //Is this RTS a Building { if (selectedManager.GetSelectedObjectsCount() == 0) //If you have nothing selected { selectedManager.SelectObject(hoverRTS); } } } if (TeamManager.main.player1.IsRTSEnemy(hoverRTS)) { if (hoverRTS.unitType == UnitType.Unit) { //Debug.Log("You cant select a enemy unit"); } else if (hoverRTS.unitType == UnitType.Building) { //Debug.Log("You cant select a enemy building"); } } } else { selectedManager.DeselectAllObjects(); } } } }