Пример #1
0
 // called when left mouse is first pressed down, creates a new rectangle and passes it to
 // BoxSelectionCheck. Clears current selection if left ctrl not down.
 public void BeginBoxSelection(Vector3 initMousePos)
 {
     // if ctrl is not being held down
     if (!Input.GetKey("left ctrl"))
     {
         OnClearSelection?.Invoke();
     }
     this.mousePos1 = initMousePos;
     this.mousePos2 = initMousePos;
     selectRect     = new Rect(mousePos1.x, mousePos1.y, mousePos2.x - mousePos1.x, mousePos2.y - mousePos1.y);
     OnBoxSelection?.Invoke(selectRect);
 }
Пример #2
0
 // selects the single unit that the raycast hit
 // if ctrl is not being held down, clears selection first
 private void SingleSelect(RaycastHit rayHit, Vector3 mousePos2)
 {
     if (mousePos1 == mousePos2 && rayHit.collider != null)
     {
         GameObject collidedObj = rayHit.collider.gameObject;
         if (collidedObj.GetComponent <Selectable>() != null)
         {
             if (!Input.GetKey("left ctrl")) // if ctrl is not held down
             {
                 OnClearSelection?.Invoke();
             }
             OnAddSelection?.Invoke(collidedObj);
         }
         else if (!Input.GetKey("left ctrl")) // if the raycast doesn't hit a selectable object and left ctrl is not down
         {
             OnClearSelection?.Invoke();
         }
     }
 }