Ejemplo n.º 1
0
    private static void SelectAllSameSelectableInScreen(Selectable currentSelectable)
    {
        DeselectSelected();
        Collider2D[] allVisibleColliders = Physics2D.OverlapAreaAll(Camera.main.ScreenToWorldPoint(new Vector2(0, 0)), Camera.main.ScreenToWorldPoint(new Vector2(Camera.main.pixelWidth, Camera.main.pixelHeight)));

        foreach (Collider2D collider in allVisibleColliders)
        {
            Selectable colliderSelectable = collider.GetComponent <Selectable>();
            if (colliderSelectable != null && colliderSelectable.selectableName.Equals(currentSelectable.selectableName) && !selected.Contains(colliderSelectable))
            {
                selected.Add(colliderSelectable);
                colliderSelectable.FlipSelected();
            }
        }
    }
Ejemplo n.º 2
0
    public static void HandleClickOnCollider(Collider2D clickedCollider)
    {
        Selectable currentSelected = clickedCollider.GetComponent <Selectable>();

        // If the selected collider has selectable component
        if (currentSelected != null)
        {
            // Check if the selected thing belongs to player faction
            if (FactionsManager.playerFaction.factionTag.Equals(currentSelected.tag))
            {
                // Check if anything else is selected, if so, check if the new selected is of the player faction, and if so, that it is of the same type of selectable
                if (selected.Count != 0 && selected[0].tag.Equals(FactionsManager.playerFaction.factionTag) && selected[0].selectableName.Equals(currentSelected.selectableName))
                {
                    // If previous conditions are filled, we then check if the selected thing is already selected, if so, we select all of the same type on screen
                    if (!selected.Contains(currentSelected))
                    {
                        // Add currentSelected to selected list as it is of same type, player faction and is not yet present in selected list
                        selected.Add(currentSelected);
                        currentSelected.FlipSelected();
                    }
                    else
                    {
                        // Select all of the same type on screen
                        SelectAllSameSelectableInScreen(currentSelected);
                    }
                }
                else
                {
                    // This is run if the current selected is first on selected list, if it is not of the player faction or different type than other selected things
                    SelectOnlyGiven(currentSelected);
                }
            }
            else
            {
                // If it does not belong to player faction, only it can be selected, so we call selectOnlyGiven -method,
                // Which deselects all previously selected things, and selects the given selectable -component
                SelectOnlyGiven(currentSelected);
            }
        }

        UpdateDescription();
    }
Ejemplo n.º 3
0
 private static void SelectOnlyGiven(Selectable currentSelected)
 {
     DeselectSelected();
     selected.Add(currentSelected);
     currentSelected.FlipSelected();
 }