private void SelectSingleUnit() { if (selectedUnit != null) { if (selectedTable.getDictionary().Keys.Count > 0) { // foreach (KeyValuePair<int, GameObject> entry in selectedTable.getDictionary() ) //{ //currentlySelectedUnits[i].transform.Find("SelectionCircle").gameObject.SetActive(false); //RemoveFromCurrentlySelectedUnits(currentlySelectedUnits[i]); // selectedTable.deselect(entry.Key); //} selectedTable.deselectAll(); } else if (selectedTable.getDictionary().Keys.Count == 0) { //AddToCurrentlySelectedUnits(selectedUnit); selectedTable.addSelected(selectedUnit); selectFSM = SelectFSM.clickOrDrag; } } else { Debug.Log("Whaaat?"); } }
private void DeselectAll() { foreach (GameObject selected in currentlySelectedUnits) { RemoveFromCurrentlySelectedUnits(selected); } selectFSM = SelectFSM.clickOrDrag; }
private void SelectSingleUnit() { DeselectAll(); if (selectedUnit) { AddToCurrentlySelectedUnits(selectedUnit); selectFSM = SelectFSM.clickOrDrag; } }
private void ClickOrDrag() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity) && /** !EventSystem.current.IsPointerOverGameObject() && **/ !UnitManager.instance.buildMode) { currentMousePoint = hit.point; if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDownPoint = hit.point; mouseDragStartPosition = Input.mousePosition; //click to select unit, or click the ground to deselect all if (hit.collider.gameObject.tag == "Unit") { selectedUnit = hit.collider.gameObject; selectFSM = SelectFSM.clickSelect; } else if (hit.collider.gameObject.tag == "Ground") { selectedTable.deselectAll(); } //selectFSM = SelectFSM.clickDeselect; } else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift)) { //holding shift, click to select units or click selected units to deselect if (hit.collider.gameObject.tag == "Unit" && !selectedTable.getDictionary().ContainsKey(hit.collider.gameObject.GetInstanceID())) { //AddToCurrentlySelectedUnits(hit.collider.gameObject); selectedTable.addSelected(hit.collider.gameObject); } else if (hit.collider.gameObject.tag == "Unit" && selectedTable.getDictionary().ContainsKey(hit.collider.gameObject.GetInstanceID())) { //RemoveFromCurrentlySelectedUnits(hit.collider.gameObject); selectedTable.deselect(hit.collider.gameObject.GetInstanceID()); } } else if (Input.GetMouseButton(0) && !Input.GetKey(KeyCode.LeftShift)) { if (UserDraggingByPosition(mouseDragStartPosition, Input.mousePosition)) { mouseDragging = true; DrawDragBox(); SelectUnitsInDrag(); } } else if (Input.GetMouseButtonUp(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDragging = false; } } }
private void DeselectAll() { if (currentSelectedObjects.Count > 0) { RemoveSelectedObjects(); } else if (currentSelectedObjects.Count == 0) { selectFSM = SelectFSM.clickOrDrag; } }
private void ClickOrDrag() { Ray ray = m_cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity) && !EventSystem.current.IsPointerOverGameObject()) { currentMousePoint = hit.point; if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDownPoint = hit.point; mouseDragStartPosition = Input.mousePosition; print(hit.collider.gameObject.name); //click to select unit, or click the ground to deselect all if (hit.collider.gameObject.tag == "Selectable") { selectedUnit = hit.collider.transform.parent.gameObject; selectFSM = SelectFSM.clickSelect; } else /*if (hit.collider.gameObject.tag == "Terrain")*/ { selectFSM = SelectFSM.clickDeselect; } } else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift)) { //holding shift, click to select units or click selected units to deselect if (hit.collider.gameObject.tag == "Selectable" && !currentlySelectedUnits.Contains(hit.collider.gameObject)) { AddToCurrentlySelectedUnits(hit.collider.transform.parent.gameObject); } else if (hit.collider.gameObject.tag == "Selectable" && currentlySelectedUnits.Contains(hit.collider.gameObject)) { RemoveFromCurrentlySelectedUnits(hit.collider.transform.parent.gameObject); } } else if (Input.GetMouseButton(0) && !Input.GetKey(KeyCode.LeftShift)) { if (UserDraggingByPosition(mouseDragStartPosition, Input.mousePosition)) { mouseDragging = true; DrawDragBox(); SelectUnitsInDrag(); } } else if (Input.GetMouseButtonUp(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDragging = false; } } }
private void DeselectAll() { if (currentlySelectedUnits.Count > 0) { for (int i = 0; i < currentlySelectedUnits.Count; i++) { currentlySelectedUnits[i].transform.Find("SelectionCircle").gameObject.SetActive(false); currentlySelectedUnits.Remove(currentlySelectedUnits[i]); } } else if (currentlySelectedUnits.Count == 0) { selectFSM = SelectFSM.clickOrDrag; } }
private void SelectSingleObject() { if (selectedObject != null) { if (currentSelectedObjects.Count > 0) { RemoveSelectedObjects(); } else if (currentSelectedObjects.Count == 0) { AddToCurrentSelectedObjects(selectedObject); selectFSM = SelectFSM.clickOrDrag; } } }
private void DeselectAll() { if (_currentEntity.Count > 0) { for (int i = 0; i < _currentEntity.Count; i++) { _currentEntity[i].GetComponent <Entity> ().IsDeselected(); _currentEntity.Remove(_currentEntity[i]); } } else if (_currentEntity.Count == 0) { selectFSM = SelectFSM.clickOrDrag; } }
private void ClickOrDrag() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit) && !EventSystem.current.IsPointerOverGameObject()) { currentMousePoint = hit.point; if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDownPoint = hit.point; mouseDragStartPosition = Input.mousePosition; //click to select unit, or click the ground to deselect all if (hit.collider.gameObject.tag == "Enemy") { selectedUnit = hit.collider.gameObject; selectFSM = SelectFSM.clickSelect; } else if (hit.collider.gameObject.tag == "Ground") { selectFSM = SelectFSM.clickDeselect; } } /*else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift)) * { * //holding shift, click to select units or click selected units to deselect * if (hit.collider.gameObject.tag == "Unit" && !currentlySelectedUnits.Contains(hit.collider.gameObject)) * AddToCurrentlySelectedUnits(hit.collider.gameObject); * else if (hit.collider.gameObject.tag == "Unit" && currentlySelectedUnits.Contains(hit.collider.gameObject)) * RemoveFromCurrentlySelectedUnits(hit.collider.gameObject); * }*/ else if (Input.GetMouseButton(0) && !Input.GetKey(KeyCode.LeftShift)) { if (UserDraggingByPosition(mouseDragStartPosition, Input.mousePosition)) { mouseDragging = true; DrawDragBox(); SelectUnitsInDrag(); } } else if (Input.GetMouseButtonUp(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDragging = false; } } }
private void DeselectAll() { selectedUnit = null; if (currentlySelectedUnits.Count > 0) { for (int i = 0; i < currentlySelectedUnits.Count; i++) { currentlySelectedUnits[i].GetComponent <Soldier>().m_canvas.enabled = false; currentlySelectedUnits[i].GetComponent <Soldier>().selected = false; currentlySelectedUnits.Remove(currentlySelectedUnits[i]); } } else if (currentlySelectedUnits.Count == 0) { selectFSM = SelectFSM.clickOrDrag; } }
private void ClickOrDrag() { Ray ray = UnityEngine.Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { currentMousePoint = hit.point; mouseDragStartPosition = Input.mousePosition; if (hit.collider.gameObject.tag == "Unit") { selectedObject = hit.collider.gameObject; selectFSM = SelectFSM.clickSelect; } else if (hit.collider.gameObject.tag == "Ground") { selectFSM = SelectFSM.clickDeselct; } } else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift)) { if (hit.collider.gameObject.tag == "Unit" && !currentSelectedObjects.Contains(hit.collider.gameObject)) { AddToCurrentSelectedObjects(hit.collider.gameObject); } else if (hit.collider.gameObject.tag == "Unit" && currentSelectedObjects.Contains(hit.collider.gameObject)) { RemoveFromCurrentSelectedObjects(hit.collider.gameObject); } } else if (Input.GetMouseButton(0) && !Input.GetKey(KeyCode.LeftShift)) { if (UserDraggingByPosition(mouseDragStartPosition, Input.mousePosition)) { mouseDragging = true; DrawDragBox(); SelectObjectsInDrag(); } } else if (Input.GetMouseButtonUp(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDragging = false; } }
private void DeselectAll() { if (currentlySelectedUnits.Count > 0) { for (int i = 0; i < currentlySelectedUnits.Count; i++) { currentlySelectedUnits[i].GetComponent <ObjectInfo>().isSelected = false; currentlySelectedUnits[i].GetComponent <ObjectInfo>().isPrimary = false; currentlySelectedUnits.Remove(currentlySelectedUnits[i]); } } else if (currentlySelectedUnits.Count == 0) { selectFSM = SelectFSM.clickOrDrag; } hasPrimary = false; selectedInfo = null; primaryObject = null; }
private void SelectSingleUnit() { if (selectedUnit != null) { if (currentlySelectedUnits.Count > 0) { for (int i = 0; i < currentlySelectedUnits.Count; i++) { currentlySelectedUnits[i].GetComponent <Soldier>().m_canvas.enabled = false; currentlySelectedUnits[i].GetComponent <Soldier>().selected = false; currentlySelectedUnits.Remove(currentlySelectedUnits[i]); } } else if (currentlySelectedUnits.Count == 0) { AddToCurrentlySelectedUnits(selectedUnit); selectFSM = SelectFSM.clickOrDrag; } } }
private void SelectSingleUnit() { if (selectedEntity != null) { if (_currentEntity.Count > 0) { for (int i = 0; i < _currentEntity.Count; i++) { _currentEntity[i].GetComponent <Entity> ().IsDeselected(); _currentEntity.Remove(_currentEntity[i]); } } else if (_currentEntity.Count == 0) { AddToCurrentlySelectedUnits(selectedEntity); selectFSM = SelectFSM.clickOrDrag; } } else { Debug.Log("Whaaat?"); } }
private void SelectSingleUnit() { if (selectedUnit != null) { if (currentlySelectedUnits.Count > 0) { for (int i = 0; i < currentlySelectedUnits.Count; i++) { currentlySelectedUnits[i].transform.Find("SelectionCircle").gameObject.SetActive(false); currentlySelectedUnits.Remove(currentlySelectedUnits[i]); } } else if (currentlySelectedUnits.Count == 0) { AddToCurrentlySelectedUnits(selectedUnit); selectFSM = SelectFSM.clickOrDrag; } } else { Debug.Log("Whaaat?"); } }
private void SelectSingleUnit() { if (selectedUnit != null) { if (currentlySelectedUnits.Count > 0) { for (int i = 0; i < currentlySelectedUnits.Count; i++) { currentlySelectedUnits[i].GetComponent <ObjectInfo>().isSelected = false; currentlySelectedUnits[i].GetComponent <ObjectInfo>().isPrimary = false; currentlySelectedUnits.Remove(currentlySelectedUnits[i]); } } else if (currentlySelectedUnits.Count == 0) { AddToCurrentlySelectedUnits(selectedUnit); selectFSM = SelectFSM.clickOrDrag; } } else { Debug.Log("Whaaat?"); } }
void ClickOrDrag() { if (!mouseDragging) { _rect.gameObject.SetActive(false); } Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (EventSystem.current.currentSelectedGameObject != null) { return; } if (Physics.Raycast(ray, out hit, Mathf.Infinity)) { if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftControl)) { var _endDragPos = hit.point; _startDragPos = Input.mousePosition; if (hit.collider.gameObject.tag == "Entity" && hit.collider.GetComponent <Entity> ().Team == GetPlayer().Team) { selectedEntity = hit.collider.gameObject; selectFSM = SelectFSM.clickSelect; } else if (hit.collider.gameObject.tag == "UI") { } else if (hit.collider.gameObject.tag == "Terrain") { selectFSM = SelectFSM.clickDeselect; } } else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftControl) && hit.collider.gameObject.tag != "UI") { if (hit.collider.gameObject.tag == "Entity" && !_currentEntity.Contains(hit.collider.gameObject) && hit.collider.GetComponent <Tank> ()?.Team == GetPlayer().Team) { AddToCurrentlySelectedUnits(hit.collider.gameObject); } else if (hit.collider.gameObject.tag == "Entity" && _currentEntity.Contains(hit.collider.gameObject) && hit.collider.GetComponent <Tank> ()?.Team == GetPlayer().Team) { RemoveFromCurrentlySelectedUnits(hit.collider.gameObject); } } else if (Input.GetMouseButton(0) && !Input.GetKey(KeyCode.LeftControl)) { if (UserDraggingByPosition(_startDragPos, Input.mousePosition)) { mouseDragging = true; DrawDragBox(); SelectUnitsInDrag(); } } else if (Input.GetMouseButtonUp(0) && !Input.GetKey(KeyCode.LeftControl)) { mouseDragging = false; } if (Input.GetMouseButtonDown(1) && _currentEntity.Count > 0) { if (hit.collider.gameObject.tag == "Entity" && hit.collider.GetComponent <Entity> ().Team != GetPlayer().Team) { for (int i = 0; i < _currentEntity.Count; i++) { Tank _currentTank = _currentEntity[i].GetComponent <Tank> (); _currentTank.SetEnnemy(hit.collider.GetComponent <Entity> ()); _currentTank._state = EntityStates.Attack; } } else if (hit.collider.gameObject.tag == "Terrain") { for (int i = 0; i < _currentEntity.Count; i++) { Tank _currentTank = _currentEntity[i].GetComponent <Tank> (); Network.GetInstance().EntityMove(_currentTank, hit.point, EntityStates.Move); } } } } }
private void ClickOrDrag() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, Mathf.Infinity) /*&& !EventSystem.current.IsPointerOverGameObject()*/)//if you want that selection box dont go over ui decomment this part of if and using in top { currentMousePoint = hit.point; if (Input.GetMouseButtonDown(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDownPoint = hit.point; mouseDragStartPosition = Input.mousePosition; //click to select unit, or click the ground to deselect all if (hit.collider.gameObject.tag == "Selectable") { selectedUnit = hit.collider.gameObject; selectFSM = SelectFSM.clickSelect; } else if (hit.collider.gameObject.tag == "ground") { selectFSM = SelectFSM.clickDeselect; } } else if (Input.GetMouseButtonDown(0) && Input.GetKey(KeyCode.LeftShift)) { mouseDownPoint = hit.point; mouseDragStartPosition = Input.mousePosition; //holding shift, click to select units or click selected units to deselect if (hit.collider.gameObject.tag == "Selectable" && !currentlySelectedUnits.Contains(hit.collider.gameObject)) { AddToCurrentlySelectedUnits(hit.collider.gameObject); } else if (hit.collider.gameObject.tag == "Selectable" && currentlySelectedUnits.Contains(hit.collider.gameObject)) { RemoveFromCurrentlySelectedUnits(hit.collider.gameObject); } } else if (Input.GetMouseButton(0) && !Input.GetKey(KeyCode.LeftShift)) { if (UserDraggingByPosition(mouseDragStartPosition, Input.mousePosition)) { mouseDragging = true; DrawDragBox(); SelectUnitsInDrag(); } } else if (Input.GetMouseButton(0) && Input.GetKey(KeyCode.LeftShift)) { if (UserDraggingByPosition(mouseDragStartPosition, Input.mousePosition)) { mouseDragging = true; DrawDragBox(); ReSelectUnitsInDrag(); } } else if (Input.GetMouseButtonUp(0) && !Input.GetKey(KeyCode.LeftShift)) { mouseDragging = false; } else if (Input.GetMouseButtonUp(0) && Input.GetKey(KeyCode.LeftShift)) { mouseDragging = false; foreach (GameObject obj in units) { obj.GetComponent <ObjectInfo>().isReselect = false; } } } }