Exemple #1
0
 // When right clicking on an item, examine the item
 public void OnHover()
 {
     if (CommonInput.GetMouseButtonDown(1))
     {
         SendExamine();
     }
 }
    void Update()
    {
        // Get right mouse click
        if (CommonInput.GetMouseButtonDown(1))
        {
            var mousePos = CommonInput.mousePosition;

            var objects = GetGameObjects(mousePos, out var isUI);
            //Generates menus
            var options = Generate(objects);

            if (options == null || options.Count <= 0)
            {
                return;
            }

            IBranchPosition branchPosition = BranchScreenPosition.SetPosition(mousePos);

            if (isUI == false)
            {
                var tile = objects.Select(o => o.RegisterTile()).FirstOrDefault();
                if (tile)
                {
                    branchPosition = BranchWorldPosition.SetTile(tile);
                }
            }

            MenuController.SetupMenu(options, branchPosition);
        }
    }
Exemple #3
0
 private void CheckMouseInput()
 {
     if (UIManager.IsMouseInteractionDisabled)
     {
         //still allow tooltips
         CheckHover();
         return;
     }
     if (CommonInput.GetMouseButtonDown(0))
     {
         if (!CheckAltClick())
         {
             if (!CheckThrow())
             {
                 CheckClick();
             }
         }
     }
     else if (CommonInput.GetMouseButton(0))
     {
         //mouse being held down / dragged
         CheckDrag();
     }
     else
     {
         CheckHover();
     }
 }
    private void Update()
    {
        if (state == State.SELECTING)
        {
            // ignore when we are over UI
            if (EventSystem.current.IsPointerOverGameObject())
            {
                return;
            }

            //check which objects we are over, pick the top one to spawn
            if (CommonInput.GetMouseButtonDown(0))
            {
                //NOTE: Avoiding multiple enumeration by converting IEnumerables to lists.
                var hitGOs = MouseUtils.GetOrderedObjectsUnderMouse(layerMask,
                                                                    go => go.GetComponent <CustomNetTransform>() != null).ToList();
                //warn about objects which cannot be cloned
                var nonPooledHits = hitGOs
                                    .Where(go => Spawn.DeterminePrefab(go) == null).ToList();
                if (nonPooledHits.Any())
                {
                    foreach (GameObject nonPooled in nonPooledHits)
                    {
                        Logger.LogWarningFormat("Object {0} does not have a PoolPrefabTracker component and its name" +
                                                " did not match one of our existing prefabs " +
                                                "therefore cannot be cloned (because we wouldn't know which prefab to instantiate). " +
                                                "Please attach this component to the object and specify the prefab" +
                                                " to allow it to be cloned.", Category.ItemSpawn, nonPooled.name);
                    }
                }

                var pooledHits = hitGOs.Where(go => Spawn.DeterminePrefab(go) != null).ToList();
                if (pooledHits.Any())
                {
                    toClone = pooledHits.First();
                    ToState(State.DRAWING);
                }
            }
        }
        else if (state == State.DRAWING)
        {
            cursorObject.transform.position = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition);
            if (CommonInput.GetMouseButtonDown(0))
            {
                Vector3Int position = cursorObject.transform.position.RoundToInt();
                position.z = 0;
                if (MatrixManager.IsPassableAtAllMatricesOneTile(position, false))
                {
                    if (CustomNetworkManager.IsServer)
                    {
                        Spawn.ServerClone(toClone, position);
                    }
                    else
                    {
                        DevCloneMessage.Send(toClone, (Vector3)position, ServerData.UserID, PlayerList.Instance.AdminToken);
                    }
                }
            }
        }
    }
Exemple #5
0
        private bool IsAnyPointerDown()
        {
            for (var i = 0; i < 3; i++)
            {
                if (CommonInput.GetMouseButtonDown(i))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #6
0
        public override void CheckMouseInput()
        {
            if (EventSystem.current.IsPointerOverGameObject())
            {
                //don't do any game world interactions if we are over the UI
                return;
            }

            if (UIManager.IsMouseInteractionDisabled)
            {
                //still allow tooltips
                CheckHover();
                return;
            }

            if (CommonInput.GetMouseButtonDown(0))
            {
                if (KeyboardInputManager.IsControlPressed() && KeyboardInputManager.IsShiftPressed())
                {
                    CheckForInteractions(AiActivate.ClickTypes.CtrlShiftClick);
                    return;
                }

                //check ctrl+click for dragging
                if (KeyboardInputManager.IsControlPressed())
                {
                    CheckForInteractions(AiActivate.ClickTypes.CtrlClick);
                    return;
                }

                if (KeyboardInputManager.IsShiftPressed())
                {
                    //like above, send shift-click request, then do nothing else.
                    //Inspect();
                    CheckForInteractions(AiActivate.ClickTypes.ShiftClick);
                    return;
                }

                if (KeyboardInputManager.IsAltPressed())
                {
                    CheckForInteractions(AiActivate.ClickTypes.AltClick);
                    return;
                }

                CheckForInteractions(AiActivate.ClickTypes.NormalClick);
            }
            else
            {
                CheckHover();
            }
        }
Exemple #7
0
    public override void CheckMouseInput()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            //don't do any game world interactions if we are over the UI
            return;
        }

        if (UIManager.IsMouseInteractionDisabled)
        {
            //still allow tooltips
            CheckHover();
            return;
        }

        if (CommonInput.GetMouseButtonDown(0))
        {
            if (ClicksFromBlobHud())
            {
                return;
            }

            //check ctrl+click for dragging
            if (KeyboardInputManager.IsControlPressed())
            {
                //Place strong blob / reflective if strong blob already
                blobPlayer.CmdTryPlaceStrongReflective(Camera.main.ScreenToWorldPoint(CommonInput.mousePosition).RoundToInt());
                return;
            }

            if (KeyboardInputManager.IsShiftPressed())
            {
                //like above, send shift-click request, then do nothing else.
                Inspect();
                return;
            }

            if (KeyboardInputManager.IsAltPressed())
            {
                //Remove blob
                blobPlayer.CmdRemoveBlob(Camera.main.ScreenToWorldPoint(CommonInput.mousePosition).RoundToInt());
                return;
            }

            blobPlayer.CmdTryPlaceBlobOrAttack(Camera.main.ScreenToWorldPoint(CommonInput.mousePosition).RoundToInt());
        }
        else
        {
            CheckHover();
        }
    }
    private void CheckMouseInput()
    {
        if (UIManager.IsMouseInteractionDisabled)
        {
            //still allow tooltips
            CheckHover();
            return;
        }

        if (!canDrag && CommonInput.GetMouseButtonUp(0))
        {
            //reset candrag on buttonup
            canDrag = true;
        }
        if (CommonInput.GetMouseButtonDown(0))
        {
            var clicked = CheckAltClick();
            if (!clicked)
            {
                clicked = CheckThrow();
            }
            if (!clicked)
            {
                clicked = CheckClick();
            }
            if (!clicked)
            {
                clicked = CheckClickV2();
            }

            if (clicked)
            {
                //wait until mouseup to allow drag interaction again
                canDrag = false;
            }
        }
        else if (CommonInput.GetMouseButton(0))
        {
            //mouse being held down / dragged
            if (!CheckDrag() && canDrag)
            {
                CheckDragV2();
            }
        }
        else
        {
            CheckHover();
        }
    }
Exemple #9
0
 void Update()
 {
     // Get right mouse click and check if mouse point occluded by FoV system.
     if (CommonInput.GetMouseButtonDown(1) && lightingSystem.IsScreenPointVisible(CommonInput.mousePosition))
     {
         //gets Items on the position of the mouse that are able to be right clicked
         List <GameObject> objects = GetRightClickableObjects();
         //Generates menus
         Generate(objects);
         //Logger.Log ("yo", Category.UI);
         if (options.Count > 0)
         {
             RadialMenuSpawner.ins.SpawnRadialMenu(options);
         }
     }
 }
    void Update()
    {
        // Get right mouse click
        if (CommonInput.GetMouseButtonDown(1))
        {
            var mousePos = CommonInput.mousePosition;

            var objects = GetGameObjects(mousePos, out var isUI);
            //Generates menus
            var options = Generate(objects);
            if (options != null && options.Count > 0)
            {
                MenuController.SetupMenu(options, Camera.main.ScreenToWorldPoint(mousePos), !isUI);
            }
        }
    }
Exemple #11
0
 private void Update()
 {
     if (state == State.SELECTING)
     {
         // ignore when we are over UI
         if (EventSystem.current.IsPointerOverGameObject())
         {
             return;
         }
         if (CommonInput.GetMouseButtonDown(0))
         {
             RequestToViewObjectsAtTile.Send(MouseUtils.MouseToWorldPos());
             OnEscape();
         }
     }
 }
Exemple #12
0
 private void Update()
 {
     if (selectedItem == this)
     {
         cursorObject.transform.position = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition);
         if (CommonInput.GetMouseButtonDown(0))
         {
             //Ignore spawn if pointer is hovering over GUI
             if (EventSystem.current.IsPointerOverGameObject())
             {
                 return;
             }
             TrySpawn();
         }
     }
 }
 private void Update()
 {
     if (state == State.SELECTING)
     {
         // ignore when we are over UI
         if (EventSystem.current.IsPointerOverGameObject())
         {
             return;
         }
         if (CommonInput.GetMouseButtonDown(0))
         {
             RequestToViewObjectsAtTile.Send(Camera.main.ScreenToWorldPoint(CommonInput.mousePosition),
                                             ServerData.UserID, PlayerList.Instance.AdminToken);
             OnEscape();
         }
     }
 }
Exemple #14
0
    void Update()
    {
        // Get right mouse click
        if (CommonInput.GetMouseButtonDown(1))
        {
            List <GameObject> objects = null;
            // Check if mouse point occluded by FoV system.
            if (!lightingSystem.enabled || lightingSystem.IsScreenPointVisible(CommonInput.mousePosition))
            {
                // Gets Items on the position of the mouse that are able to be right clicked
                objects = GetRightClickableObjects();
            }
            else
            {
                objects = new List <GameObject>();
            }

            // Gets UI elements
            var pointerData = new PointerEventData(EventSystem.current)
            {
                pointerId = -1,                 // Mouse
                position  = CommonInput.mousePosition,
            };
            EventSystem.current.RaycastAll(pointerData, raycastResults);
#pragma warning disable UEA0005 // Ignore warning about using GetComponent() inside Update()
            // Searching for UI_ItemSwap instead of UI_ItemSlot for the larger and more consistent hitbox.
            objects.AddRange(raycastResults.Select(rc => {
                // Verbose workaround since you should not use null propagation on Unity objects. Thanks, Unity.
                var itemSwap = rc.gameObject.GetComponent <UI_ItemSwap>();
                var itemSlot = itemSwap == null ? null : itemSwap.GetComponentInChildren <UI_ItemSlot>();
                return(itemSlot == null ? null : itemSlot.ItemObject);
            }).Where(go => go != null));
#pragma warning restore UEA0005

            //Generates menus
            var options = Generate(objects);
            //Logger.Log ("yo", Category.UI);
            if (options != null && options.Count > 0)
            {
                RadialMenuSpawner.ins.SpawnRadialMenu(options);
            }
        }
    }
 private void UpdateMe()
 {
     // check which objects we are over, pick the top one to delete
     if (CommonInput.GetMouseButtonDown(0))
     {
         var hits = MouseUtils.GetOrderedObjectsUnderMouse(layerMask,
                                                           go => go.GetComponent <CustomNetTransform>() != null);
         if (hits.Any())
         {
             if (CustomNetworkManager.IsServer)
             {
                 _ = Despawn.ServerSingle(hits.First().GetComponentInParent <CustomNetTransform>().gameObject);
             }
             else
             {
                 DevDestroyMessage.Send(hits.First().GetComponentInParent <CustomNetTransform>().gameObject);
             }
         }
     }
 }
Exemple #16
0
 private void CheckMouseInput()
 {
     if (CommonInput.GetMouseButtonDown(0))
     {
         if (!CheckAltClick())
         {
             if (!CheckThrow())
             {
                 CheckClick();
             }
         }
     }
     else if (CommonInput.GetMouseButton(0))
     {
         //mouse being held down / dragged
         CheckDrag();
     }
     else
     {
         CheckHover();
     }
 }
Exemple #17
0
    private void CheckMouseInput()
    {
        if (EventSystem.current.IsPointerOverGameObject())
        {
            //don't do any game world interactions if we are over the UI
            return;
        }

        if (UIManager.IsMouseInteractionDisabled)
        {
            //still allow tooltips
            CheckHover();
            return;
        }

        //do we have a loaded gun
        var loadedGun = GetLoadedGunInActiveHand();

        if (CommonInput.GetMouseButtonDown(0))
        {
            //check ctrl+click for dragging
            if (KeyboardInputManager.IsControlPressed())
            {
                //even if we didn't drag anything, nothing else should happen
                CheckInitiatePull();

                return;
            }

            //check the alt click and throw, which doesn't have any special logic
            if (CheckAltClick())
            {
                return;
            }
            if (CheckThrow())
            {
                return;
            }

            if (loadedGun != null)
            {
                //if we are on harm intent with loaded gun,
                //don't do anything else, just shoot (trigger the AimApply).
                if (UIManager.CurrentIntent == Intent.Harm)
                {
                    CheckAimApply(MouseButtonState.PRESS);
                }
                else
                {
                    //proceed to normal click interaction
                    CheckClickInteractions(true);
                }
            }
            else
            {
                //we don't have a loaded gun
                //Are we over something draggable?
                var draggable = GetDraggable();
                if (draggable != null)
                {
                    //We are over a draggable. We need to wait to see if the user
                    //tries to drag the object or lifts the mouse.
                    potentialDraggable = draggable;
                    dragStartOffset    = MouseWorldPosition - potentialDraggable.transform.position;
                    clickDuration      = 0;
                }
                else
                {
                    //no possibility of dragging something, proceed to normal click logic
                    CheckClickInteractions(true);
                }
            }
        }
        else if (CommonInput.GetMouseButton(0))
        {
            //mouse button being held down.
            //increment the time since they initially clicked the mouse
            clickDuration += Time.deltaTime;

            //If we are possibly dragging and have exceeded the drag distance, initiate the drag
            if (potentialDraggable != null)
            {
                var currentOffset = MouseWorldPosition - potentialDraggable.transform.position;
                if (((Vector2)currentOffset - dragStartOffset).magnitude > MouseDragDeadzone)
                {
                    potentialDraggable.BeginDrag();
                    potentialDraggable = null;
                }
            }

            //continue to trigger the aim apply if it was initially triggered
            CheckAimApply(MouseButtonState.HOLD);
        }
        else if (CommonInput.GetMouseButtonUp(0))
        {
            //mouse button is lifted.
            //If we were waiting for mouseup to trigger a click, trigger it if we're still within
            //the duration threshold
            if (potentialDraggable != null)
            {
                if (clickDuration < MaxClickDuration)
                {
                    //we are lifting the mouse, so AimApply should not be performed but other
                    //clicks can.
                    CheckClickInteractions(false);
                }

                clickDuration      = 0;
                potentialDraggable = null;
            }

            //no more triggering of the current aim apply
            triggeredAimApply = null;
            secondsSinceLastAimApplyTrigger = 0;
        }
        else
        {
            CheckHover();
        }
    }
Exemple #18
0
    private void Update()
    {
        // return if visualisation is disabled or distance is greater than interaction distance
        if (!cablePlacementVisualisation.activeSelf)
        {
            return;
        }

        // get releative mouse position
        Vector2 releativeMousePosition = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition) - cablePlacementVisualisation.transform.position;
        // get nearest point
        int x = Mathf.RoundToInt(releativeMousePosition.x * 2);
        int y = 2 - Mathf.RoundToInt(releativeMousePosition.y * 2);

        // clamp to be sure that value is in range <0, 2>
        x = Mathf.Clamp(x, 0, 2);
        y = Mathf.Clamp(y, 0, 2);
        Vector2Int point = new Vector2Int(x, y);

        Connection currentConnection = GetConnectionByPoint(point);

        // if mouse down - start drawing
        if (CommonInput.GetMouseButtonDown(0))
        {
            startPoint = currentConnection;
            target     = MouseUtils.GetOrderedObjectsUnderMouse().FirstOrDefault();

            SetConnectionPointColor(startPoint, startPointColor);
        }
        // if mouse up - stop drawing and check if can build
        else if (CommonInput.GetMouseButtonUp(0))
        {
            endPoint = currentConnection;
            Build();
            ResetValues();
            return;
        }

        // check if position has changed
        if (currentConnection != lastConnection)
        {
            // check if last point isn't startPoint or endPoint (to not override color)
            if (lastConnection != startPoint && lastConnection != endPoint)
            {
                SetConnectionPointColor(lastConnection, defaultPointColor);
            }

            SetConnectionPointColor(currentConnection, onHoverPointColor);

            if (startPoint != Connection.NA)
            {
                lineRenderer.SetPositions(new Vector3[]
                {
                    connectionPointRenderers[startPoint].transform.localPosition,                               // position of start point
                    connectionPointRenderers[currentConnection].transform.localPosition                         // position of current point
                });
            }

            lastConnection = currentConnection;
        }
    }