public static IEnumerator RotateOverTime(this Rigidbody2D rb2D, float amount, float time, RotationDirection direction) { // Store the inverse time so we can use multiplication, which is more efficient than division float inverseTime = 1f / time; // Store starting and ending rotation values to interpolate between float startingRotation = rb2D.rotation; // Initiaize the ending rotation. If rotating clockwise, subtract the rotation amount float endingRotation; if (direction == RotationDirection.Clockwise) { endingRotation = startingRotation - amount; } else { endingRotation = startingRotation + amount; } // This function linearly interpolates between starting and ending rotations for the rigidbody UnityAction <float> updateRotation = currentTime => { rb2D.MoveRotation(Mathf.Lerp(startingRotation, endingRotation, currentTime * inverseTime)); }; // Run the fixed update for some time, updating the rigidbody rotation yield return(CoroutineModule.FixedUpdateForTime(time, updateRotation)); // Make sure that the ending rotation is exactly the roation the rigidbody ends on rb2D.rotation = endingRotation; }
public static IEnumerator FadeIn(this AudioSource source, float time) { source.Play(); UnityAction <float> updateVolume = t => { source.volume = Mathf.Lerp(0f, 1f, t); }; yield return(CoroutineModule.LerpForTime(time, updateVolume)); }
public static IEnumerator MoveOverTime(this Transform transform, Vector3 endingPos, float time) { // Store the starting position of the transform Vector3 startPos = transform.position; UnityAction <float> updatePosition = t => { transform.position = Vector3.Lerp(startPos, endingPos, t); }; // Run an update loop for time, updating position yield return(CoroutineModule.LerpForTime(time, updatePosition)); }
public static IEnumerator Fade(Color startColor, Color endColor, float time, UnityAction <Color> callback) { Color currentColor = startColor; // Called on each frame in the update for time routine UnityAction <float> update = t => { // Lerp the color from start to end currentColor = Color.Lerp(startColor, endColor, t); // Invoke the callback to get the returned color callback.Invoke(currentColor); }; yield return(CoroutineModule.LerpForTime(time, update)); }
// Flicker the color between the two colors given public static IEnumerator Flicker(Color startColor, Color endColor, float totalTime, float flickerTime, UnityAction <Color> callback) { Color currentColor = startColor; float inverseFadeTime = 1f / flickerTime; UnityAction <float> update = currentTime => { // Ping-pong the interpolator between 0 and 1, and use that for the current color currentTime = Mathf.PingPong(currentTime * inverseFadeTime, 1f); currentColor = Color.Lerp(startColor, endColor, currentTime); // Invoke the callback so that calling method can receive the current color callback.Invoke(currentColor); }; yield return(CoroutineModule.UpdateForTime(totalTime, update)); }
public static IEnumerator MoveOverTime(this Rigidbody2D rb2D, Vector2 endingPos, float time) { // Store the inverse of the time so we can use multiplication, which is more efficient than repeated division float inverseTime = 1f / time; // Store the starting position of the rigidbody. We use this to linearly interpolate to the end positiong Vector2 startingPos = rb2D.position; // This function updates the rigidbody position by linearly interpolating it between the start and ending position UnityAction <float> updatePosition = currentTime => { rb2D.MovePosition(Vector2.Lerp(startingPos, endingPos, currentTime * inverseTime)); }; // Run fixed update for time, where the action updates the rigidbody position yield return(CoroutineModule.FixedUpdateForTime(time, updatePosition)); }
private void Start() { mo = FrameworkModule.CreatInstance <CoroutineModule>("", ""); this.Sequence(EnvironmentType.Ev0) .Repeat((r) => { r.Sequence((s) => { s.TimeSpan(new TimeSpan(0, 0, 5)) .Event(() => { Log.L("GG"); }) .OnCompelete(() => { Log.L("comp"); }) .OnBegin(() => { Log.L("begin"); }); }) ; }, 2) .TimeSpan(new TimeSpan(0, 0, 5)) .OnCompelete((ss) => { /*ss.Reset();*/ }) .OnRecyle(() => { Log.L(""); }) .Run(mo); }
public static T Run <T>(this T self, CoroutineModule moudle) where T : ActionNode { moudle.StartCoroutine(self.ActionEnumerator()); return(self); }
public void Load() { CoroutineModule.GetInstance().DoCoroutine(LoadProcess()); }