/// @brief Get a snapshot input value by enum. public float GetInputValue(GCInput eInput) { switch (eInput) { case GCInput.gpDPadXAxis: return(dpadX); case GCInput.gpDPadYAxis: return(dpadY); case GCInput.gpDPadUp: return(Mathf.Max(0.0f, dpadY)); case GCInput.gpDPadDown: return(Mathf.Max(0.0f, -dpadY)); case GCInput.gpDPadLeft: return(Mathf.Max(0.0f, -dpadX)); case GCInput.gpDPadRight: return(Mathf.Max(0.0f, dpadX)); case GCInput.gpButtonA: return(buttonA); case GCInput.gpButtonB: return(buttonB); case GCInput.gpButtonX: return(buttonX); case GCInput.gpButtonY: return(buttonY); case GCInput.gpLeftShoulder: return(leftShoulder); case GCInput.gpRightShoulder: return(rightShoulder); default: return(0.0f); } }
/// @brief Set a snapshot input value by enum. public void SetInputValue(GCInput eInput, float fValue) { switch (eInput) { case GCInput.gpDPadXAxis: dpadX = fValue; break; case GCInput.gpDPadYAxis: dpadY = fValue; break; case GCInput.gpDPadUp: break; case GCInput.gpDPadDown: break; case GCInput.gpDPadLeft: break; case GCInput.gpDPadRight: break; case GCInput.gpButtonA: buttonA = fValue; break; case GCInput.gpButtonB: buttonB = fValue; break; case GCInput.gpButtonX: buttonX = fValue; break; case GCInput.gpButtonY: buttonY = fValue; break; case GCInput.gpLeftShoulder: leftShoulder = fValue; break; case GCInput.gpRightShoulder: rightShoulder = fValue; break; default: break; } }
void OnDestroy() { if (IsUsing) { instance = null; } }
/// <summary> /// 使用当前的触摸状态去更新这个拖拽物体的位置 /// </summary> internal void Update() { if (caluCamera == null || isStop) { return; } //得到现在鼠标的2维坐标系位置 //Vector3 curScreenSpace = new Vector3(Input.mousePosition.x, Input.mousePosition.y, dragControlPoint.z); Vector3 curScreenSpace = new Vector3(GCInput.mousePosition.x, GCInput.mousePosition.y, dragControlPoint.z); //将当前鼠标的2维位置转换成3维位置,再加上鼠标的移动量 Vector3 curPosition = caluCamera.ScreenToWorldPoint(curScreenSpace) + offset; //curPosition就是物体应该的移动向量赋给transform的position属性 dragObj.position = curPosition; if (mouseBtn == -1) { mouseBtn = 0; } if (GCInput.GetMouseButtonUp(mouseBtn)) { try { EventStopDrag?.Invoke(this); } catch (Exception e) { Debug.Log("DragRecord.Update():执行用户事件EventStopDrag异常" + e.Message); } isStop = true; } }
/***************************** INPUT ACCESS *****************************/ ////////////////////////////////////////////////////////////////////////// /// @brief Get a controller input's value. ////////////////////////////////////////////////////////////////////////// public static float GetInputValue(int nController, GCInput eInput) { #if UNITY_IPHONE if( Application.platform == RuntimePlatform.IPhonePlayer ) return( _GCGetInputValue(nController, (int)eInput) ); #endif // UNITY_IPHONE return(0.0f); }
////////////////////////////////////////////////////////////////////////// /// @brief Get whether a controller input is currently pressed down. ////////////////////////////////////////////////////////////////////////// public static bool GetInputPressed(int nController, GCInput eInput) { #if UNITY_IPHONE if( Application.platform == RuntimePlatform.IPhonePlayer ) return( _GCGetInputPressed(nController, (int)eInput) ); #endif // UNITY_IPHONE return(false); }
// Update is called once per frame void Update() { if (_rotaModel != null) { RotaModel(); } if (GCInput.GetMouseButtonUp(0)) { _rotaModel = null; } }
/// <summary> /// 来自二分之一触摸 /// </summary> protected MouseState GetMousePointerData(int id) { PointerEventData leftData; /*var created = */ GetPointerData(kMouseLeftId, out leftData, true); leftData.Reset(); //Vector2 pos = is3D ? new Vector2(Input.mousePosition.x / 2, Input.mousePosition.y) : new Vector2(Input.mousePosition.x, Input.mousePosition.y); Vector2 pos = GCInput.mouseUIPosition; //支持投屏鼠标输入数据 leftData.delta = pos - leftData.position; leftData.position = pos; leftData.scrollDelta = Input.mouseScrollDelta; leftData.button = PointerEventData.InputButton.Left; m_RaycastResultCache.Clear(); eventSystem.RaycastAll(leftData, m_RaycastResultCache); //activeGraphicRaycaster2.ignoreRaycast = false; var raycast = FindFirstRaycast(m_RaycastResultCache); leftData.pointerCurrentRaycast = raycast; hitUIDis = raycast.distance; m_RaycastResultCache.Clear(); // copy the apropriate data into right and middle slots PointerEventData rightData; GetPointerData(kMouseRightId, out rightData, true); CopyFromTo(leftData, rightData); rightData.button = PointerEventData.InputButton.Right; PointerEventData middleData; GetPointerData(kMouseMiddleId, out middleData, true); CopyFromTo(leftData, middleData); middleData.button = PointerEventData.InputButton.Middle; m_MouseState.SetButtonState(PointerEventData.InputButton.Left, GCInput.GetStateForMouseButton(0), leftData); m_MouseState.SetButtonState(PointerEventData.InputButton.Right, GCInput.GetStateForMouseButton(1), rightData); m_MouseState.SetButtonState(PointerEventData.InputButton.Middle, GCInput.GetStateForMouseButton(2), middleData); return(m_MouseState); }
private void Update() { if (m_LogLevel <= Common.LogLevel.DEBUG) { Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "SimpleDrag.Update", ""); } if (GCInput.GetMouseButtonDown(0)) { if (m_LogLevel <= Common.LogLevel.DEBUG) { Common.AppLog.AddFormat(Common.LogLevel.DEBUG, "SimpleDrag.Update", "leftDown=true"); } Drag2DObj(); } if (GCInput.GetMouseButtonUp(0)) { OnMouseBtnUp(); } }
/// @brief Get a snapshot input value by enum. public float GetInputValue(GCInput eInput) { switch(eInput) { case GCInput.gpDPadXAxis: return(dpadX); case GCInput.gpDPadYAxis: return(dpadY); case GCInput.gpDPadUp: return(Math.Max(0.0f, dpadY)); case GCInput.gpDPadDown: return(Math.Max(0.0f, -dpadY)); case GCInput.gpDPadLeft: return(Math.Max(0.0f, -dpadX)); case GCInput.gpDPadRight: return(Math.Max(0.0f, dpadX)); case GCInput.gpButtonA: return(buttonA); case GCInput.gpButtonB: return(buttonB); case GCInput.gpButtonX: return(buttonX); case GCInput.gpButtonY: return(buttonY); case GCInput.gpLeftShoulder: return(leftShoulder); case GCInput.gpRightShoulder: return(rightShoulder); default: return(0.0f); } }
/*-------------支持投屏和触屏修改部分--------------*/ // The following 2 functions are equivalent to PointerInputModule.GetMousePointerEventData but are customized to // get data for ray pointers and canvas mouse pointers. /// <summary> /// State for a pointer controlled by a world space ray. E.g. gaze pointer /// </summary> /// <returns></returns> virtual protected MouseState GetGazePointerData() { // Get the OVRRayPointerEventData reference GCSeriesPointerEventData leftData; GetPointerData(kMouseLeftId, out leftData, true); leftData.Reset(); leftData.position = GCInput.mouseUIPosition; //Now set the world space ray. This ray is what the user uses to point at UI elements leftData.worldSpaceRay = new Ray(FCore.penPosition, FCore.penDirection); //leftData.scrollDelta = GetExtraScrollDelta(); //Populate some default values leftData.button = PointerEventData.InputButton.Left; leftData.useDragThreshold = true; // Perform raycast to find intersections with world m_RaycastResultCache.Clear(); eventSystem.RaycastAll(leftData, m_RaycastResultCache); var raycast = FindFirstRaycast(m_RaycastResultCache); leftData.pointerCurrentRaycast = raycast; //hitPos = new Vector3(1000f, 1000f, 1000f); GCSeriesRaycaster ovrRaycaster = raycast.module as GCSeriesRaycaster; if (!curPenRay) { curPenRay = GameObject.FindObjectOfType <PenRay>(); } bool isClickButtonOrToggle = false; // We're only interested in intersections from OVRRaycasters if (ovrRaycaster) { // The Unity UI system expects event data to have a screen position // so even though this raycast came from a world space ray we must get a screen // space position for the camera attached to this raycaster for compatability leftData.position = ovrRaycaster.GetScreenPosition(raycast); // Find the world position and normal the Graphic the ray intersected RectTransform graphicRect = raycast.gameObject.GetComponent <RectTransform>(); if (graphicRect != null) { // Set are gaze indicator with this world position and normal Vector3 worldPos = raycast.worldPosition; //射到UI上的点 //Vector3 normal = GetRectTransformNormal(graphicRect); //hitPos = worldPos; if (curPenRay) { curPenRay.hitUI_bool = true; curPenRay.hitUIWorldPos = worldPos; } } //获取父物体是否有button组件 Button uiButton = raycast.gameObject.GetComponentInParent <Button>(); if (uiButton) { Transform[] transforms = raycast.gameObject.GetComponentsInParent <Transform>(); //在限定的层级里寻找是否存在button组件,存在且不与上次的物体同名,则说明需要响应shake操作 int traverseTime = transforms.Length < traverseButtonTime ? transforms.Length : traverseButtonTime; for (int i = 0; i < traverseTime; i++) { if (transforms[i].name == uiButton.name) { isClickButtonOrToggle = true; if (lastCheckObj) { if (lastCheckObj.name != uiButton.name) { FCore.PenShake(); lastCheckObj = uiButton.gameObject; } } else { FCore.PenShake(); lastCheckObj = uiButton.gameObject; } } } } else { Toggle toggle = raycast.gameObject.GetComponentInParent <Toggle>(); if (toggle) { Transform[] transforms = raycast.gameObject.GetComponentsInParent <Transform>(); //在限定的层级里寻找是否存在button组件,存在且不与上次的物体同名,则说明需要响应shake操作 int traverseTime = transforms.Length < traverseToggleTime ? transforms.Length : traverseToggleTime; for (int i = 0; i < traverseTime; i++) { if (transforms[i].name == toggle.name) { isClickButtonOrToggle = true; if (lastCheckObj) { if (lastCheckObj.name != toggle.name) { FCore.PenShake(); lastCheckObj = toggle.gameObject; } } else { FCore.PenShake(); lastCheckObj = toggle.gameObject; } } } } else { lastCheckObj = null; } } } else { if (curPenRay) { curPenRay.hitUI_bool = false; //没有点到UI 或者说是移出UI lastCheckObj = null; } } if (curPenRay) { curPenRay.hitGameObject = raycast.gameObject; } if (!isClickButtonOrToggle) { m_PenState.SetButtonState(PointerEventData.InputButton.Left, GetPenButtonState(), leftData); } else { m_PenState.SetButtonState(PointerEventData.InputButton.Left, GetPenButtonClickToggleOrButton(), leftData); } //F3D.AppLog.AddMsg($"GCSeriesInputModule.eventSystem.RaycastAll.Count = {m_RaycastResultCache.Count}"); //m_PenState.SetButtonState(PointerEventData.InputButton.Left, PointerEventData.FramePressState.Released, leftData); //情况1:默认笔命中结果 (命中有交互功能UI) //情况2:笔没有命中 鼠标也没有命中 释放按压状态 if (raycast.gameObject == null) { m_PenState.SetButtonState(PointerEventData.InputButton.Left, GCInput.GetStateForMouseButton(0), leftData); } //情况3:笔没有命中 鼠标命中了 else if (raycast.gameObject != null && !(raycast.module is GCSeriesRaycaster)) { curPenRay.hitGameObject = null; leftData.useDragThreshold = false; leftData.delta = Vector2.zero; m_PenState.SetButtonState(PointerEventData.InputButton.Left, GCInput.GetStateForMouseButton(0), leftData); } //情况4:如果触笔命中了(但是无交互功能的UI) 则使用鼠标命中结果 else if (raycast.gameObject == null || (raycast.module is GCSeriesRaycaster && raycast.gameObject.GetComponent <Interactable>() == null)) { foreach (var item in m_RaycastResultCache) { if (item.module is GCSeriesRaycaster) { continue; } if (item.gameObject == null) { continue; } // F3D.AppLog.AddMsg($"GetGazePointerData {item.gameObject.name}"); //第一个鼠标输入数据命中的对象处理 curPenRay.hitGameObject = null; leftData.position = GCInput.mouseUIPosition; leftData.pointerCurrentRaycast = item; leftData.useDragThreshold = false; leftData.delta = Vector2.zero; m_PenState.SetButtonState(PointerEventData.InputButton.Left, GCInput.GetStateForMouseButton(0), leftData); break; } } m_RaycastResultCache.Clear(); //IsPointerOverGameObject判断需要 leftData.pointerEnter = leftData.pointerCurrentRaycast.gameObject; return(m_PenState); }
/// @brief Get a snapshot input pressed status by enum. public bool GetInputPressed(GCInput eInput) { return(Mathf.Abs(GetInputValue(eInput)) > k_fPressedThreshold); }