Ejemplo n.º 1
0
    void Update()
    {
        if (CommonInput.GetMouseButtonUp(1))
        {
            if (Selected)
            {
                Selected.action?.Invoke();
            }

            Destroy(gameObject);
        }
    }
Ejemplo n.º 2
0
    private void Update()
    {
        if (shadowObject == null)
        {
            return;
        }

        shadowObject.transform.position = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition);

        if (CommonInput.GetMouseButtonUp(0))
        {
            OnDragEnd();
        }
    }
    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();
        }
    }
Ejemplo n.º 4
0
    private void LateUpdate()
    {
        if (CustomNetworkManager.IsHeadless)
        {
            return;
        }

        if (shadowObject == null)
        {
            return;
        }

        shadowObject.transform.position = Camera.main.ScreenToWorldPoint(CommonInput.mousePosition);

        if (CommonInput.GetMouseButtonUp(0))
        {
            OnDragEnd();
        }
    }
Ejemplo n.º 5
0
        private void Update()
        {
            if (previousDrag != null)
            {
                var newDrag = (((Vector2)CommonInput.mousePosition - (Vector2)((RectTransform)transform).position) / UIManager.Instance.transform.localScale.x).normalized;
                // how far did we rotate from the previous position?
                var degreeDisplacement = Vector2.SignedAngle((Vector2)previousDrag, newDrag);

                // rotate
                SetRotation(degrees + degreeDisplacement);

                previousDrag = newDrag;

                if (CommonInput.GetMouseButtonUp(0))
                {
                    previousDrag = null;
                    ReleasePressureDial.IgnoreServerUpdates = false;
                    OnAdjustmentComplete.Invoke(KPA);
                    windowDrag.disableDrag = false;
                }
            }
        }
Ejemplo n.º 6
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();
        }
    }
Ejemplo n.º 7
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;
        }
    }
Ejemplo n.º 8
0
    void Update()
    {
        if (Initialised)
        {
            List <RadialButton> CurrentOptions = CurrentOptionsDepth [CurrentMenuDepth];

            MousePosition = new Vector2(CommonInput.mousePosition.x, CommonInput.mousePosition.y);
            toVector2M    = new Vector2(CommonInput.mousePosition.x, CommonInput.mousePosition.y);
            double  IndividualItemDegrees = 0;
            Vector2 Relativecentre        = toVector2M - centercirlce;
            //Logger.Log (Relativecentre.ToString ()+ " Relativecentre" , Category.RightClick);
            double Angle = (Mathf.Atan2(Relativecentre.y, Relativecentre.x) * Mathf.Rad2Deg);
            //off sets the Angle because it starts as -180 to 180
            Angle += -90;
            Angle  = Angle + SelectionRange[CurrentMenuDepth][1];
            if (Angle > 0)
            {
                Angle += -360;
            }
            Angle = Angle * -1;             //Turns it from negative to positive

            //Logger.Log (Angle.ToString () + " old Angle", Category.RightClick);
            //Logger.Log (((int)((Angle) / (SelectionRange[CurrentMenuDepth][0] / CurrentOptions.Count))).ToString () + " old MenuItem", Category.RightClick);
            //Logger.Log (Angle.ToString ()+ " Angle" , Category.RightClick);
            IndividualItemDegrees = SelectionRange[CurrentMenuDepth][0] / CurrentOptions.Count;
            Angle = Angle + ((IndividualItemDegrees) / 2); //Offsets by half a menu so So the different selection areas aren't in the middle of the menu

            if (Angle > 360)                               //Makes sure it's 360
            {
                Angle += -360;
            }

            MenuItem = (int)((Angle) / (IndividualItemDegrees));

            //Logger.Log ((IndividualItemDegrees).ToString () + " Density", Category.RightClick);
            //Logger.Log (Angle.ToString () + " Angle", Category.RightClick);
            //Logger.Log (SelectionRange[CurrentMenuDepth][0].ToString () + " Range", Category.RightClick);
            //Logger.Log (SelectionRange[CurrentMenuDepth][1].ToString () + " MinimumAngle", Category.RightClick);
            //Logger.Log (MenuItem.ToString () + "MenuItem", Category.RightClick);
            //Logger.Log (CurrentOptions.Count.ToString () + "CurrentOptions.Count", Category.RightClick);

            if (!(MenuItem > (CurrentOptions.Count - 1)) && !(MenuItem < 0))               //Ensures its in range Of selection
            {
                LastInRangeSubMenu = Time.time;
                Selected           = CurrentOptions [MenuItem];
                if (!(LastSelected == Selected))
                {
                    if (LastSelectedset)
                    {
                        if (LastSelected.MenuDepth == CurrentMenuDepth)
                        {
                            LastSelected.title.text = "";
                            LastSelected.transform.SetSiblingIndex(LastSelected.DefaultPosition);
                            LastSelected.SetColour(LastSelected.DefaultColour);
                        }
                        else
                        {
                            ResetDepthOnDestroy [CurrentMenuDepth] = LastSelected;
                        }
                    }
                    CurrentOptions [MenuItem].title.text      = CurrentOptions [MenuItem].Hiddentitle;
                    CurrentOptions [MenuItem].DefaultColour   = CurrentOptions [MenuItem].ReceiveCurrentColour();
                    CurrentOptions [MenuItem].DefaultPosition = CurrentOptions[MenuItem].transform.GetSiblingIndex();
                    CurrentOptions [MenuItem].SetColour(CurrentOptions [MenuItem].DefaultColour + (Color.white / 3f));
                    CurrentOptions [MenuItem].transform.SetAsLastSibling();
                    LastSelected     = CurrentOptions [MenuItem];
                    LastSelectedset  = true;
                    LastSelectedTime = Time.time;
                    //Logger.Log (LastSelectedTime.ToString (), Category.RightClick);
                }
                if (LastSelectedset)
                {
                    if ((Time.time - LastSelectedTime) > 0.4f)                       //How long it takes to make a menu

                    {
                        if ((!(DepthMenus [CurrentMenuDepth] [MenuItem].SubMenus == null)) && DepthMenus [CurrentMenuDepth] [MenuItem].SubMenus.Count > 0)
                        {
                            Logger.Log(MenuItem.ToString() + " Selected", Category.RightClick);
                            int NewMenuDepth = CurrentMenuDepth;
                            LastSelectedTime = Time.time;
                            NewMenuDepth     = NewMenuDepth + 100;
                            int InitialAngle = MenuItem * (360 / CurrentOptions.Count);

                            SpawnButtons(DepthMenus [CurrentMenuDepth] [MenuItem].SubMenus, NewMenuDepth, InitialAngle);
                        }
                    }
                }
            }
            else
            {
                if ((Time.time - LastInRangeSubMenu) > 0.3f && (CurrentMenuDepth > 100))                  //How long it takes to exit a menu
                //Logger.Log ("yo am Destroying", Category.UI);

                {
                    if (ResetDepthOnDestroy.ContainsKey(CurrentMenuDepth))
                    {
                        ResetDepthOnDestroy [CurrentMenuDepth].title.text = "";
                        ResetDepthOnDestroy [CurrentMenuDepth].transform.SetSiblingIndex(ResetDepthOnDestroy [CurrentMenuDepth].DefaultPosition);
                        ResetDepthOnDestroy [CurrentMenuDepth].SetColour(ResetDepthOnDestroy [CurrentMenuDepth].DefaultColour);
                    }
                    else
                    {
                        LastSelected.transform.SetSiblingIndex(LastSelected.DefaultPosition);
                        LastSelected.SetColour(LastSelected.DefaultColour);
                        LastSelected.title.text = "";
                        LastSelected            = null;
                        LastSelectedset         = false;
                    }
                    List <RadialButton> Acopy = CurrentOptions;
                    for (int i = 0; i < Acopy.Count; i++)
                    {
                        Destroy(CurrentOptions[i].gameObject);
                    }
                    //Cleans up the dictionarys
                    SelectionRange.Remove(CurrentMenuDepth);
                    CurrentOptionsDepth.Remove(CurrentMenuDepth);
                    DepthMenus.Remove(CurrentMenuDepth);
                    ResetDepthOnDestroy.Remove(CurrentMenuDepth);
                    CurrentMenuDepth = CurrentMenuDepth - 100;
                    LastSelectedset  = false;
                }
            }
        }
        if (CommonInput.GetMouseButtonUp(1))
        {
            if (Selected)
            {
                Selected.Action?.Invoke();
                //Logger.Log ("yo this "+Selected.title.text , Category.RightClick);
            }
            LastSelectedset = false;
            Destroy(gameObject);
        }
    }
Ejemplo n.º 9
0
    private void Update()
    {
        if (ControlledByPlayer == NetworkInstanceId.Invalid)
        {
            return;
        }

        //don't start it too early:
        if (!isServer && !PlayerManager.LocalPlayer)
        {
            return;
        }

        //only perform the rest of the update if the weapon is in the hand of the local player or
        //we are the server
        if (!isServer && PlayerManager.LocalPlayer != ClientScene.FindLocalObject(ControlledByPlayer))
        {
            return;
        }

        //update the time until the next shot can happen
        if (FireCountDown > 0)
        {
            FireCountDown -= Time.deltaTime;
            //prevents the next projectile taking miliseconds longer than it should
            if (FireCountDown < 0)
            {
                FireCountDown = 0;
            }
        }

        //this will only be executed on the server since only the server
        //maintains the queued actions
        if (queuedShots.Count > 0 && FireCountDown <= 0)
        {
            //fire the next shot in the queue
            DequeueAndProcessServerShot();
        }

        if (queuedUnload && queuedShots.Count == 0)
        {
            // done processing shot queue,
            // perform the queued unload action, causing all clients and server to update their version of this Weapon
            //due to the syncvar hook
            MagNetID     = NetworkInstanceId.Invalid;
            queuedUnload = false;
        }
        if (queuedLoadMagNetID != NetworkInstanceId.Invalid && queuedShots.Count == 0)
        {
            //done processing shot queue, perform the reload, causing all clients and server to update their version of this Weapon
            //due to the syncvar hook
            MagNetID           = queuedLoadMagNetID;
            queuedLoadMagNetID = NetworkInstanceId.Invalid;
        }

        //rest of the Update is only needed for the weapon if it is held by the local player
        if (PlayerManager.LocalPlayer != ClientScene.FindLocalObject(ControlledByPlayer))
        {
            return;
        }

        //check if burst should stop if the weapon is held by the local player
        if (CommonInput.GetMouseButtonUp(0))
        {
            StopAutomaticBurst();
        }
    }