예제 #1
0
        public void UseRemoteInput(bool _useRemote)
        {
            if (_useRemote && InputDevice == AlternativeInputDevice)
            {
                return;
            }

            InputDevice = _useRemote ? AlternativeInputDevice : GetComponent <NVROculusInputDevice>();
            SkinnedMeshRenderer handSkin = GetComponentInChildren <SkinnedMeshRenderer> ();

            handSkin.enabled = !_useRemote;
            Collider[] handColliders = GetComponentsInChildren <Collider>();
            for (int i = 0; i < handColliders.Length; i++)
            {
                handColliders[i].enabled = !_useRemote;
            }

            if (_useRemote)
            {
                Animator[] allAnimators = GetComponentsInChildren <Animator>();
                if (allAnimators.Length > 0)
                {
                    foreach (var item in allAnimators)
                    {
                        item.enabled = false;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///   Adds the input device components to this hand to enable tracking for the given integration type.
        /// </summary>
        public void SetupInputDevice(NVRInputDevice input_device)
        {
            InputDevice = input_device;
            InitializeRenderModel(); // Initializes the render model for this hand from the Input Device.

            Inputs = new Dictionary <NVRButtons, NVRButtonInputs>(new NVRButtonsComparer());
            foreach (NVRButtons button in NVRButtonsHelper.Array)
            {
                if (Inputs.ContainsKey(button))
                {
                    throw new ApplicationException("Button already exists in Input dictionary. Duplicate button in helper array.");
                }
                Inputs.Add(button, new NVRButtonInputs(InputDevice, button));
            }
        }
예제 #3
0
        /// <summary>
        /// Reset the cached values for a new frame.
        /// </summary>
        /// <param name="inputDevice">NVRInputDevice</param>
        /// <param name="button">NVRButtons</param>
        public void FrameReset(NVRInputDevice inputDevice, NVRButtons button)
        {
            InputDevice = inputDevice;
            NVRbutton   = button;

            PressDownExpired     = true;
            PressUpExpired       = true;
            IsPressedExpired     = true;
            TouchDownExpired     = true;
            TouchUpExpired       = true;
            IsTouchedExpired     = true;
            NearTouchDownExpired = true;
            NearTouchUpExpired   = true;
            IsNearTouchedExpired = true;
            AxisExpired          = true;
            SingleAxisExpired    = true;
        }
예제 #4
0
        private void Awake()
        {
            if (AutoSetFixedDeltaTime)
            {
                Time.fixedDeltaTime = NewtonVRExpectedDeltaTime;
            }

            Instances.Add(this);

            NVRInteractables.Initialize();

            if (Head == null)
            {
                Head = GetComponentInChildren <NVRHead>();
            }
            Head.Initialize();

            if (LeftHand == null || RightHand == null)
            {
                Debug.LogError("[FATAL ERROR] Please set the left and right hand to a nvrhands.");
            }

            ColliderToHandMapping = new Dictionary <Collider, NVRHand>();

            SetupIntegration();

            if (Hands.Count == 0)
            {
                Hands = new List <NVRHand> {
                    LeftHand, RightHand
                };

                foreach (NVRHand hand in Hands)
                {
                    hand.PreInitialize(this);
                    NVRInputDevice dev = null;
                    switch (CurrentIntegrationType)
                    {
                    case NVRSDKIntegrations.Oculus:
                        dev = hand.gameObject.AddComponent <NVROculusInputDevice>();
                        break;

                    case NVRSDKIntegrations.SteamVR:
                        dev = hand.gameObject.AddComponent <NVRSteamVRInputDevice>();
                        break;

                    case NVRSDKIntegrations.FallbackNonVR:
                    case NVRSDKIntegrations.None:
                    default:
                        Debug.LogError("[NewtonVR] Error: NVRPlayer.CurrentIntegration not setup.");
                        break;
                    }

                    dev.Initialize(hand);
                    hand.SetupInputDevice(dev);
                }
            }

            if (Integration != null)
            {
                Integration.Initialize(this);
            }

            if (OnInitialized != null)
            {
                OnInitialized.Invoke();
            }
        }
예제 #5
0
        public virtual void PreInitialize(NVRPlayer player)
        {
            Player = player;

            IsRight = Player.RightHand == this;
            IsLeft  = Player.LeftHand == this;

            CurrentInteractionStyle = Player.InteractionStyle;

            CurrentlyHoveringOver = new Dictionary <NVRInteractable, Dictionary <Collider, float> >();

            LastPositions         = new Vector3[EstimationSamples];
            LastRotations         = new Quaternion[EstimationSamples];
            LastDeltas            = new float[EstimationSamples];
            EstimationSampleIndex = 0;

            VisibilityLocked = false;

            Inputs = new Dictionary <NVRButtons, NVRButtonInputs>(new NVRButtonsComparer());
            for (int buttonIndex = 0; buttonIndex < NVRButtonsHelper.Array.Length; buttonIndex++)
            {
                if (Inputs.ContainsKey(NVRButtonsHelper.Array[buttonIndex]) == false)
                {
                    Inputs.Add(NVRButtonsHelper.Array[buttonIndex], new NVRButtonInputs());
                }
            }

            if (Player.CurrentIntegrationType == NVRSDKIntegrations.Oculus)
            {
                InputDevice = this.gameObject.AddComponent <NVROculusInputDevice>();

                if (Player.OverrideOculus == true)
                {
                    if (IsLeft)
                    {
                        CustomModel             = Player.OverrideOculusLeftHand;
                        CustomPhysicalColliders = Player.OverrideOculusLeftHandPhysicalColliders;
                    }
                    else if (IsRight)
                    {
                        CustomModel             = Player.OverrideOculusRightHand;
                        CustomPhysicalColliders = Player.OverrideOculusRightHandPhysicalColliders;
                    }
                    else
                    {
                        Debug.LogError("[NewtonVR] Error: Unknown hand for oculus model override.");
                    }
                }
            }
            else if (Player.CurrentIntegrationType == NVRSDKIntegrations.SteamVR)
            {
                InputDevice = this.gameObject.AddComponent <NVRSteamVRInputDevice>();

                if (Player.OverrideSteamVR == true)
                {
                    if (IsLeft)
                    {
                        CustomModel             = Player.OverrideSteamVRLeftHand;
                        CustomPhysicalColliders = Player.OverrideSteamVRLeftHandPhysicalColliders;
                    }
                    else if (IsRight)
                    {
                        CustomModel             = Player.OverrideSteamVRRightHand;
                        CustomPhysicalColliders = Player.OverrideSteamVRRightHandPhysicalColliders;
                    }
                    else
                    {
                        Debug.LogError("[NewtonVR] Error: Unknown hand for SteamVR model override.");
                    }
                }
            }
            else
            {
                //Debug.LogError("[NewtonVR] Critical Error: NVRPlayer.CurrentIntegration not setup.");
                return;
            }

            if (Player.OverrideAll)
            {
                if (IsLeft)
                {
                    CustomModel             = Player.OverrideAllLeftHand;
                    CustomPhysicalColliders = Player.OverrideAllLeftHandPhysicalColliders;
                }
                else if (IsRight)
                {
                    CustomModel             = Player.OverrideAllRightHand;
                    CustomPhysicalColliders = Player.OverrideAllRightHandPhysicalColliders;
                }
                else
                {
                    Debug.LogError("[NewtonVR] Error: Unknown hand for SteamVR model override.");
                    return;
                }
            }


            InputDevice.Initialize(this);
            InitializeRenderModel();
        }
예제 #6
0
        private void Update()
        {
            NVRInputDevice   nvrinputDevice   = (NVRInputDevice)UnityEngine.Object.FindObjectOfType(typeof(NVRInputDevice));
            PlayerController playerController = (PlayerController)UnityEngine.Object.FindObjectOfType(typeof(PlayerController));
            Vector2          axis2D           = nvrinputDevice.GetAxis2D(NVRButtons.Axis2);

            if (Input.GetKeyDown(KeyCode.H))
            {
                foreach (GameObject gameObject in UnityEngine.Object.FindObjectsOfType <GameObject>())
                {
                    if (gameObject.layer == 8)
                    {
                        gameObject.layer = 0;
                    }
                }
            }
            if (Input.GetKeyDown(KeyCode.BackQuote))
            {
                this.debugVisible = !this.debugVisible;
            }
            if (Input.GetKeyDown(KeyCode.F2))
            {
                this.freecamEnabled = !this.freecamEnabled;
            }
            if (this.freecamEnabled)
            {
                if (Input.GetKeyDown(KeyCode.F3))
                {
                    Debug.Log("Toggle vertical control: " + this.verticalControl.ToString());
                    this.verticalControl = !this.verticalControl;
                }
                if (Input.GetKeyDown(KeyCode.F4))
                {
                    this.speed = ((this.speed > 10f) ? 0f : (this.speed + 1f));
                    Debug.Log("freecam speed: " + this.speed);
                }
                if ((double)nvrinputDevice.GetAxis2D(NVRButtons.Touchpad).y > 0.5 && this.verticalControl)
                {
                    playerController.CachedTransform.Translate(0f, this.speed * Time.deltaTime, 0f, Space.World);
                }
                if ((double)nvrinputDevice.GetAxis2D(NVRButtons.Touchpad).y < -0.5 && this.verticalControl)
                {
                    playerController.CachedTransform.Translate(0f, -(this.speed * Time.deltaTime), 0f, Space.World);
                }
                if ((double)axis2D.x < -0.3)
                {
                    playerController.CachedTransform.Rotate(Vector3.up, -(this.speed * 30f * Time.deltaTime * Math.Abs(axis2D.x)));
                }
                if ((double)axis2D.x > 0.6)
                {
                    playerController.CachedTransform.Rotate(Vector3.up, this.speed * 30f * Time.deltaTime * Math.Abs(axis2D.x));
                }
                if ((double)axis2D.y < -0.6)
                {
                    playerController.CachedTransform.Translate(0f, 0f, -(this.speed * Time.deltaTime * Math.Abs(axis2D.y)), Space.Self);
                }
                if ((double)axis2D.y > 0.3)
                {
                    playerController.CachedTransform.Translate(0f, 0f, this.speed * Time.deltaTime * axis2D.y, Space.Self);
                }
            }
            if (Input.GetKeyDown(KeyCode.F5))
            {
                int num = 0;
                foreach (MeshRenderer meshRenderer in UnityEngine.Object.FindObjectsOfType <MeshRenderer>())
                {
                    if (meshRenderer.material != null && meshRenderer.material.name != null && meshRenderer.material.name.Contains("trigger"))
                    {
                        num++;
                    }
                }
                Debug.Log("Trigger meshes found: " + num);
            }
            if (Input.GetKeyDown(KeyCode.F6))
            {
                Material material = new Material(UnityEngine.Object.FindObjectOfType <MeshRenderer>().material);
                foreach (MeshRenderer meshRenderer2 in UnityEngine.Object.FindObjectsOfType <MeshRenderer>())
                {
                    Material material2 = meshRenderer2.material;
                    meshRenderer2.material = material;
                    material = material2;
                }
            }
            int num2 = 0;

            if (Input.GetKey(KeyCode.LeftShift))
            {
                num2 = 8;
            }
            if (Input.GetKeyDown(KeyCode.Keypad1))
            {
                StationController stationController = UnityEngine.Object.FindObjectOfType <StationController>();
                if (stationController != null)
                {
                    stationController.ChangeAlternativeLevel("AccPlus_Stomach_MASTER");
                    stationController.BroadcastLevelComplete();
                }
                return;
            }
            if (Input.GetKeyDown(KeyCode.Keypad2))
            {
                StationController stationController2 = UnityEngine.Object.FindObjectOfType <StationController>();
                if (stationController2 != null)
                {
                    stationController2.ChangeAlternativeLevel("AccPlus_Finale_MASTER");
                    stationController2.BroadcastLevelComplete();
                }
                return;
            }
            if (Input.GetKeyDown(KeyCode.Keypad3))
            {
                StationController stationController3 = UnityEngine.Object.FindObjectOfType <StationController>();
                if (stationController3 != null)
                {
                    stationController3.ChangeAlternativeLevel("AccPlus_Arg_MASTER");
                    stationController3.BroadcastLevelComplete();
                }
                return;
            }
            if (Input.GetKeyDown(KeyCode.Keypad4))
            {
                StationController stationController4 = UnityEngine.Object.FindObjectOfType <StationController>();
                if (stationController4 != null)
                {
                    stationController4.ChangeAlternativeLevel("AccPlus_Office_MASTER");
                    stationController4.BroadcastLevelComplete();
                }
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha1))
            {
                SceneManager.LoadScene(num2, LoadSceneMode.Additive);
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha2))
            {
                SceneManager.LoadScene(1 + num2, LoadSceneMode.Additive);
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha3))
            {
                SceneManager.LoadScene(2 + num2, LoadSceneMode.Additive);
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha4))
            {
                SceneManager.LoadScene(3 + num2, LoadSceneMode.Additive);
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha5))
            {
                SceneManager.LoadScene(4 + num2, LoadSceneMode.Additive);
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha6))
            {
                SceneManager.LoadScene(5 + num2, LoadSceneMode.Additive);
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha7))
            {
                SceneManager.LoadScene(6 + num2, LoadSceneMode.Additive);
                return;
            }
            if (Input.GetKeyDown(KeyCode.Alpha8))
            {
                SceneManager.LoadScene(7 + num2, LoadSceneMode.Additive);
            }
        }
예제 #7
0
 public NVRButtonInputs(NVRInputDevice device, NVRButtons button)
 {
     nvrbutton    = button;
     input_device = device;
 }