public void MouseClick(object sender, InputState inputState) { if (!inputState.IsActionActive(ActionType.MouseClick)) { return; } mActive = true; mMousePosition1 = inputState.mMouseWorldPosition; mBox = true; if (mTileMenu.FenceBuildMode || mTileMenu.Visible) { mBox = !mTileMenu.TileSelection(inputState); return; } if (mObjectMenu.FenceBuildMode || mObjectMenu.Visible) { mBox = !mObjectMenu.Selection(inputState); return; } if (!ObjectManager.Instance.GetSelected().Any() && !ObjectManager.Instance.GetQuadTree() .GetGameObjects(new Vector2(mMousePosition1.X, mMousePosition1.Y), true).Any()) { mBox = !mTileMenu.TileSelection(inputState); mObjectMenu.Clear(); } else if (ObjectManager.Instance.GetSelected().Any() && ObjectManager.Instance.GetQuadTree() .GetGameObjects(new Vector2(mMousePosition1.X, mMousePosition1.Y), true) .Any(obj => obj.Selected)) { mBox = !mObjectMenu.Selection(inputState); mTileMenu.Clear(); } else { var selectedTowers = ObjectManager.Instance.GetSelected().Where(obj => obj is Tower).ToList(); ObjectManager.Instance.ClearSelected(); if (!mTileMenu.Visible && !mObjectMenu.Visible) { if (!UnitSelectionBox.Select(ObjectManager.Instance.GetQuadTree() .GetGameObjects(new Vector2(mMousePosition1.X, mMousePosition1.Y), true), true, mMousePosition1)) { mBox = !mTileMenu.TileSelection(inputState); mObjectMenu.Clear(); } } if (selectedTowers.Count > 0) { var selectedEnemies = ObjectManager.Instance.TargetsInRange(InputManager.GetCurrentInputState().mMouseWorldPosition, 1).Where(obj => !obj.Team).Cast <BGameObject>().ToList(); foreach (var tower in selectedTowers) { ((Tower)tower).SetTargets(selectedEnemies, true); } } } }
void OnGUI() { if (isSelecting) { // Create a rect from both mouse positions var rect = UnitSelectionBox.GetScreenRect(mousePosition1, Input.mousePosition); UnitSelectionBox.DrawScreenRect(rect, new Color(0.8f, 0.8f, 0.95f, 0.25f)); UnitSelectionBox.DrawScreenRectBorder(rect, 2, new Color(0.8f, 0.8f, 0.95f)); } }
public bool IsWithinSelectionBounds(GameObject gameObject) { if (!isSelecting) { return(false); } var camera = Camera.main; var viewportBounds = UnitSelectionBox.GetViewportBounds(camera, mousePosition1, Input.mousePosition); return(viewportBounds.Contains( camera.WorldToViewportPoint(gameObject.transform.position))); }
public void Update(InputState inputState, Menu.GameState gameState) { if ((UnitSelectionBox.Instance.Height > 0.2 || UnitSelectionBox.Instance.Width > 0.2) && mActive) { mTileMenu.Clear(); mObjectMenu.Clear(); } if (UnitSelectionBox.Instance.Height > 0.2 || UnitSelectionBox.Instance.Width > 0.2) { ObjectManager.Instance.ClearSelected(); UnitSelectionBox.Select(ObjectManager.Instance.GetQuadTree().GetGameObjects(new Vector2(UnitSelectionBox.Instance.X, UnitSelectionBox.Instance.Y), new Vector2(UnitSelectionBox.Instance.X + UnitSelectionBox.Instance.Width, UnitSelectionBox.Instance.Y + UnitSelectionBox.Instance.Height), true), false, mMousePosition1); } if (mBox) { UnitSelectionBox.Instance.Update(mMousePosition1); } mTileMenu.Update(inputState, gameState); mObjectMenu.Update(inputState, gameState); }