DongYingLiangGuanYiGong/DongYing/Assets/Zion/Scripts/SInput.cs

85 lines
2.1 KiB
C#

using UnityEngine;
using System.Collections;
public class SInput : MonoBehaviour
{
private static float mouseX;
private static float mouseY;
private static float mouseS;
public static float controlX;
public static float controlY;
public static float controlS;
public static bool controlRight = false;
private float lastX;
private float lastY;
public static bool IsTouch2AndControlRot => Input.touchCount >= 2 || controlRight;
public static float GetAxis(string key)
{
//if (Run.UIService.HoverRect)
//{
// return 0;
//}
if (key == "Mouse X")
{
return mouseX + controlX;
}
if (key == "Mouse Y")
{
return mouseY + controlY;
}
if (key == "Mouse ScrollWheel")
{
return mouseS + Input.GetAxis("Mouse ScrollWheel") + controlS;
}
return 0;
}
public float lastScaleDis = -1;
private void Update()
{
float height = Screen.height;
var mp = Input.mousePosition;
if (!Input.GetMouseButtonDown(0) && !Input.GetMouseButtonDown(1))
{
mouseX = (mp.x - lastX) / height * 50;
mouseY = (mp.y - lastY) / height * 50;
}
lastX = mp.x;
lastY = mp.y;
if (IsTouch2AndControlRot)
{
if (Input.touchCount >= 2)
{
if (lastScaleDis < 0)
{
lastScaleDis = Vector3.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);
lastScaleDis = lastScaleDis / height * 10;
}
else
{
float nowdis = Vector3.Distance(Input.GetTouch(0).position, Input.GetTouch(1).position);
nowdis = nowdis / height * 10;
mouseS = (nowdis - lastScaleDis);
lastScaleDis = nowdis;
}
}
}
else
{
lastScaleDis = -1;
mouseS = 0;
}
}
}