Пример #1
0
        private void Update()
        {
            if (!shaking)
            {
                return;
            }

            float deltaTime = JuicyUtils.DeltaTime(ignoreTimeScale);
            float time      = JuicyUtils.Time(ignoreTimeScale);

            if (time > stopTime)
            {
                fallOff = Mathf.Clamp01(fallOff - recoverySpeed * deltaTime);
            }

            if (fallOff > 1)
            {
                target.transform.localPosition = originalPosition;
                shaking = false;
                return;
            }

            float shake          = Mathf.Pow(fallOff, fallOffSmoothness);
            float easeMultiplier = ease.Evaluate(elapsedTimePercentage);

            target.transform.localPosition = originalPosition + new Vector3(
                maximumStrength.x * (Mathf.PerlinNoise(seed, time * frequency) * 2 - 1),
                maximumStrength.y * (Mathf.PerlinNoise(seed + 1, time * frequency) * 2 - 1),
                maximumStrength.z * (Mathf.PerlinNoise(seed + 2, time * frequency) * 2 - 1)
                ) * shake * easeMultiplier;

            elapsedTimePercentage += recoveryRate * deltaTime;
        }
Пример #2
0
        public void Shake(ShakeProperties properties)
        {
            if (Mathf.Approximately(properties.duration, 0))
            {
                return;
            }
            maximumStrength   = properties.maximumStrength;
            frequency         = properties.frequency;
            fallOffSmoothness = properties.smoothness;
            recoveryRate      = 1 / properties.duration;
            stopTime          = JuicyUtils.Time(properties.ignoreTimeScale) + properties.duration;

            ease            = properties.falloffCurve;
            ignoreTimeScale = properties.ignoreTimeScale;
            recoverySpeed   = Mathf.Max(0.1f, properties.recoverySpeed);

            fallOff = properties.power;
            seed    = Random.value;

            shaking = true;
        }
Пример #3
0
        public void Invoke(MonoBehaviour mono, Action callback)
        {
            if (!mono.gameObject.activeInHierarchy)
            {
                return;
            }

            if (HasCooldown && currentTimestamp > JuicyUtils.Time(ignoreTimeScale))
            {
                return;
            }

            if (!HasDelay)
            {
                callback.Invoke();
                return;
            }

            currentTimestamp = JuicyUtils.Time(ignoreTimeScale) + cooldown;

            mono.InvokeDelayed(delay, callback, ignoreTimeScale);
        }