Exemple #1
0
        /// <summary>
        /// This is where all the selecting happens
        /// </summary>
        /// <param name="hit"></param>
        private void DefaultLeftClickUp(GameObject hit)
        {
            var clickTarget = hit.GetComponent <MouseControllable>();

            if (selected.Contains(clickTarget) && cameraController != null)
            {
                cameraController.FocusOn(hit);
            }

            DeselectCurrentSelection();

            // Add objects within selection
            FindObjectsOfType <MouseControllable>()
            .Where(unit => IsWithinSelectionBounds(unit.gameObject)).ToList()
            .ForEach(AddToSelection);

            // Add click target
            if (clickTarget != null)
            {
                AddToSelection(clickTarget);
                AddToSelection(focusedSelected);
                focusedSelected = clickTarget;
            }
            else if (selected.Count > 0)
            {
                focusedSelected = selected[0];
            }

            if (focusedSelected != null)
            {
                focusedSelected.OnFocusSelect();
            }

            isSelecting = false;
        }
Exemple #2
0
 private void AddToSelection(MouseControllable controllable)
 {
     if (controllable == null)
     {
         return;
     }
     selected.Add(controllable);
     controllable.OnSelect();
 }
Exemple #3
0
 private void AddToSelection(List <MouseControllable> controllables, bool focus)
 {
     controllables.ForEach(AddToSelection);
     if (!focus || selected.Count <= 0)
     {
         return;
     }
     focusedSelected = selected[0];
     focusedSelected.OnFocusSelect();
 }
Exemple #4
0
        private void HandleHotkeys(ClickLocation click)
        {
            // Remove selection
            if (Input.GetKeyDown(KeyCode.Escape))
            {
                if (isSelecting)
                {
                    isSelecting = false;
                }
                else
                {
                    DeselectCurrentSelection();
                }
            }

            foreach (var buttonName in ButtonNames)
            {
                if (Input.GetButtonDown(buttonName))
                {
                    selected.ForEach(controllable => controllable.OnButton(buttonName, click));
                }
            }

            // Center Camera
            if (Input.GetKey(Hotkeys.CenterCamera) && focusedSelected != null)
            {
                cameraController.FocusOn(focusedSelected.transform.gameObject);
            }

            // Tab selection
            if (Input.GetKeyDown(Hotkeys.NextSelection) && selected.Count > 1)
            {
                var oldIndex = selected.IndexOf(focusedSelected);
                var newIndex = oldIndex + 1;
                if (focusedSelected != null)
                {
                    focusedSelected.OnSelect();
                }
                focusedSelected = selected[newIndex == selected.Count ? 0 : newIndex];
                focusedSelected.OnFocusSelect();
            }

            // Revive TODO: remove
            if (Input.GetKeyDown(KeyCode.Keypad0))
            {
                selected.ForEach(controllable => {
                    var health = controllable.transform.gameObject.GetComponent <Damageable>();
                    if (health != null)
                    {
                        health.Revive(0, 2);
                    }
                });
            }

            // Control Groups
            if (Input.GetButtonUp("Select All"))
            {
                DeselectCurrentSelection();
                AddToSelection(FindObjectsOfType <MouseControllable>().ToList(), true);
            }
            for (var i = 1; i <= 5; i++)
            {
                if (!Input.GetButtonUp("Select " + i))
                {
                    continue;
                }
                DeselectCurrentSelection();
                AddToSelection(ControlGroups[i], true);
                if (ValidDoubleTap(i))
                {
                    cameraController.FocusOn(ControlGroups[i][0].gameObject);
                }
                doubleTapGroup = i;
                doubleTapTime  = Time.time;
            }
        }
Exemple #5
0
 /// <summary>
 /// Clear selection and focused selection
 /// </summary>
 private void DeselectCurrentSelection()
 {
     selected.ForEach(o => o.OnDeselect());
     selected.Clear();
     focusedSelected = null;
 }