Exemple #1
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();
            }
        }
        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();
        }