Skip to content

Commit

Permalink
Add OnClockwise Delegate and functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
bono committed May 19, 2016
1 parent be6de59 commit b17e267
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
11 changes: 11 additions & 0 deletions scripts/ControlScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ void Start () {
MBTOnCharge ();
};

MBTHelper.OnClockwise += (flg) => {
Debug.Log ("::Clock " + flg.ToString() + "::");
ShowParameter("::Clock " + flg.ToString() + "::");
MBTOnClock (flg);
};

// DebugText.text = "";
}

Expand Down Expand Up @@ -66,6 +72,11 @@ private void MBTOnCharge () {

}

private void MBTOnClock (bool flg) {

}


private void ShowParameter (string st) {
if (DebugMode) {
DebugText.text = st;
Expand Down
34 changes: 34 additions & 0 deletions scripts/MBTHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public class MBTHelper : MonoBehaviour {
public delegate void Trigger();
public delegate void TouchPad(float x, float y);
public delegate void Gesture(string name);
public delegate void Clockwise(bool flg);

//タップの許容時間
public const float tapDetectTime = 1.0f;
Expand All @@ -29,6 +30,14 @@ public class MBTHelper : MonoBehaviour {
private int lastTime = 0;
private bool charged = false;


private const float CLOCK_PARAM_MAX = 20.0f;
private const float CLOCK_PARAM_THRESHOLD = 5.0f;
private const float CLOCK_PARAM_ADD = 1.0f;
private const float CLOCK_PARAM_GAIN = 0.9f;
private float clockParam = 0f;


void Start () {
if (minSwipeDistX == 0) {
minSwipeDistX = 50;
Expand All @@ -45,13 +54,15 @@ void Start () {
public static event Trigger OnCharge, OnTap, OnDoubleTap;
public static event TouchPad OnScroll;
public static event Gesture OnSwipe;
public static event Clockwise OnClockwise;

public void Awake(){
OnTap = delegate { };
OnCharge = delegate { };
OnDoubleTap = delegate { };
OnSwipe = delegate { };
OnScroll = delegate { };
OnClockwise = delegate { };
}

void Update () {
Expand Down Expand Up @@ -93,6 +104,29 @@ void Update () {
OnScroll(0, nowTouch.position.y);
}
}

Vector2 td = nowTouch.deltaPosition;

clockParam *= CLOCK_PARAM_GAIN;

if (0<td.x)
{
if( -CLOCK_PARAM_MAX < clockParam ){ clockParam -= CLOCK_PARAM_ADD; }
}
else if (td.x<0)
{
if( clockParam < CLOCK_PARAM_MAX ){ clockParam += CLOCK_PARAM_ADD; }
}

if( CLOCK_PARAM_THRESHOLD < clockParam )
{
OnClockwise(true);
}
else if( clockParam < -CLOCK_PARAM_THRESHOLD )
{
OnClockwise(false);
}

break;

case TouchPhase.Ended:
Expand Down

0 comments on commit b17e267

Please sign in to comment.