Esempio n. 1
0
 private void AddToSelection(MouseControllable controllable)
 {
     if (controllable == null)
     {
         return;
     }
     selected.Add(controllable);
     controllable.OnSelect();
 }
Esempio n. 2
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;
            }
        }