/// <summary>
 /// Creates a new <see cref="GearVRTrackedControllerProxy"/> for the specified avatar and controller type.
 /// </summary>
 /// <param name="avatar">The avatar that owns the controller.</param>
 /// <param name="controllerType">The controller type the proxy wraps.</param>
 public GearVRTrackedControllerProxy(IVRAvatar avatar, VRAvatarLimbType limbType)
 {
     mAvatar          = avatar;
     mAvatarTransform = mAvatar.Transform;
     mHeadTransform   = mAvatar.Head.Transform;
     mLimbType        = limbType;
 }
Exemplo n.º 2
0
        void IVRDevice.SetupAvatar(IVRAvatar avatar)
        {
            if (avatar == null)
            {
                throw new ArgumentNullException("avatar");
            }

            // Attach the GearVR avatar component
            // The component will take care of the rest of the setup
            var deviceAv = avatar.Transform.gameObject.AddComponent <GearVRAvatar>();

            deviceAv.hideFlags = HideFlags.NotEditable;

            UpdateConnectedControllers();
            SetDefaultPointerActivation();
        }
        public UnityXRTrackedControllerProxy(IVRAvatar avatar, VRAvatarLimbType limbType)
        {
            mAvatar          = avatar;
            mAvatarTransform = mAvatar.Transform;
            mHeadTransform   = mAvatar.Head.Transform;
            mLimbType        = limbType;

            if (TryGetXRNode(out XRNode outNode))
            {
                mInputDevice = InputDevices.GetDeviceAtXRNode(outNode);

                if (!mInputDevice.isValid)
                {
                    Debug.LogError($"No valid input device for {limbType}");
                    //throw new System.Exception($"No valid input device for {limbType}");
                }
            }
        }
Exemplo n.º 4
0
        public void SetupAvatar(IVRAvatar avatar)
        {
            var openVRAvatar = avatar.Transform.gameObject.AddComponent <OpenVRAvatar>();
            var rigPrefab    = Resources.Load("SteamVRRig");
            var rig          = GameObject.Instantiate(rigPrefab) as GameObject;

            rig.transform.SetParent(avatar.Auxiliaries);

            var leftHand  = rig.GetComponentsInChildren <SteamVR_Behaviour_Pose>().FirstOrDefault(x => x.inputSource == SteamVR_Input_Sources.LeftHand);
            var rightHand = rig.GetComponentsInChildren <SteamVR_Behaviour_Pose>().FirstOrDefault(x => x.inputSource == SteamVR_Input_Sources.RightHand);

            avatar.PrimaryHand.TrackedObject   = new OpenVRTrackedControllerProxy(rightHand, avatar.Head.Transform, avatar.Transform);
            avatar.SecondaryHand.TrackedObject = new OpenVRTrackedControllerProxy(leftHand, avatar.Head.Transform, avatar.Transform);

            var leftModel  = leftHand.GetComponentInChildren <SteamVR_RenderModel>();
            var rightModel = rightHand.GetComponentInChildren <SteamVR_RenderModel>();

            var coroutineService = new GameObject("Coroutine Service").AddComponent <CoroutineService>();

            coroutineService.StartCoroutine(MigrateModel(leftModel, avatar.SecondaryHand));
            coroutineService.StartCoroutine(MigrateModel(rightModel, avatar.PrimaryHand));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the avatar extension.
        /// </summary>
        /// <param name="avatar">The <see cref="IVRAvatar"/> the extension is bound to.</param>
        public void Initialize(IVRAvatar avatar)
        {
            mAvatar        = avatar;
            mDevice        = VRDevice.Device;
            mPointer       = mDevice.Headset.Pointer;
            mPointerVisual = m_PointerVisual;

            if (mPointerVisual == null)
            {
                if (mPointer.Transform == transform)
                {
                    mPointer.Transform = null;
                }
            }
            else
            {
                mPointerVisual.Bind(mPointer);
                mPointer.Transform = mPointerVisual.transform;
            }

            ApplyTimedPointerProperties();

            Debug.Log("Initialized");
        }
Exemplo n.º 6
0
        public void Initialize()
        {
            mAvatar = GetComponentInParent <IVRAvatar>();
            mAvatar.InitializeExtensions();

            mDevice    = VRDevice.Device;
            mGazeInput = GetComponent <GazeInput>();

            // Load controller visuals for any VRAvatarController objects attached to the avatar
            var avatarControllers = GetComponentsInChildren <VRAvatarController>(includeInactive: true);

            foreach (var controller in avatarControllers)
            {
                AttachControllerVisual(controller);
            }

            // Add event listeners
            mDevice.InputDeviceConnected     += OnInputDeviceConnected;
            mDevice.InputDeviceDisconnected  += OnInputDeviceDisconnected;
            mAvatar.Head.ActiveCameraChanged += OnActiveCameraChanged;

            SetupInitialControllerState();
            UpdateHandedness();
        }
Exemplo n.º 7
0
        private void Awake()
        {
            mAvatar = GetComponentInParent <IVRAvatar>();
            mAvatar.InitializeExtensions();

            mPrimaryControllerTracker   = new GearVRTrackedControllerProxy(mAvatar, VRAvatarLimbType.RightHand);
            mSecondaryControllerTracker = new GearVRTrackedControllerProxy(mAvatar, VRAvatarLimbType.LeftHand);

            mDevice    = VRDevice.Device;
            mSettings  = gameObject.GetOrAddComponent <GearVRAvatarSettings>();
            mGazeInput = GetComponent <GazeInput>();

            // Setup auxiliary systems
            SetupManager();
            SetupCameraRig();

            // Activate OVRManager once everything is setup
            mManager.gameObject.SetActive(true);

            // Load controller visuals for any VRAvatarController objects attached to the avatar
            {
                var avatarControllers = GetComponentsInChildren <VRAvatarController>(includeInactive: true);
                foreach (var controller in avatarControllers)
                {
                    AttachControllerVisual(controller);
                }
            }

            // Add event listeners
            mDevice.InputDeviceConnected     += OnInputDeviceConnected;
            mDevice.InputDeviceDisconnected  += OnInputDeviceDisconnected;
            mAvatar.Head.ActiveCameraChanged += OnActiveCameraChanged;
            SetupInitialControllerState();

            UpdateHandedness();
        }
Exemplo n.º 8
0
 private void OnTransformParentChanged()
 {
     mAvatar = GetComponentInParent <IVRAvatar>();
 }
Exemplo n.º 9
0
 private void OnVRAvatarChanged(IVRAvatar avatar)
 {
     CreateImplementation();
 }
Exemplo n.º 10
0
 void IVRDevice.SetupAvatar(IVRAvatar avatar)
 {
     mImpl.SetupAvatar(avatar);
 }