123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568 |
- // Copyright (c) 2011 Bob Berkebile (pixelplacment)
- // Please direct any bugs/comments/suggestions to http://pixelplacement.com
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- /*
- TERMS OF USE - EASING EQUATIONS
- Open source under the BSD License.
- Copyright (c)2001 Robert Penner
- All rights reserved.
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- using UnityEngine;
- namespace Rokid.MRC
- {
- /// <summary>
- /// <para>Version: 2.0.5</para>
- /// <para>Author: Bob Berkebile (http://pixelplacement.com)</para>
- /// <para>Support: http://itween.pixelplacement.com</para>
- /// </summary>
- public static class iTween
- {
- /// <summary>
- /// The type of easing to use based on Robert Penner's open source easing equations (http://www.robertpenner.com/easing_terms_of_use.html).
- /// </summary>
- public enum EaseType
- {
- None = -1,
- easeInQuad,
- easeOutQuad,
- easeInOutQuad,
- easeInCubic,
- easeOutCubic,
- easeInOutCubic,
- easeInQuart,
- easeOutQuart,
- easeInOutQuart,
- easeInQuint,
- easeOutQuint,
- easeInOutQuint,
- easeInSine,
- easeOutSine,
- easeInOutSine,
- easeInExpo,
- easeOutExpo,
- easeInOutExpo,
- easeInCirc,
- easeOutCirc,
- easeInOutCirc,
- linear,
- spring,
- /* GFX47 MOD START */
- //bounce,
- easeInBounce,
- easeOutBounce,
- easeInOutBounce,
- /* GFX47 MOD END */
- easeInBack,
- easeOutBack,
- easeInOutBack,
- /* GFX47 MOD START */
- //elastic,
- easeInElastic,
- easeOutElastic,
- easeInOutElastic,
- /* GFX47 MOD END */
- punch
- }
- /// <summary>
- /// The type of loop (if any) to use.
- /// </summary>
- public enum LoopType
- {
- /// <summary>
- /// Do not loop.
- /// </summary>
- none,
- /// <summary>
- /// Rewind and replay.
- /// </summary>
- loop,
- /// <summary>
- /// Ping pong the animation back and forth.
- /// </summary>
- pingPong
- }
- #region Easing Curves
- /// <summary> simple tween value once </summary>
- public static float easeValue(EaseType easeType, float start, float end, float value)
- {
- switch(easeType)
- {
- case EaseType.easeInQuad:
- return easeInQuad(start, end, value);
- case EaseType.easeOutQuad:
- return easeOutQuad(start, end, value);
- case EaseType.easeInOutQuad:
- return easeInOutQuad(start, end, value);
- case EaseType.easeInCubic:
- return easeInCubic(start, end, value);
- case EaseType.easeOutCubic:
- return easeOutCubic(start, end, value);
- case EaseType.easeInOutCubic:
- return easeInOutCubic(start, end, value);
- case EaseType.easeInQuart:
- return easeInQuart(start, end, value);
- case EaseType.easeOutQuart:
- return easeOutQuart(start, end, value);
- case EaseType.easeInOutQuart:
- return easeInOutQuart(start, end, value);
- case EaseType.easeInQuint:
- return easeInQuint(start, end, value);
- case EaseType.easeOutQuint:
- return easeOutQuint(start, end, value);
- case EaseType.easeInOutQuint:
- return easeInOutQuint(start, end, value);
- case EaseType.easeInSine:
- return easeInSine(start, end, value);
- case EaseType.easeOutSine:
- return easeOutSine(start, end, value);
- case EaseType.easeInOutSine:
- return easeInOutSine(start, end, value);
- case EaseType.easeInExpo:
- return easeInExpo(start, end, value);
- case EaseType.easeOutExpo:
- return easeOutExpo(start, end, value);
- case EaseType.easeInOutExpo:
- return easeInOutExpo(start, end, value);
- case EaseType.easeInCirc:
- return easeInCirc(start, end, value);
- case EaseType.easeOutCirc:
- return easeOutCirc(start, end, value);
- case EaseType.easeInOutCirc:
- return easeInOutCirc(start, end, value);
- case EaseType.linear:
- return linear(start, end, value);
- case EaseType.spring:
- return spring(start, end, value);
- case EaseType.easeInBounce:
- return easeInBounce(start, end, value);
- case EaseType.easeOutBounce:
- return easeOutBounce(start, end, value);
- case EaseType.easeInOutBounce:
- return easeInOutBounce(start, end, value);
- case EaseType.easeInBack:
- return easeInBack(start, end, value);
- case EaseType.easeOutBack:
- return easeOutBack(start, end, value);
- case EaseType.easeInOutBack:
- return easeInOutBack(start, end, value);
- case EaseType.easeInElastic:
- return easeInElastic(start, end, value);
- case EaseType.easeOutElastic:
- return easeOutElastic(start, end, value);
- case EaseType.easeInOutElastic:
- return easeInOutElastic(start, end, value);
- }
- return 0f;
- }
- private static float linear(float start, float end, float value)
- {
- return Mathf.Lerp(start, end, value);
- }
- private static float clerp(float start, float end, float value)
- {
- float min = 0.0f;
- float max = 360.0f;
- float half = Mathf.Abs((max - min) * 0.5f);
- float retval = 0.0f;
- float diff = 0.0f;
- if((end - start) < -half)
- {
- diff = ((max - start) + end) * value;
- retval = start + diff;
- }
- else if((end - start) > half)
- {
- diff = -((max - end) + start) * value;
- retval = start + diff;
- }
- else
- retval = start + (end - start) * value;
- return retval;
- }
- private static float spring(float start, float end, float value)
- {
- value = Mathf.Clamp01(value);
- value = (Mathf.Sin(value * Mathf.PI * (0.2f + 2.5f * value * value * value)) * Mathf.Pow(1f - value, 2.2f) + value) * (1f + (1.2f * (1f - value)));
- return start + (end - start) * value;
- }
- private static float easeInQuad(float start, float end, float value)
- {
- end -= start;
- return end * value * value + start;
- }
- private static float easeOutQuad(float start, float end, float value)
- {
- end -= start;
- return -end * value * (value - 2) + start;
- }
- private static float easeInOutQuad(float start, float end, float value)
- {
- value /= .5f;
- end -= start;
- if(value < 1)
- return end * 0.5f * value * value + start;
- value--;
- return -end * 0.5f * (value * (value - 2) - 1) + start;
- }
- private static float easeInCubic(float start, float end, float value)
- {
- end -= start;
- return end * value * value * value + start;
- }
- private static float easeOutCubic(float start, float end, float value)
- {
- value--;
- end -= start;
- return end * (value * value * value + 1) + start;
- }
- private static float easeInOutCubic(float start, float end, float value)
- {
- value /= .5f;
- end -= start;
- if(value < 1)
- return end * 0.5f * value * value * value + start;
- value -= 2;
- return end * 0.5f * (value * value * value + 2) + start;
- }
- private static float easeInQuart(float start, float end, float value)
- {
- end -= start;
- return end * value * value * value * value + start;
- }
- private static float easeOutQuart(float start, float end, float value)
- {
- value--;
- end -= start;
- return -end * (value * value * value * value - 1) + start;
- }
- private static float easeInOutQuart(float start, float end, float value)
- {
- value /= .5f;
- end -= start;
- if(value < 1)
- return end * 0.5f * value * value * value * value + start;
- value -= 2;
- return -end * 0.5f * (value * value * value * value - 2) + start;
- }
- private static float easeInQuint(float start, float end, float value)
- {
- end -= start;
- return end * value * value * value * value * value + start;
- }
- private static float easeOutQuint(float start, float end, float value)
- {
- value--;
- end -= start;
- return end * (value * value * value * value * value + 1) + start;
- }
- private static float easeInOutQuint(float start, float end, float value)
- {
- value /= .5f;
- end -= start;
- if(value < 1)
- return end * 0.5f * value * value * value * value * value + start;
- value -= 2;
- return end * 0.5f * (value * value * value * value * value + 2) + start;
- }
- private static float easeInSine(float start, float end, float value)
- {
- end -= start;
- return -end * Mathf.Cos(value * (Mathf.PI * 0.5f)) + end + start;
- }
- private static float easeOutSine(float start, float end, float value)
- {
- end -= start;
- return end * Mathf.Sin(value * (Mathf.PI * 0.5f)) + start;
- }
- private static float easeInOutSine(float start, float end, float value)
- {
- end -= start;
- return -end * 0.5f * (Mathf.Cos(Mathf.PI * value) - 1) + start;
- }
- private static float easeInExpo(float start, float end, float value)
- {
- end -= start;
- return end * Mathf.Pow(2, 10 * (value - 1)) + start;
- }
- private static float easeOutExpo(float start, float end, float value)
- {
- end -= start;
- return end * (-Mathf.Pow(2, -10 * value) + 1) + start;
- }
- private static float easeInOutExpo(float start, float end, float value)
- {
- value /= .5f;
- end -= start;
- if(value < 1)
- return end * 0.5f * Mathf.Pow(2, 10 * (value - 1)) + start;
- value--;
- return end * 0.5f * (-Mathf.Pow(2, -10 * value) + 2) + start;
- }
- private static float easeInCirc(float start, float end, float value)
- {
- end -= start;
- return -end * (Mathf.Sqrt(1 - value * value) - 1) + start;
- }
- private static float easeOutCirc(float start, float end, float value)
- {
- value--;
- end -= start;
- return end * Mathf.Sqrt(1 - value * value) + start;
- }
- private static float easeInOutCirc(float start, float end, float value)
- {
- value /= .5f;
- end -= start;
- if(value < 1)
- return -end * 0.5f * (Mathf.Sqrt(1 - value * value) - 1) + start;
- value -= 2;
- return end * 0.5f * (Mathf.Sqrt(1 - value * value) + 1) + start;
- }
- /* GFX47 MOD START */
- private static float easeInBounce(float start, float end, float value)
- {
- end -= start;
- float d = 1f;
- return end - easeOutBounce(0, end, d - value) + start;
- }
- /* GFX47 MOD END */
- /* GFX47 MOD START */
- //private float bounce(float start, float end, float value){
- private static float easeOutBounce(float start, float end, float value)
- {
- value /= 1f;
- end -= start;
- if(value < (1 / 2.75f))
- {
- return end * (7.5625f * value * value) + start;
- }
- else if(value < (2 / 2.75f))
- {
- value -= (1.5f / 2.75f);
- return end * (7.5625f * (value) * value + .75f) + start;
- }
- else if(value < (2.5 / 2.75))
- {
- value -= (2.25f / 2.75f);
- return end * (7.5625f * (value) * value + .9375f) + start;
- }
- else
- {
- value -= (2.625f / 2.75f);
- return end * (7.5625f * (value) * value + .984375f) + start;
- }
- }
- /* GFX47 MOD END */
- /* GFX47 MOD START */
- private static float easeInOutBounce(float start, float end, float value)
- {
- end -= start;
- float d = 1f;
- if(value < d * 0.5f)
- return easeInBounce(0, end, value * 2) * 0.5f + start;
- else
- return easeOutBounce(0, end, value * 2 - d) * 0.5f + end * 0.5f + start;
- }
- /* GFX47 MOD END */
- private static float easeInBack(float start, float end, float value)
- {
- end -= start;
- value /= 1;
- float s = 1.70158f;
- return end * (value) * value * ((s + 1) * value - s) + start;
- }
- private static float easeOutBack(float start, float end, float value)
- {
- float s = 1.70158f;
- end -= start;
- value = (value) - 1;
- return end * ((value) * value * ((s + 1) * value + s) + 1) + start;
- }
- private static float easeInOutBack(float start, float end, float value)
- {
- float s = 1.70158f;
- end -= start;
- value /= .5f;
- if((value) < 1)
- {
- s *= (1.525f);
- return end * 0.5f * (value * value * (((s) + 1) * value - s)) + start;
- }
- value -= 2;
- s *= (1.525f);
- return end * 0.5f * ((value) * value * (((s) + 1) * value + s) + 2) + start;
- }
- private static float punch(float amplitude, float value)
- {
- float s = 9;
- if(value == 0)
- {
- return 0;
- }
- else if(value == 1)
- {
- return 0;
- }
- float period = 1 * 0.3f;
- s = period / (2 * Mathf.PI) * Mathf.Asin(0);
- return (amplitude * Mathf.Pow(2, -10 * value) * Mathf.Sin((value * 1 - s) * (2 * Mathf.PI) / period));
- }
- /* GFX47 MOD START */
- private static float easeInElastic(float start, float end, float value)
- {
- end -= start;
- float d = 1f;
- float p = d * .3f;
- float s = 0;
- float a = 0;
- if(value == 0)
- return start;
- if((value /= d) == 1)
- return start + end;
- if(a == 0f || a < Mathf.Abs(end))
- {
- a = end;
- s = p / 4;
- }
- else
- {
- s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
- }
- return -(a * Mathf.Pow(2, 10 * (value -= 1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p)) + start;
- }
- /* GFX47 MOD END */
- /* GFX47 MOD START */
- //private float elastic(float start, float end, float value){
- private static float easeOutElastic(float start, float end, float value)
- {
- /* GFX47 MOD END */
- //Thank you to rafael.marteleto for fixing this as a port over from Pedro's UnityTween
- end -= start;
- float d = 1f;
- float p = d * .3f;
- float s = 0;
- float a = 0;
- if(value == 0)
- return start;
- if((value /= d) == 1)
- return start + end;
- if(a == 0f || a < Mathf.Abs(end))
- {
- a = end;
- s = p * 0.25f;
- }
- else
- {
- s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
- }
- return (a * Mathf.Pow(2, -10 * value) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p) + end + start);
- }
- /* GFX47 MOD START */
- private static float easeInOutElastic(float start, float end, float value)
- {
- end -= start;
- float d = 1f;
- float p = d * .3f;
- float s = 0;
- float a = 0;
- if(value == 0)
- return start;
- if((value /= d * 0.5f) == 2)
- return start + end;
- if(a == 0f || a < Mathf.Abs(end))
- {
- a = end;
- s = p / 4;
- }
- else
- {
- s = p / (2 * Mathf.PI) * Mathf.Asin(end / a);
- }
- if(value < 1)
- return -0.5f * (a * Mathf.Pow(2, 10 * (value -= 1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p)) + start;
- return a * Mathf.Pow(2, -10 * (value -= 1)) * Mathf.Sin((value * d - s) * (2 * Mathf.PI) / p) * 0.5f + end + start;
- }
- /* GFX47 MOD END */
- #endregion
- }
- }
|