mouseLeftClickType; //记录点击类型/// <summary>/// 该协程判断输入状态是单击双击还是长按,按下后状态4,拖动时状态3,双击2,单击1/// </summary>IEnumerator leftClickMonitor(float intervalInTwoClick = 0.2f){float firstClickTime = 0;while (true){leftMouseState = 0;if (Input.GetMouseButtonDown(0)){if (firstClickTime != 0){if (Time.time - firstClickTime <= intervalInTwoClick) {leftMouseState = 2;Debug.Log($"mouseState:{leftMouseState}");}firstClickTime = 0;}Vector3 downPosition = Input.mousePosition;leftMouseState = 4;Debug.Log($"mouseState:{leftMouseState}");while (downPosition == Input.mousePosition && Input.GetMouseButton(0)) yield return null;if (!Input.GetMouseButton(0))//在同一位置抬起鼠标{leftMouseState = 1;Debug.Log($"mouseState:{leftMouseState}");firstClickTime = Time.time;}else//按着鼠标挪动位置{leftMouseState = 3;Debug.Log($"mouseState:{leftMouseState}");while (Input.GetMouseButton(0)) yield return null;}}yield return null;}}
用该协程可以判断鼠标左键是单击,双击,还是长按