private void Start() { cam = Camera.main; player = NetworkClient.connection.identity.GetComponent <Player>(); Unit.AuthoryOnUnitDespawn += AuthorityHandleUnitDespawn; Building.AuthorityOnBuildingDespawn += AuthorityHandleBuildingDespawn; GameOverManager.ClientOnGameOver += ClientHandleGameOver; curSelectionType = Selectable.SelectType.UNIT; }
private void ReleaseSelectionBox() { selectionBox.gameObject.SetActive(false); if (selectionBox.sizeDelta.magnitude == 0) { return; } Vector2 min = selectionBox.anchoredPosition - (selectionBox.sizeDelta / 2); Vector2 max = selectionBox.anchoredPosition + (selectionBox.sizeDelta / 2); // FIXME: check if shift still held? // FIXME: Only units can be box selected? if (curSelectionType != Selectable.SelectType.UNIT) { DeselectAll(); } foreach (Unit unit in player.GetAllUnits()) { if (SelectedObjects.Contains((Selectable)unit)) { continue; } Vector3 screenPos = cam.WorldToScreenPoint(unit.transform.position); if (screenPos.x > min.x && screenPos.x < max.x && screenPos.y > min.y && screenPos.y < max.y) { SelectedObjects.Add((Selectable)unit); unit.Select(); } } curSelectionType = Selectable.SelectType.UNIT; }
private void TrySelect() { Ray ray = cam.ScreenPointToRay(Mouse.current.position.ReadValue()); RaycastHit hit; if (!Physics.Raycast(ray, out hit, Mathf.Infinity, selectionMask)) { return; } if (!hit.collider.TryGetComponent <Selectable>(out Selectable s)) { return; } if (!s.hasAuthority) { return; } if (Keyboard.current.shiftKey.isPressed) { if (SelectedObjects.Contains(s)) { SelectedObjects.Remove(s); s.Deselect(); return; } // Only select units of the same base type, i.e. not buildings and units if (s.GetSelectableType() != curSelectionType) { return; } } SelectedObjects.Add(s); s.Select(); curSelectionType = s.GetSelectableType(); }