public void OnUpdate(CADisplayLink sender) {
bool hasTouchesBegan = false;
bool hasTouchesMoved = false;
bool hasTouchesEnded = false;
bool hasTouchesCancelled = false;
int touchCount = Input.touchCount;
if (touchCount > 0) {
int count = Input.touches.Length;
for (int i=0; i<count; i++) {
Touch touch = Input.touches [i];
UITouch uiTouch = new UITouch ();
uiTouch.fingerId = touch.fingerId;
uiTouch.phase = touch.phase;
uiTouch.location = Camera.main.ScreenToWorldPoint (touch.position) * PIXEL_PER_UNIT;
uiTouch.tapCount = touch.tapCount;
uiTouch.timestamp = DateTime.Now;
if (touch.phase == TouchPhase.Began) {
touchesBegan.Add (uiTouch);
hasTouchesBegan = true;
} else if (touch.phase == TouchPhase.Moved) {
touchesMoved.Add (uiTouch);
hasTouchesMoved = true;
} else if (touch.phase == TouchPhase.Ended) {
touchesEnded.Add (uiTouch);
hasTouchesEnded = true;
} else if (touch.phase == TouchPhase.Canceled) {
touchesCancelled.Add (uiTouch);
hasTouchesCancelled = true;
}
}
} else {
#if UNITY_EDITOR
#if UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_WP8_1
if(Input.GetMouseButtonDown(0)){
UITouch uiTouch = new UITouch();
uiTouch.fingerId = UITouch.SINGLE_TOUCH_ID;
uiTouch.phase = TouchPhase.Began;
uiTouch.location = Camera.main.ScreenToWorldPoint(Input.mousePosition) * PIXEL_PER_UNIT;
uiTouch.tapCount = 1;
uiTouch.timestamp = DateTime.Now;
touchesBegan.Add (uiTouch);
hasTouchesBegan = true;
}else if(Input.GetMouseButtonUp(0)){
UITouch uiTouch = new UITouch();
uiTouch.fingerId = UITouch.SINGLE_TOUCH_ID;
uiTouch.phase = TouchPhase.Ended;
uiTouch.location = Camera.main.ScreenToWorldPoint(Input.mousePosition) * PIXEL_PER_UNIT;
uiTouch.tapCount = 1;
uiTouch.timestamp = DateTime.Now;
touchesEnded.Add (uiTouch);
hasTouchesEnded = true;
}else if(Input.GetMouseButton(0)){
UITouch uiTouch = new UITouch();
uiTouch.fingerId = UITouch.SINGLE_TOUCH_ID;
uiTouch.phase = TouchPhase.Moved;
uiTouch.location = Camera.main.ScreenToWorldPoint(Input.mousePosition) * PIXEL_PER_UNIT;
uiTouch.tapCount = 1;
uiTouch.timestamp = DateTime.Now;
touchesMoved.Add (uiTouch);
hasTouchesMoved = true;
}
#endif
#endif
}
if (hasTouchesBegan)
_rootViewController.view.touchesBegan (touchesBegan);
if (hasTouchesMoved)
_rootViewController.view.touchesMoved (touchesMoved);
if (hasTouchesEnded)
_rootViewController.view.touchesEnded (touchesEnded);
if (hasTouchesCancelled)
_rootViewController.view.touchesCancelled (touchesCancelled);
touchesBegan.Clear ();
touchesMoved.Clear ();
touchesEnded.Clear ();
touchesCancelled.Clear ();
#if UNITY_STANDALONE || UNITY_WEBGL
if (Input.GetMouseButtonDown (0)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.mouseDown (nsevent);
} else if (Input.GetMouseButtonUp (0)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.mouseUp (nsevent);
} else if (Input.GetMouseButton (0)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.mouseDragged (nsevent);
} else if (Input.GetMouseButtonDown (1)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.rightMouseDown (nsevent);
} else if (Input.GetMouseButtonUp (1)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.rightMouseUp (nsevent);
} else if (Input.GetMouseButton (1)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.rightMouseDragged (nsevent);
} else if (Input.GetMouseButtonDown (2)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.otherMouseDown (nsevent);
} else if (Input.GetMouseButtonUp (2)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.otherMouseUp (nsevent);
} else if (Input.GetMouseButton (2)) {
NSEvent nsevent = getMouseEvent ();
_rootViewController.view.otherMouseDragged (nsevent);
}else{
float d = Input.GetAxis("Mouse ScrollWheel");
if(!FloatUtils.EQ(d, 0)){
NSEvent wheelEvt = getMouseEvent();
wheelEvt.mouseWheelDelta = d;
_rootViewController.view.scrollWheel(wheelEvt);
}
float dx = Input.GetAxis("Mouse X");
float dy = Input.GetAxis("Mouse Y");
if(!FloatUtils.EQ(dx, 0) || !FloatUtils.EQ(dy, 0)){
NSEvent nsevent = getMouseEvent ();
nsevent.mouseDelta = new Vector2(dx, dy) * PIXEL_PER_UNIT;
_rootViewController.view.mouseMoved(nsevent);
}
}
//Keybaord Events
keyboardEvent();
#endif
}
#if UNITY_STANDALONE || UNITY_WEBGL