鼠标拖动
//鼠标拖动
private float previousPositionX;
private float offset;
private bool startReduceSpeed = false;
private bool startAddSpeed = false;
private bool startAddSpeed_reduce = false;
private float reduceSpeed = 10.0f;
private Vector3 mouseCurrentPos = Vector3.zero;
private void checkMouseDragChangeSpeed()
{
#if UNITY_EDITOR
if (Input.GetMouseButtonDown(0))
{
previousPositionX = Input.mousePosition.x;
startAddSpeed = false;
startAddSpeed_reduce = false;
startReduceSpeed = false;
roatSpeed = 15f;
}
if (Input.GetMouseButton(0)) //按下(状态)
{
offset = Input.mousePosition.x - previousPositionX;
if (offset > 0)
{
roatSpeed = 55f;
}
else if (offset < 0)
{
roatSpeed = -30f;
}
previousPositionX = Input.mousePosition.x;
}
if (Input.GetMouseButtonUp(0)) //抬起(瞬间)
{
if (roatSpeed < 15)
{
startAddSpeed = true;
startAddSpeed_reduce = true;
}
else if (roatSpeed > 15)
{
startReduceSpeed = true;
}
mouseCurrentPos = Input.mousePosition;
}
#elif UNITY_IOS || UNITY_ANDROID
if(Input.touchCount <= 0)
{
return;
}
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
startAddSpeed = false;
startAddSpeed_reduce = false;
startReduceSpeed = false;
roatSpeed = 15f;
}
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
if (Input.GetTouch(0).deltaPosition.x > 0)
{
roatSpeed = 55f;
}
else if (Input.GetTouch(0).deltaPosition.x < 0)
{
roatSpeed = -30f;
}
}
if (Input.GetTouch(0).phase == TouchPhase.Ended)
{
if (roatSpeed < 15)
{
startAddSpeed = true;
startAddSpeed_reduce = true;
}
else if (roatSpeed > 15)
{
startReduceSpeed = true;
}
}
#else
if (Input.GetMouseButtonDown(0))
{
previousPositionX = Input.mousePosition.x;
startAddSpeed = false;
startAddSpeed_reduce = false;
startReduceSpeed = false;
roatSpeed = 15f;
}
if (Input.GetMouseButton(0)) //按下(状态)
{
offset = Input.mousePosition.x - previousPositionX;
if (offset > 0)
{
roatSpeed = 55f;
}
else if (offset < 0)
{
roatSpeed = -30f;
}
previousPositionX = Input.mousePosition.x;
}
if (Input.GetMouseButtonUp(0)) //抬起(瞬间)
{
if (roatSpeed < 15)
{
startAddSpeed = true;
startAddSpeed_reduce = true;
}
else if (roatSpeed > 15)
{
startReduceSpeed = true;
}
mouseCurrentPos = Input.mousePosition;
//mouseIsMove = false;
}
#endif
}