Example #1
0
        private static TweenerCore <Vector3, Vector3[], Vector3ArrayOptions> Shake(DOGetter <Vector3> getter, DOSetter <Vector3> setter, float duration, Vector3 strength, int vibrato, float randomness, bool ignoreZAxis, bool vectorBased)
        {
            float num  = vectorBased ? strength.magnitude : strength.x;
            int   num2 = (int)((float)vibrato * duration);

            if (num2 < 2)
            {
                num2 = 2;
            }
            float num3 = num / (float)num2;

            float[] array = new float[num2];
            float   num4  = 0f;

            for (int i = 0; i < num2; i++)
            {
                float num5 = (float)(i + 1) / (float)num2;
                float num6 = duration * num5;
                num4    += num6;
                array[i] = num6;
            }
            float num7 = duration / num4;

            for (int j = 0; j < num2; j++)
            {
                array[j] *= num7;
            }
            float num8 = UnityEngine.Random.Range(0f, 360f);

            Vector3[] array2 = new Vector3[num2];
            for (int k = 0; k < num2; k++)
            {
                if (k < num2 - 1)
                {
                    if (k > 0)
                    {
                        num8 = num8 - 180f + UnityEngine.Random.Range(-randomness, randomness);
                    }
                    if (vectorBased)
                    {
                        Quaternion rotation = Quaternion.AngleAxis(UnityEngine.Random.Range(-randomness, randomness), Vector3.up);
                        Vector3    vector   = rotation * DG.Tweening.Core.Utils.Vector3FromAngle(num8, num);
                        vector.x  = Vector3.ClampMagnitude(vector, strength.x).x;
                        vector.y  = Vector3.ClampMagnitude(vector, strength.y).y;
                        vector.z  = Vector3.ClampMagnitude(vector, strength.z).z;
                        array2[k] = vector;
                        num      -= num3;
                        strength  = Vector3.ClampMagnitude(strength, num);
                    }
                    else
                    {
                        if (ignoreZAxis)
                        {
                            array2[k] = DG.Tweening.Core.Utils.Vector3FromAngle(num8, num);
                        }
                        else
                        {
                            Quaternion rotation2 = Quaternion.AngleAxis(UnityEngine.Random.Range(-randomness, randomness), Vector3.up);
                            array2[k] = rotation2 * DG.Tweening.Core.Utils.Vector3FromAngle(num8, num);
                        }
                        num -= num3;
                    }
                }
                else
                {
                    array2[k] = Vector3.zero;
                }
            }
            return(DOTween.ToArray(getter, setter, array2, array).NoFrom <Vector3, Vector3[], Vector3ArrayOptions>().SetSpecialStartupMode(SpecialStartupMode.SetShake));
        }
Example #2
0
        public static TweenerCore <Vector3, Vector3[], Vector3ArrayOptions> Punch(DOGetter <Vector3> getter, DOSetter <Vector3> setter, Vector3 direction, float duration, int vibrato = 10, float elasticity = 1f)
        {
            if (elasticity > 1f)
            {
                elasticity = 1f;
            }
            else if (elasticity < 0f)
            {
                elasticity = 0f;
            }
            float num  = direction.magnitude;
            int   num2 = (int)((float)vibrato * duration);

            if (num2 < 2)
            {
                num2 = 2;
            }
            float num3 = num / (float)num2;

            float[] array = new float[num2];
            float   num4  = 0f;

            for (int i = 0; i < num2; i++)
            {
                float num5 = (float)(i + 1) / (float)num2;
                float num6 = duration * num5;
                num4    += num6;
                array[i] = num6;
            }
            float num7 = duration / num4;

            for (int j = 0; j < num2; j++)
            {
                array[j] *= num7;
            }
            Vector3[] array2 = new Vector3[num2];
            for (int k = 0; k < num2; k++)
            {
                if (k < num2 - 1)
                {
                    if (k == 0)
                    {
                        array2[k] = direction;
                    }
                    else if (k % 2 != 0)
                    {
                        array2[k] = -Vector3.ClampMagnitude(direction, num * elasticity);
                    }
                    else
                    {
                        array2[k] = Vector3.ClampMagnitude(direction, num);
                    }
                    num -= num3;
                }
                else
                {
                    array2[k] = Vector3.zero;
                }
            }
            return(DOTween.ToArray(getter, setter, array2, array).NoFrom <Vector3, Vector3[], Vector3ArrayOptions>().SetSpecialStartupMode(SpecialStartupMode.SetPunch));
        }