コード例 #1
0
ファイル: VivePlayer.cs プロジェクト: raywind/VirtualTable
        public override void OnStartLocalPlayer()
        {
            base.OnStartLocalPlayer();

            tempCameraRig.SetActive(true);

            var controllerManager = FindObjectOfType<SteamVR_ControllerManager>();

            var left = controllerManager.left;
            var right = controllerManager.right;
            var leftTrackedObj = left.GetComponent<SteamVR_TrackedObject>();
            var rightTrackedObj = right.GetComponent<SteamVR_TrackedObject>();

            // add interaction controllers
            // left
            _leftInteraction = left.GetComponent<ViveInteractionController>();
            if (_leftInteraction == null)
                _leftInteraction = left.AddComponent<ViveInteractionController>();
            // right
            _rightInteraction = right.GetComponent<ViveInteractionController>();
            if (_rightInteraction == null)
                _rightInteraction = right.AddComponent<ViveInteractionController>();

            // add vive player input
            // left
            _leftInput = left.GetComponent<VivePlayerInput>();
            if (_leftInput == null)
                _leftInput = left.AddComponent<VivePlayerInput>();

            // right
            _rightInput = right.GetComponent<VivePlayerInput>();
            if (_rightInput == null)
                _rightInput = right.AddComponent<VivePlayerInput>();

            // Update the input slots added in OnStartClient
            FindAttachmentSlot(leftController).input = _leftInput;
            FindAttachmentSlot(rightController).input = _rightInput;

            // the interactin controllers also need the player input
            _leftInteraction.input = _leftInput;
            _rightInteraction.input = _rightInput;

            // add the tracked object to the VivePlayerInput
            // for it to know where to get input from
            _leftInput.trackedObj = leftTrackedObj;
            _rightInput.trackedObj = rightTrackedObj;

            // connect pickup and drop delegates of the interaction controllers
            // to be notified when we should pick up a usable item
            _leftInteraction.UsableItemPickedUp += ItemPickedUp;
            _rightInteraction.UsableItemPickedUp += ItemPickedUp;
            _leftInteraction.UsableItemDropped += ItemDropped;
            _rightInteraction.UsableItemDropped += ItemDropped;

            // finally we want to find the gameobject representation
            // of the actual vive HMD
            // todo: can we do this a bit cleaner?
            var trackedObjects = FindObjectsOfType<SteamVR_TrackedObject>();
            foreach (var obj in trackedObjects)
            {
                if (obj.index == SteamVR_TrackedObject.EIndex.Hmd)
                {
                    hmd = obj.gameObject;
                }
            }

            if (hmd == null)
                Debug.LogError("VivePlayer: couldn't find a hmd for the local player");

        }
コード例 #2
0
ファイル: VivePlayer.cs プロジェクト: cpvrlab/VirtualTable
        public override void OnStartLocalPlayer()
        {
            base.OnStartLocalPlayer();

            tempCameraRig.SetActive(true);

            var controllerManager = FindObjectOfType<SteamVR_ControllerManager>();

            var left = controllerManager.left;
            var right = controllerManager.right;
            var leftTrackedObj = left.GetComponent<SteamVR_TrackedObject>();
            var rightTrackedObj = right.GetComponent<SteamVR_TrackedObject>();

            // add interaction controllers
            // left
            _leftInteraction = left.GetComponent<ViveInteractionController>();
            if (_leftInteraction == null)
                _leftInteraction = left.AddComponent<ViveInteractionController>();
            // right
            _rightInteraction = right.GetComponent<ViveInteractionController>();
            if (_rightInteraction == null)
                _rightInteraction = right.AddComponent<ViveInteractionController>();

            // add vive player input
            // left
            _leftInput = left.GetComponent<VivePlayerInput>();
            if (_leftInput == null)
                _leftInput = left.AddComponent<VivePlayerInput>();

            // right
            _rightInput = right.GetComponent<VivePlayerInput>();
            if (_rightInput == null)
                _rightInput = right.AddComponent<VivePlayerInput>();

            // Update the input slots added in OnStartClient
            FindAttachmentSlot(leftController).input = _leftInput;
            FindAttachmentSlot(rightController).input = _rightInput;

            // the interactin controllers also need the player input
            _leftInteraction.input = _leftInput;
            _rightInteraction.input = _rightInput;

            // add the tracked object to the VivePlayerInput
            // for it to know where to get input from
            _leftInput.trackedObj = leftTrackedObj;
            _rightInput.trackedObj = rightTrackedObj;

            // connect pickup and drop delegates of the interaction controllers
            // to be notified when we should pick up a usable item
            _leftInteraction.UsableItemPickedUp += ItemPickedUp;
            _rightInteraction.UsableItemPickedUp += ItemPickedUp;
            _leftInteraction.UsableItemDropped += ItemDropped;
            _rightInteraction.UsableItemDropped += ItemDropped;

            // finally we want to find the gameobject representation
            // of the actual vive HMD
            // todo: can we do this a bit cleaner?
            var trackedObjects = FindObjectsOfType<SteamVR_TrackedObject>();
            foreach (var obj in trackedObjects)
            {
                if (obj.index == SteamVR_TrackedObject.EIndex.Hmd)
                {
                    hmd = obj.gameObject;
                }
            }

            if (hmd == null)
                Debug.LogError("VivePlayer: couldn't find a hmd for the local player");
        }