// TODO: Look into right mouse /*void OnMouseOver() { * if (MapMenu.activeSelf) { * //Debug.Log(Input.GetMouseButton(1) + ", " + Input.GetMouseButtonDown(1) + ", " + Input.GetMouseButtonUp(1)); * } * }*/ public void OnMouseDown() { if (tiles == null) { tiles = World.Instance.Tiles; } if (UIMenuController.IsActiveMenu(uiMapEditor)) { Debug("Left: " + Input.GetMouseButton(0) + " Right: " + Input.GetMouseButton(1)); Debug("Should be doing something."); operationManager.BeginDraw(); var gridPos = MouseToGridAPI.GetGridCoordinate(Input.mousePosition); Point point = new Point((int)gridPos.x, (int)gridPos.y); switch (currentTool) { case ToolType.FILL: Fill(point, paintCurrent.ID, tiles[Convert.ToInt32(point.x), Convert.ToInt32(point.y)]); MapDisplayAPI.FinishOperation(); break; case ToolType.LINE: case ToolType.SHAPE: startPoint = point; break; case ToolType.BRUSH: previous = point; break; default: break; } } }
public void OnMouseUp() { if (UIMenuController.IsActiveMenu(uiMapEditor)) { var gridPos = MouseToGridAPI.GetGridCoordinate(Input.mousePosition); Point point = new Point((int)gridPos.x, (int)gridPos.y); switch (currentTool) { case ToolType.LINE: DrawLine(startPoint, point, paintCurrent.ID); MapDisplayAPI.FinishOperation(); break; case ToolType.SHAPE: int distance = (int)(Math.Sqrt(Math.Pow(startPoint.x - point.x, 2) + Math.Pow(startPoint.y - point.y, 2))); int deltaX = Convert.ToInt32(startPoint.x) - Convert.ToInt32(point.x); int deltaY = Convert.ToInt32(startPoint.y) - Convert.ToInt32(point.y); Point center = new Point(startPoint.x - (deltaX / 2), startPoint.y - (deltaY / 2)); DrawWithBrush(center, distance / 2, paintCurrent.ID); MapDisplayAPI.FinishOperation(); break; case ToolType.BRUSH: previous = null; break; default: break; } operationManager.EndDraw(); } }
void OnMouseDrag() { if (UIMenuController.IsActiveMenu(UnitMenu)) { var gridPos = mapCamera.ScreenToWorldPoint(Input.mousePosition); Point point = new Point((int)gridPos.x, (int)gridPos.y); switch (selectedTool) { case Tools.MOVE: if (selectedGO != null) { if (NetworkManager.NetworkInstance.IsServer) { selectedGO.transform.localPosition = new Vector3(point.x, point.y, 0); } else { NetworkManager.NetworkInstance.MoveObject(selectedGO.name, point); } } break; default: break; } } }
void OnMouseUp() { var gridPos = mapCamera.ScreenToWorldPoint(Input.mousePosition); // Record the grid position of where the mouse was released //Debug.Log("OnMouseUp at: [" + gridPos.x + "," + gridPos.y + "]"); if (UIMenuController.IsActiveMenu(UnitMenu)) { Point point = new Point((int)gridPos.x, (int)gridPos.y); switch (selectedTool) { case Tools.MOVE: if (selectedGO != null) { selectedGO.transform.localPosition = new Vector3(point.x, point.y, 0); if (checkForCarrier(selectedGO)) { return; } switch (selectedGO.tag) { case "Surface": case "Subsurface": if (!IsValid(point.x, point.y) || IsLand(point.x, point.y)) { selectedGO.transform.localPosition = origionalPosition; } break; case "Marine": if (!IsValid(point.x, point.y) || !IsLand(point.x, point.y)) { selectedGO.transform.localPosition = origionalPosition; } break; case "Air": if (!IsValid(point.x, point.y)) { selectedGO.transform.localPosition = origionalPosition; } break; default: break; } } break; default: break; } selectedGO = null; } }
void Update() { if (UIMenuController.IsActiveMenu(uiMapEditor)) { if (KeyUndo.Released) { Undo(); } else if (KeyRedo.Released) { Redo(); } else { if (KeyDefaultTerrain.Pressed) { Pick(DEFAULT_CLEAR_TERRAIN); Pick(DEFAULT_PAINT_TERRAIN); } else if (KeySwapTerrain.Pressed) { SwapPick(); } else if (KeyPickWater.Pressed) { Pick("WATER"); } else if (KeyPickLand.Pressed) { Pick("LAND"); } else if (KeyPickUndefined.Pressed) { Pick("UNDEFINED"); } else if (KeyPickMountain.Pressed) { Pick("MOUNTAIN"); } else if (KeyPickWooded.Pressed) { Pick("WOODED"); } else if (KeyPickHeavyBrush.Pressed) { Pick("HEAVY_BRUSH"); } } } }
public void OnMouseDrag() { if (UIMenuController.IsActiveMenu(uiMapEditor)) { var gridPos = MouseToGridAPI.GetGridCoordinate(Input.mousePosition); Point point = new Point((int)gridPos.x, (int)gridPos.y); switch (currentTool) { case ToolType.BRUSH: DrawLine(previous, point, paintCurrent.ID); previous = point; MapDisplayAPI.FinishOperation(); break; default: break; } } }
void OnMouseDown() { var gridPos = mapCamera.ScreenToWorldPoint(Input.mousePosition); timeSinceClick = 0; // Record the grid position of where the mouse was released ////Debug.Log ("OnMouseDown at: [" + gridPos.x + "," + gridPos.y + "]"); Point point = new Point((int)(gridPos.x + 0.5), (int)(gridPos.y + 0.5)); ////Debug.Log ("Point at : [" + point.x + "," + point.y + "]"); if (UIMenuController.IsActiveMenu(UnitMenu)) { GameObject gameObjectToAdd = null; switch (selectedTool) { case Tools.PLACE: try { selectedUnit = unitmanager.GetSelectedUnit(); } catch (Exception) { //Debug.Log ("Selected Unit not found from combobox!"); selectedUnit = ""; } if (!selectedUnit.Equals("")) { switch (selectedUnitType) { case UnitType.AIR: if (IsValid(Convert.ToInt32(point.x), Convert.ToInt32(point.y))) { point.z = -0.0004f; if (NetworkManager.NetworkInstance.IsServer) { gameObjectToAdd = unitFactory.LoadAir(selectedUnit); AddObject(gameObjectToAdd, point); string[] teams = { Team.Teams[TeamComboBox.SelectedIndex].GetTeamName() }; string message = "Admin has spawned an Air unit on team " + teams[0] + " at latitude: " + point.x + " longitude: " + point.y; EventLog.LogManual(EventLog.FormatEventString(teams, Time.time, message)); } else { int teamIndex = TeamComboBox.SelectedIndex; NetworkManager.NetworkInstance.StartObject(selectedUnit, point, Convert.ToString(teamIndex), "0"); } } break; case UnitType.MARINE: if (IsValid(point.x, point.y) && IsLand(point.x, point.y)) { if (NetworkManager.NetworkInstance.IsServer) { gameObjectToAdd = unitFactory.LoadMarine(selectedUnit); AddObject(gameObjectToAdd, point); string[] teams = { Team.Teams[TeamComboBox.SelectedIndex].GetTeamName() }; string message = "Admin has spawned a Marine unit on team " + teams[0] + " at latitude: " + point.x + " longitude: " + point.y; EventLog.LogManual(EventLog.FormatEventString(teams, Time.time, message)); } else { int teamIndex = TeamComboBox.SelectedIndex; NetworkManager.NetworkInstance.StartObject(selectedUnit, point, Convert.ToString(teamIndex), "1"); } } break; case UnitType.SUBSURFACE: if (IsValid(point.x, point.y) && !IsLand(point.x, point.y)) { if (NetworkManager.NetworkInstance.IsServer) { gameObjectToAdd = unitFactory.LoadSubSurface(selectedUnit); gameObjectToAdd.transform.localPosition = new Vector3(point.x, point.y, point.z); AddObject(gameObjectToAdd, point); string[] teams = { Team.Teams[TeamComboBox.SelectedIndex].GetTeamName() }; string message = "Admin has spawned a Subsurface unit on team " + teams[0] + " at latitude: " + point.x + " longitude: " + point.y; EventLog.LogManual(EventLog.FormatEventString(teams, Time.time, message)); } else { int teamIndex = TeamComboBox.SelectedIndex; NetworkManager.NetworkInstance.StartObject(selectedUnit, point, Convert.ToString(teamIndex), "2"); } } break; case UnitType.SURFACE: if (IsValid(point.x, point.y) && !IsLand(point.x, point.y)) { point.z = -.0002f; if (NetworkManager.NetworkInstance.IsServer) { gameObjectToAdd = unitFactory.LoadSurface(selectedUnit); AddObject(gameObjectToAdd, point); string[] teams = { Team.Teams[TeamComboBox.SelectedIndex].GetTeamName() }; string message = "Admin has spawned an Surface unit on team " + teams[0] + " at latitude: " + point.x + " longitude: " + point.y; EventLog.LogManual(EventLog.FormatEventString(teams, Time.time, message)); } else { int teamIndex = TeamComboBox.SelectedIndex; NetworkManager.NetworkInstance.StartObject(selectedUnit, point, Convert.ToString(teamIndex), "3"); } } break; default: break; } } break; case Tools.MOVE: selectedGO = RaycastForObject(); if (selectedGO != null) { if (NetworkManager.NetworkInstance.IsServer) { origionalPosition = selectedGO.transform.localPosition; } else { NetworkManager.NetworkInstance.setObject(selectedGO.GetComponent <IdentityController>().GetGuid()); } } break; case Tools.DELETE: GameObject toDelete = RaycastForObject(); if (toDelete != null) { NetworkManager.NetworkInstance.DestroyUnitOnNetwork(toDelete); // } break; case Tools.EDIT: GameObject toEdit = RaycastForObject(); if (toEdit != null) { if (NetworkManager.NetworkInstance.IsServer) { // Send to editor. unitmanager.SetCurrentObject(toEdit); unitmanager.realObjectSelected = true; unitmanager.RefreshUI(); } else { NetworkManager.NetworkInstance.setObject(selectedGO.GetComponent <IdentityController>().GetGuid()); unitmanager.SetCurrentObject(toEdit); unitmanager.realObjectSelected = true; unitmanager.RefreshUI(); } } break; default: break; } } }