using UnityEngine;
using System.Collections;
public class jarodInputController : MonoBehaviour {
private float fingerActionSensitivity = Screen.width * 0.05f; //手指动作的敏感度,这里设定为 二十分之一的屏幕宽度.
//
private float fingerBeginX;
private float fingerBeginY;
private float fingerCurrentX;
private float fingerCurrentY;
private float fingerSegmentX;
private float fingerSegmentY;
//
private int fingerTouchState;
//
private int FINGER_STATE_NULL = ;
private int FINGER_STATE_TOUCH = ;
private int FINGER_STATE_ADD = ;
// Use this for initialization
void Start ()
{
fingerActionSensitivity = Screen.width * 0.05f;
fingerBeginX = ;
fingerBeginY = ;
fingerCurrentX = ;
fingerCurrentY = ;
fingerSegmentX = ;
fingerSegmentY = ;
fingerTouchState = FINGER_STATE_NULL;
}
// Update is called once per frame
void Update ()
{
if (Input.GetKeyDown (KeyCode.Mouse0))
{
if(fingerTouchState == FINGER_STATE_NULL)
{
fingerTouchState = FINGER_STATE_TOUCH;
fingerBeginX = Input.mousePosition.x;
fingerBeginY = Input.mousePosition.y;
}
}
if(fingerTouchState == FINGER_STATE_TOUCH)
{
fingerCurrentX = Input.mousePosition.x;
fingerCurrentY = Input.mousePosition.y;
fingerSegmentX = fingerCurrentX - fingerBeginX;
fingerSegmentY = fingerCurrentY - fingerBeginY;
}
if (fingerTouchState == FINGER_STATE_TOUCH)
{
float fingerDistance = fingerSegmentX*fingerSegmentX + fingerSegmentY*fingerSegmentY;
if (fingerDistance > (fingerActionSensitivity*fingerActionSensitivity))
{
toAddFingerAction();
}
}
if (Input.GetKeyUp(KeyCode.Mouse0))
{
fingerTouchState = FINGER_STATE_NULL;
}
}
private void toAddFingerAction()
{
fingerTouchState = FINGER_STATE_ADD;
if (Mathf.Abs (fingerSegmentX) > Mathf.Abs (fingerSegmentY))
{
fingerSegmentY = ;
}
else
{
fingerSegmentX = ;
}
if (fingerSegmentX == )
{
if (fingerSegmentY > )
{
Debug.Log ("up");
}
else {
Debug.Log ("down");
}
}
else if(fingerSegmentY == )
{
if(fingerSegmentX > )
{
Debug.Log ("right");
}
else
{
Debug.Log("left");
}
}
}
}