Skip to content

Commit

Permalink
Merge pull request #6 from BobZombie/feature_mouse
Browse files Browse the repository at this point in the history
Feature mouse
  • Loading branch information
moajo committed May 23, 2016
2 parents f8a42da + 8f72dab commit aae3092
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 9 deletions.
18 changes: 9 additions & 9 deletions scripts/MBTHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public void Awake(){

void Update () {

if (Input.touchCount == 0) {
MBTTouch.Update();

if (MBTTouch.touchCount == 0) {
return;
}

Expand All @@ -75,30 +77,28 @@ void Update () {
}
}

Touch nowTouch = Input.GetTouch(0);

switch (nowTouch.phase) {
switch (MBTTouch.phase) {
case TouchPhase.Began:
tapBeganPos = nowTouch.position;
tapBeganPos = MBTTouch.position;
break;
case TouchPhase.Moved:
case TouchPhase.Stationary:
touchTime += Time.deltaTime;

Vector3 vp = nowTouch.deltaPosition;
Vector3 vp = MBTTouch.deltaPosition;
if (vp.sqrMagnitude > tapDetectLength*tapDetectLength) {
if (vp.x*vp.x > vp.y*vp.y){
OnScroll(nowTouch.position.x, 0);
OnScroll(MBTTouch.position.x, 0);
} else {
OnScroll(0, nowTouch.position.y);
OnScroll(0, MBTTouch.position.y);
}
}
break;

case TouchPhase.Ended:
case TouchPhase.Canceled:

var endPos = nowTouch.position;
var endPos = MBTTouch.position;

//check tap and double tap.
if (touchTime < tapDetectTime) {
Expand Down
98 changes: 98 additions & 0 deletions scripts/MBTInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using UnityEngine;

public class MBTTouch
{
public static int touchCount
{
get;
private set;
}

public static Vector2 position
{
get;
private set;
}

public static Vector2 deltaPosition
{
get;
private set;
}

public static TouchPhase phase
{
get;
private set;
}


private static int _nowFrameCount = -1;

#if UNITY_EDITOR
private static Vector2 _prePos = Vector2.zero;
#else

#endif


public static void Update ()
{
if (_nowFrameCount==Time.frameCount)
{
return;
}

_nowFrameCount = Time.frameCount;

#if UNITY_EDITOR

if (Input.GetMouseButton(0))
{
touchCount = 1;
position = Input.mousePosition;

if (Input.GetMouseButtonDown(0))
{
phase = TouchPhase.Began;
deltaPosition = Vector2.zero;
}
else
{
phase = TouchPhase.Moved;
deltaPosition = _prePos - position;
}
_prePos = position;
}
else if (Input.GetMouseButtonUp(0))
{
touchCount = 1;
phase = TouchPhase.Ended;
position = Input.mousePosition;
deltaPosition= _prePos - position;
}
else
{
touchCount = 0;
phase = TouchPhase.Ended;
}

#else

touchCount = Input.touchCount;

if( 0<touchCount )
{
Touch nowTouch = Input.GetTouch(0);

phase = nowTouch.phase;
position = nowTouch.position;
deltaPosition = nowTouch.deltaPosition;
}
else
{
phase = TouchPhase.Ended;
}
#endif
}
}

0 comments on commit aae3092

Please sign in to comment.