コード例 #1
0
        void OnManageCursor(Vector3 position)
        {
            // Create Cursor
            if (m_CurrentCursorA.gameObject.activeSelf == false || m_CurrentCursorB.gameObject.activeSelf == false)
            {
                m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
                m_AnchorSelection.OnPointerUp(position);

                return;
            }

            // Selection
            if (m_MainCamera == null || !m_MainCamera.gameObject.activeInHierarchy)
            {
                m_MainCamera = Camera.main;
                if (m_MainCamera == null)
                {
                    Debug.LogError($"[{nameof(MeasureToolUIController)}] active main camera not found!");
                    return;
                }
            }

            RaycastHit hitInfo;
            Ray        ray = m_MainCamera.ScreenPointToRay(position);

            if (m_VREnableSelector.GetValue() && m_VRControllerSelector.GetValue() != null)
            {
                ray.origin    = m_VRControllerSelector.GetValue().position;
                ray.direction = m_VRControllerSelector.GetValue().forward;
            }

            if (Physics.Raycast(ray, out hitInfo))
            {
                if (hitInfo.transform.gameObject.Equals(m_CurrentCursorA))
                {
                    Dispatcher.Dispatch(ClearStatusAction.From(true));
                    Dispatcher.Dispatch(ClearStatusAction.From(false));
                    m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    m_AnchorSelection.SelectCursor(m_CurrentCursorA, m_SelectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    return;
                }

                if (hitInfo.transform.gameObject.Equals(m_CurrentCursorB))
                {
                    Dispatcher.Dispatch(ClearStatusAction.From(true));
                    Dispatcher.Dispatch(ClearStatusAction.From(false));
                    m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    m_AnchorSelection.SelectCursor(m_CurrentCursorB, m_SelectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    return;
                }
            }

            // Unselect
            Dispatcher.Dispatch(ClearStatusAction.From(true));
            Dispatcher.Dispatch(ClearStatusAction.From(false));
            m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
        }
コード例 #2
0
        void OnManageCursor(Vector3 position)
        {
            // Create Cursor
            if (m_CurrentCursorA.gameObject.activeSelf == false || m_CurrentCursorB.gameObject.activeSelf == false)
            {
                m_CreatePointOnScreen = true;
                m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
                if (m_AnchorSelection.OnPointerUp(position, m_CachedMeasureToolStateData.Value))
                {
                    Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.ClearStatus, ""));
                }
                else
                {
                    Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.SetStatusWithType,
                                                                    new StatusMessageData()
                    {
                        text = m_InstructionTapOnSurface, type = StatusMessageType.Instruction
                    }));
                }

                return;
            }

            // Selection
            if (m_MainCamera == null || !m_MainCamera.gameObject.activeInHierarchy)
            {
                m_MainCamera = Camera.main;
                if (m_MainCamera == null)
                {
                    Debug.LogError($"[{nameof(UIMeasureToolController)}] active main camera not found!");
                    return;
                }
            }

            RaycastHit hitInfo;
            Ray        ray = m_MainCamera.ScreenPointToRay(position);

            if (UIStateManager.current.stateData.VREnable)
            {
                ray.origin    = m_RightController.Value.position;
                ray.direction = m_RightController.Value.forward;
            }

            if (Physics.Raycast(ray, out hitInfo))
            {
                if (hitInfo.transform.gameObject.Equals(m_CurrentCursorA))
                {
                    Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.ClearStatus, ""));
                    m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    m_AnchorSelection.SelectCursor(m_CurrentCursorA, m_SelectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    return;
                }

                if (hitInfo.transform.gameObject.Equals(m_CurrentCursorB))
                {
                    Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.ClearStatus, ""));
                    m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    m_AnchorSelection.SelectCursor(m_CurrentCursorB, m_SelectedCursorMaterial, m_CachedCursorsMeshRenderer);
                    return;
                }
            }

            // Unselect
            Dispatcher.Dispatch(Payload <ActionTypes> .From(ActionTypes.ClearStatus, ""));
            m_AnchorSelection.UnselectCursor(m_UnselectedCursorMaterial, m_CachedCursorsMeshRenderer);
        }