Exemple #1
0
        void Awake()
        {
            Head = new GameObject("Head").AddComponent <VRCamera>();
            Head.transform.parent = transform;

            LeftController = new GameObject("LeftController").AddComponent <VRController>();
            LeftController.transform.parent = transform;
            LeftController.NodeType         = VRNodeType.LeftHand;

            RightController = new GameObject("RightController").AddComponent <VRController>();
            RightController.transform.parent = transform;
            RightController.NodeType         = VRNodeType.RightHand;
        }
Exemple #2
0
        public static void Update()
        {
            if (!_active)
            {
                return;
            }


            if (_ray == null)
            {
                _ray = GameObject.CreatePrimitive(PrimitiveType.Cube);
                GameObject.Destroy(_ray.GetComponent <Collider>());
            }

            VRController controller = VRManager.Instance.Player.RightController;
            Ray          ray        = new Ray(controller.transform.position, controller.transform.forward);

            if (Physics.Raycast(ray, out RaycastHit hit, float.PositiveInfinity))
            {
                if (!_ray.activeSelf)
                {
                    _ray.SetActive(true);
                }

                Vector3 offset = hit.point - controller.transform.position;
                float   length = offset.magnitude;
                _ray.transform.localScale    = new Vector3(0.02f, 0.02f, length);
                _ray.transform.localPosition = offset / 2f + controller.transform.position;
                _ray.transform.forward       = offset.normalized;

                Component componentWithSelectHandaler = getInterfaceComponent <ISelectHandler>(hit.collider.gameObject);
                if (componentWithSelectHandaler != null)
                {
                    if (!_selectedObjects.Contains(componentWithSelectHandaler))
                    {
                        deselectEverything();
                        ((ISelectHandler)componentWithSelectHandaler).OnSelect(new BaseEventData(_eventSystem));
                        _selectedObjects.Add(componentWithSelectHandaler);
                    }
                }


                if (controller.ControllerState.GetFrontTriggerValue() > 0.5f)
                {
                    if (!_hasClickedCurrentSelectable)
                    {
                        Component componentWithClickHandaler = getInterfaceComponent <IPointerClickHandler>(hit.collider.gameObject);
                        if (componentWithClickHandaler != null)
                        {
                            ((IPointerClickHandler)componentWithClickHandaler).OnPointerClick(new PointerEventData(_eventSystem));
                            DelegateScheduler.Instance.Schedule(refreshCanvases, 0f);
                            if (OnAnyButtonClicked != null)
                            {
                                OnAnyButtonClicked();
                            }
                            _hasClickedCurrentSelectable = true;
                        }
                    }
                }
                else
                {
                    _hasClickedCurrentSelectable = false;
                }
            }