コード例 #1
0
    private void UpdateBoxHover()
    {
        // Get all objects within selection box
        Vector2 boxCenter = (boxSelectStartPos + mousePos) / 2;
        Vector2 boxDiff   = mousePos - boxSelectStartPos;
        Vector2 boxSize   = new Vector2(Mathf.Abs(boxDiff.x), Mathf.Abs(boxDiff.y));

        Physics2D.OverlapBox(boxCenter, boxSize, 0, selectionFilter, overlapResults);
        hoverTargets = SelectionHelper.ConvertAll <Collider2D, Interactable>(overlapResults);
        hoverTargets = SelectionHelper.RemoveAll <Resource>(hoverTargets);

        // Update indicator box
        boxSelectIndicator.transform.position = boxCenter;
        boxSelectIndicator.size = boxSize;
    }
コード例 #2
0
 private void SelectByPriority()
 {
     // We could make this generic using type reflection, however that would make the code substantially more confusing
     if (SelectionHelper.ContainsAny <Unit>(hoverTargets) || SelectionHelper.ContainsOnly <Unit>(selection))
     {
         List <Unit> selectedUnits = SelectionHelper.ConvertAll <Interactable, Unit>(hoverTargets);
         selection.AddRange(selectedUnits);
         selection = selection.Distinct().ToList();
     }
     else if (SelectionHelper.ContainsAny <Building>(hoverTargets) || SelectionHelper.ContainsOnly <Building>(selection))
     {
         List <Building> selectedBuildings = SelectionHelper.ConvertAll <Interactable, Building>(hoverTargets);
         selection.AddRange(selectedBuildings);
         selection = selection.Distinct().ToList();
     }
     else if (SelectionHelper.ContainsAny <Resource>(hoverTargets) || SelectionHelper.ContainsOnly <Resource>(selection))
     {
         List <Resource> selectedResources = SelectionHelper.ConvertAll <Interactable, Resource>(hoverTargets);
         selection.AddRange(selectedResources);
         selection = selection.Distinct().ToList();
     }
 }
コード例 #3
0
 public List <T> GetHoverTargetsOfType <T>() where T : Interactable
 {
     return(SelectionHelper.ConvertAll <Interactable, T>(hoverTargets));
 }
コード例 #4
0
 public List <T> GetSelectionOfType <T>() where T : Interactable
 {
     return(SelectionHelper.ConvertAll <Interactable, T>(selection));
 }