Exemple #1
0
    void OnSelectObject(object sender, PointerEventArgs args)
    {
        bool additive = (additiveSelectionButton != null && additiveSelectionButton.GetActive(SteamVR_Input_Sources.Any)) ||
                        (additiveSelectionKeyboardButton != "" && Input.GetButton(additiveSelectionKeyboardButton));
        bool subtractive = subtractiveSelectionButton != null && subtractiveSelectionButton.GetActive(SteamVR_Input_Sources.Any) ||
                           (subtractiveSelectionKeyboardButton != "" && Input.GetButton(subtractiveSelectionKeyboardButton));

        if (!additive && !subtractive)
        {
            selectionMgr.ClearSelection();
        }

        if (additive)
        {
            Debug.Log("additive selection");
        }
        if (subtractive)
        {
            Debug.Log("subtractive selection");
        }

        var selectable = args.target.GetComponentInParent <SelectableUnit>();

        if (selectable != null)
        {
            if (additive || !subtractive)
            {
                selectionMgr.AddUnitToSelection(selectable);
            }
            else
            {
                selectionMgr.RemoveUnitFromSelection(selectable);
            }
        }
    }
Exemple #2
0
 private void Update()
 {
     if (touchPadTouch.GetActive(leftOrRightHand))
     {
         Process(false, false);
     }
 }
    //-------------------------------------------------
    // Cycles through all the button hints on the controller
    //-------------------------------------------------
    private IEnumerator HintCoroutine()
    {
        Hand hand = player.rightHand;

        while (true)
        {
            if (action.GetActive(hand.handType))
            {
                ControllerButtonHints.ShowTextHint(hand, action, "Grab Toy");
            }
            else
            {
                ControllerButtonHints.HideButtonHint(hand, action);
            }

            yield return(new WaitForSeconds(3.0f));

            yield return(null);
        }
    }
        /*--------------------------------------------------------------------------------------------*/
        protected virtual ControlState GetControllerState(GameObject pControlGo)
        {
            SteamVR_Behaviour_Pose control = pControlGo.GetComponent <SteamVR_Behaviour_Pose>();
            //Device input = null;

            var state = new ControlState();

            state.Controller = control;
            state.Tx         = control.transform;
            state.IsValid    = control.isValid;

            if (control.GetDeviceIndex() < 0)
            {
                state.IsValid = false;
            }
            else
            {
                //input = SteamVR_Controller.Input((int)control.index);
                state.IsValid = true;                // control.isValid;//(state.IsValid && control.isValid);
            }

            if (state.IsValid)
            {
                //state.TouchpadAxis = input.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
                //state.TriggerAxis = input.GetAxis(EVRButtonId.k_EButton_SteamVR_Trigger);
                //state.TouchpadTouch = input.GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad);
                //state.TouchpadPress = input.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad);
                //state.GripPress = input.GetPress(EVRButtonId.k_EButton_Grip);
                //state.MenuPress = input.GetPress(EVRButtonId.k_EButton_ApplicationMenu);


                state.TouchpadAxis  = TouchpadAxis.GetAxis(control.inputSource);
                state.TriggerAxis   = new Vector2(TriggerAxis.GetAxis(control.inputSource), 0);
                state.TouchpadTouch = TouchpadTouch.GetActive(control.inputSource);
                state.TouchpadPress = TouchpadPress.GetActive(control.inputSource);
                state.GripPress     = GripPress.GetActive(control.inputSource);
                state.MenuPress     = MenuPress.GetActive(control.inputSource);
            }

            return(state);
        }
    private void Update()
    {
        Show = WiresInRange.Count;

        if (IsInHand && ReadyToCut)
        {
            if (Trigger.GetActive(currentHand))
            {
                CutWire(closestWire);
                StartCoroutine(DelayNextCut());
            }
            else if (!VR)
            {
                if (Input.GetKeyDown(KeyCode.Alpha1))
                {
                    CutWire(closestWire);
                    StartCoroutine(DelayNextCut());
                }
            }
        }

        if (WiresInRange.Count > 0)
        {
            Wire  W    = WiresInRange[0];
            float Dist = Vector3.Distance(transform.position, W.transform.position);

            foreach (Wire w in WiresInRange)
            {
                float dist = Vector3.Distance(transform.position, w.transform.position);
                w.InRange.Remove(this);

                if (Dist > dist && (w.CanBeFixed && !w.active || w.active))
                {
                    W    = w;
                    Dist = dist;
                }
            }

            closestWire = W;

            closestWire.InRange.Add(this);
        }

        if (!IsInHand && WiresInRange.Count > 0)
        {
            foreach (Wire w in WiresInRange)
            {
                w.InRange.Remove(this);
            }

            WiresInRange = new List <Wire>();
        }

        if (ReadyToCut && B.active)
        {
            CutWire(closestWire);

            ReadyToCut = false;
        }
        else if (!B.active)
        {
            ReadyToCut = true;
        }
    }
Exemple #6
0
    void FixedUpdate()
    {
        _Player.GetComponent <Rigidbody>().mass = _ViveMass;


        // The trigger is noisy, looks like only the first digit is reliable.
        _TriggerVal = 0;
        if (_throttle_action != null && _throttle_action.GetActive(SteamVR_Input_Sources.Any))
        {
            float value = (float)Math.Round(_throttle_action.GetAxis(SteamVR_Input_Sources.Any), 1);
            if (value > 0)
            {
                _TriggerVal = value;
            }
        }
        _Speed = _Player.GetComponent <Rigidbody>().velocity.magnitude;

        if (_TriggerVal > 0 && _EnableMovePlatform)
        {
            _DirectionArrow.SetActive(true);

            if (_Speed < _MaxSpeed)
            {
                Vector3 directionOfForce = new Vector3(60f, 0f, 0f);
                Vector3 directionVector  = Quaternion.Euler(directionOfForce) * Vector3.forward;

                if (_move_backwards_action != null && _move_backwards_action.GetActive(SteamVR_Input_Sources.Any))
                {
                    if (_move_backwards_action.GetState(SteamVR_Input_Sources.Any))
                    {
                        directionVector = Quaternion.Euler(directionOfForce) * Vector3.back;
                        _DirectionArrow.transform.localEulerAngles = new Vector3(-58f, 180f, 0f);
                        _DirectionArrow.transform.localPosition    = new Vector3(0f, 0f, 0f);
                    }
                    else
                    {
                        _DirectionArrow.transform.localEulerAngles = new Vector3(58f, 0f, 0f);
                        _DirectionArrow.transform.localPosition    = new Vector3(0f, -0.0609f, 0.038f);
                    }
                }

                Vector3 forceDirection = _RightHand.transform.rotation * directionVector * _ViveMoveForce * (float)_TriggerVal;

                _Player.GetComponent <Rigidbody>().drag = _ViveNormalDrag;
                _Player.GetComponent <Rigidbody>().AddForce(forceDirection, ForceMode.Acceleration);

                _Player.GetComponent <Rigidbody>().maxAngularVelocity = 2f;
            }
            else
            {
                float   brakeSpeed         = _Speed - _MaxSpeed;
                Vector3 normalisedVelocity = _Player.GetComponent <Rigidbody>().velocity.normalized;
                Vector3 brakeVelocity      = normalisedVelocity * brakeSpeed * _ViveBreakFactor;
                _Player.GetComponent <Rigidbody>().AddForce(-brakeVelocity);
            }
        }
        else
        {
            _DirectionArrow.SetActive(false);
            _Player.GetComponent <Rigidbody>().drag = _ViveStopDrag;
        }
    }
Exemple #7
0
 private bool isTouchingTrackpad(Hand hand)
 {
     return(touchingTrackpadAction.GetActive(hand.handType));
 }