-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from BobZombie/feature_mouse
Feature mouse
- Loading branch information
Showing
2 changed files
with
107 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |