public void Initialize(CoreProperty coreProperty) { // Initializer Guard if (coreProperty == null) { Debug.LogWarning("You Inserted a null CoreProperty! Property not correctly initialized"); return; } easeProperty = new EaseProperty(StartVector, EndVector, easeIn, easeOut, coreProperty); this.coreProperty = coreProperty; }
public static IEnumerator EaseCoroutine(Transform source, EaseProperty property, object target, float easeTime, EaseType easeIn = EaseType.LINEAR, EaseType easeOut = EaseType.LINEAR, CallBack callback = null) { // Save the original value (to tween from it!), and convert // a target transform to the correct property (target can be // either the target value or a transform with the value) object orig = null; switch (property) { case EaseProperty.POSITION: { if (target is Transform) { target = ((Transform)target).localPosition; } if (target is Vector3) { orig = source.localPosition; } } break; case EaseProperty.ROTATION: { if (target is Transform) { target = ((Transform)target).localRotation; } if (target is Quaternion) { orig = source.localRotation; } } break; case EaseProperty.SCALE: { if (target is Transform) { target = ((Transform)target).localScale; } if (target is Vector3) { orig = source.localScale; } } break; } // orig is only set (above) if the target value was the correct type if (orig == null) { // Error if the target was an incompatable type Debug.LogError("Easing with incorrect parameters"); } else { // Start the easing... float timeScale = 1.0f / easeTime; float time = 0; while (time < 1) { // Wait until the next frame yield return null; // Advance iterator and solve easing for this frame time += Time.deltaTime * timeScale; switch (property) { case EaseProperty.POSITION: { source.localPosition = VecEaseInOut((Vector3)orig, (Vector3)target, time, easeIn, easeOut); break; } case EaseProperty.ROTATION: { Vector3 a = ((Quaternion)orig).eulerAngles; Vector3 b = ((Quaternion)target).eulerAngles; while (Mathf.Abs(a.x - b.x) > 180) { if (a.x - b.x < 0) { b.x -= 360; } else { b.x += 360; } } while (Mathf.Abs(a.y - b.y) > 180) { if (a.z - b.z < 0) { b.z -= 360; } else { b.z += 360; } } while (Mathf.Abs(a.z - b.z) > 180) { if (a.z - b.z < 0) { b.z -= 360; } else { b.z += 360; } } source.localRotation = Quaternion.Euler(VecEaseInOut(a, b, time, easeIn, easeOut)); break; } case EaseProperty.SCALE: { source.localScale = VecEaseInOut((Vector3)orig, (Vector3)target, time, easeIn, easeOut); break; } } } // Once the time has elapsed set the property to the final value switch (property) { case EaseProperty.POSITION: { source.localPosition = (Vector3)target; break; } case EaseProperty.ROTATION: { source.localRotation = (Quaternion)target; break; } case EaseProperty.SCALE: { source.localScale = (Vector3)target; break; } } } // If we got a callback method, call it if (callback != null) { callback.Invoke(); } // End the coroutine! yield break; }
public static IEnumerator EaseCoroutine(Transform source, EaseProperty property, object target, float easeTime, EaseType easeIn = EaseType.LINEAR, EaseType easeOut = EaseType.LINEAR, CallBack callback = null) { // Save the original value (to tween from it!), and convert // a target transform to the correct property (target can be // either the target value or a transform with the value) object orig = null; switch (property) { case EaseProperty.POSITION: { if (target is Transform) { target = ((Transform)target).localPosition; } if (target is Vector3) { orig = source.localPosition; } } break; case EaseProperty.ROTATION: { if (target is Transform) { target = ((Transform)target).localRotation; } if (target is Quaternion) { orig = source.localRotation; } } break; case EaseProperty.SCALE: { if (target is Transform) { target = ((Transform)target).localScale; } if (target is Vector3) { orig = source.localScale; } } break; } // orig is only set (above) if the target value was the correct type if (orig == null) { // Error if the target was an incompatable type Debug.LogError("Easing with incorrect parameters"); } else { // Start the easing... float timeScale = 1.0f / easeTime; float time = 0; while (time < 1) { // Wait until the next frame yield return(null); // Advance iterator and solve easing for this frame time += Time.deltaTime * timeScale; switch (property) { case EaseProperty.POSITION: { source.localPosition = VecEaseInOut((Vector3)orig, (Vector3)target, time, easeIn, easeOut); break; } case EaseProperty.ROTATION: { Vector3 a = ((Quaternion)orig).eulerAngles; Vector3 b = ((Quaternion)target).eulerAngles; while (Mathf.Abs(a.x - b.x) > 180) { if (a.x - b.x < 0) { b.x -= 360; } else { b.x += 360; } } while (Mathf.Abs(a.y - b.y) > 180) { if (a.z - b.z < 0) { b.z -= 360; } else { b.z += 360; } } while (Mathf.Abs(a.z - b.z) > 180) { if (a.z - b.z < 0) { b.z -= 360; } else { b.z += 360; } } source.localRotation = Quaternion.Euler(VecEaseInOut(a, b, time, easeIn, easeOut)); break; } case EaseProperty.SCALE: { source.localScale = VecEaseInOut((Vector3)orig, (Vector3)target, time, easeIn, easeOut); break; } } } // Once the time has elapsed set the property to the final value switch (property) { case EaseProperty.POSITION: { source.localPosition = (Vector3)target; break; } case EaseProperty.ROTATION: { source.localRotation = (Quaternion)target; break; } case EaseProperty.SCALE: { source.localScale = (Vector3)target; break; } } } // If we got a callback method, call it if (callback != null) { callback.Invoke(); } // End the coroutine! yield break; }