private void TrySelect(bool applyToCurrent) { RaycastHit hit; Camera currentCam = Service.Cameras.CurrentCamera; Ray mouseRay = Service.Cameras.CurrentCamera.ScreenPointToRay(Input.mousePosition); bool entitySelected = false; if (Physics.Raycast(mouseRay, out hit) && hit.transform != null) { EntityRef entRef = hit.transform.GetComponent <EntityRef> (); if (entRef != null && !CurrentEntities.Contains(entRef.GetEntity())) { SelectAction selectAction = new SelectAction(); selectAction.SetArguments(CurrentEntities, entRef.GetEntity(), applyToCurrent); Service.ActionManager.ExecuteAction(selectAction); entitySelected = true; } else if (applyToCurrent && entRef != null && CurrentEntities.Count > 1 && CurrentEntities.Contains(entRef.GetEntity())) { DeselectAction deselectAction = new DeselectAction(); deselectAction.SetArguments(entRef.GetEntity()); Service.ActionManager.ExecuteAction(deselectAction); entitySelected = true; } else if (entRef != null && CurrentEntities.Count > 1 && CurrentEntities.Contains(entRef.GetEntity())) { // If the user selects a single element that is already selected as part of a group, do nothing. entitySelected = true; } } // No entity clicked on. Deselect all entities. if (!entitySelected && CurrentEntities.Count > 0) { SelectAction selectAction = new SelectAction(); selectAction.SetArguments(CurrentEntities, null, false); Service.ActionManager.ExecuteAction(selectAction); CurrentEntities.Clear(); } }