Last active
August 29, 2015 14:01
-
-
Save DomDomHaas/a1cfc0ca25d6751e5f56 to your computer and use it in GitHub Desktop.
Coroutines for (gamepad) vibration patterns using iTween to get the linear transition
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
public IEnumerator ImpactVibration (float enemyDirection) | |
{ | |
float vibTime = 0.5f; | |
float impVibStart = 0.1f; | |
float impVibStrength = 0.35f; | |
doVibrate = true; | |
StartCoroutine (DoVibrate ()); | |
if (enemyDirection > 0) { | |
StartCoroutine (setVibrate (0, vibTime, impVibStart, impVibStrength, "setLeftVibrate")); | |
} else { | |
StartCoroutine (setVibrate (0, vibTime, impVibStart, impVibStrength, "setRightVibrate")); | |
} | |
yield return new WaitForSeconds (vibTime + 0.1f); | |
doVibrate = false; | |
this.deviceObs.doVibration (0, 0); | |
} | |
public IEnumerator DashVibration (float startStrength, float endStrength) | |
{ | |
float vibTime = 0.5f; | |
doVibrate = true; | |
StartCoroutine (DoVibrate ()); | |
if (this.xFacing > 0) { | |
StartCoroutine (setVibrate (0, vibTime * 0.75f, startStrength, endStrength, "setLeftVibrate")); | |
StartCoroutine (setVibrate (vibTime * 0.2f, vibTime * 0.8f, startStrength, endStrength, "setRightVibrate")); | |
} else { | |
StartCoroutine (setVibrate (0, vibTime * 0.75f, startStrength, endStrength, "setRightVibrate")); | |
StartCoroutine (setVibrate (vibTime * 0.2f, vibTime * 0.8f, startStrength, endStrength, "setLeftVibrate")); | |
} | |
yield return new WaitForSeconds (vibTime + 0.1f); | |
doVibrate = false; | |
this.deviceObs.doVibration (0, 0); | |
} | |
private IEnumerator setVibrate (float delay, float vibTime, float from, float to, string callBackMethod) | |
{ | |
yield return new WaitForSeconds (delay); | |
iTween.ValueTo (this.gameObject, | |
iTween.Hash (iT.ValueTo.from, from, | |
iT.ValueTo.to, to, | |
iT.ValueTo.time, vibTime, | |
iT.ValueTo.onupdate, callBackMethod, | |
iT.ValueTo.easetype, iTween.EaseType.linear)); | |
yield return new WaitForSeconds (vibTime + 0.05f); | |
if (callBackMethod.Equals ("setLeftVibrate")) { | |
setLeftVibrate (0); | |
} else { | |
setRightVibrate (0); | |
} | |
} | |
private IEnumerator DoVibrate () | |
{ | |
while (this.doVibrate) { | |
this.deviceObs.doVibration (leftVib, rightVib); | |
yield return new WaitForEndOfFrame (); | |
} | |
} | |
private void setLeftVibrate (float newValue) | |
{ | |
this.leftVib = newValue; | |
} | |
private void setRightVibrate (float newValue) | |
{ | |
this.rightVib = newValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment