Example #1
0
        /// <summary>
        /// Enables this controller.
        /// </summary>
        public void OnEnable()
        {
            if (instance != null)
            {
                Debug.LogError("More than one DpnController instance was found in your scene. "
                               + "Ensure that there is only one DpnController.");
                instance.enabled = false;
            }
            //string deviceName = "WiseVision_DayDream_Controller";
            string deviceName = null;

            if (DpnManager.peripheral == DPVRPeripheral.Flip)
            {
                deviceName = "SkyWorth_DayDream_Controller";
            }
            if (!OpenPeripheral(deviceName))
            {
                Debug.Log("Open Peripheral " + deviceName + " fails.");
                return;
            }

            instance = this;

            if (DpnManager.DPVRPointer)
            {
                Pointer = Instantiate(reticlePointer);
                Pointer.SetParent(this.transform, false);
                Pointer.gameObject.SetActive(false);
                DpnBasePointer pointer = Pointer.GetComponent <DpnBasePointer>();
                if (pointer)
                {
                    pointer.SetTitledAngle(-15.0f);
                }
            }
        }
        protected override void ProcessMove(PointerEventData pointerEvent)
        {
            // process pointer move
            if (DpnManager.DPVRPointer)
            {
                GameObject gameObject = pointerEvent.pointerCurrentRaycast.gameObject;
                if (gameObject)
                {
                    BaseRaycaster raycaster       = pointerEvent.pointerCurrentRaycast.module;
                    Ray           intersectionRay = new Ray();
                    if (raycaster != null)
                    {
                        DpnBasePointer pointer = DpnPointerManager.Pointer as DpnBasePointer;
                        intersectionRay = pointer.GetRay();
                    }
                    else if (pointerEvent.enterEventCamera != null)
                    {
                        Camera cam = pointerEvent.enterEventCamera;
                        intersectionRay = new Ray(cam.transform.position, cam.transform.forward);
                    }

                    Vector3 intersectionPos = pointerEvent.pointerCurrentRaycast.worldPosition;
                    if (intersectionPos == Vector3.zero)
                    {
                        Camera camera = pointerEvent.enterEventCamera;
                        if (camera != null)
                        {
                            float intersectionDistance = pointerEvent.pointerCurrentRaycast.distance + camera.nearClipPlane;
                            intersectionPos = camera.transform.position + intersectionRay.direction * intersectionDistance;
                        }
                    }

                    bool interactived = pointerEvent.pointerPress != null ||
                                        ExecuteEvents.GetEventHandler <IPointerEnterHandler>(gameObject) != null;

                    if (_lastGameObejct == null)
                    {
                        DpnPointerManager.Pointer.OnPointerEnter(gameObject, intersectionPos, intersectionRay, interactived);

                        _lastGameObejct = gameObject;
                    }
                    else
                    {
                        DpnPointerManager.Pointer.OnPointerHover(gameObject, intersectionPos, intersectionRay, interactived);
                    }
                }
                else
                {
                    if (_lastGameObejct != null)
                    {
                        DpnPointerManager.Pointer.OnPointerExit(gameObject);
                        _lastGameObejct = null;
                    }
                }
            }

            base.ProcessMove(pointerEvent);
        }