コード例 #1
0
        IEnumerator <float> _AnimationCoroutine(Vector3 startPos, Vector3 endPos, float duration, Easings.Functions easingType, GameObject objectToAnimate)
        {
            //Animation process
            for (float time = 0f; time < duration; time += Time.deltaTime)
            {
                //if gameObject exists
                if (objectToAnimate != null)
                {
                    time = Mathf.Clamp(time, 0f, duration);
                    float value = MathW.Remap(time, 0f, duration, 0f, 1f);

                    Vector3 currentPosition = Vector3.LerpUnclamped(startPos, endPos, Easings.Interpolate(value, easingType));

                    objectToAnimate.transform.position = currentPosition;

                    yield return(Timing.WaitForOneFrame);
                }

                //if gameObject was destroyed while being animated
                else
                {
                    Debug.LogWarning("Animation Coroutine: objectToAnimate was destroyed");
                    yield break;
                }

                //ensure that the final position is exactly the target position
                objectToAnimate.transform.position = endPos;
            }
        }
コード例 #2
0
ファイル: RandomW.cs プロジェクト: MeisterDerMagie/_Wichtel
        private float Next()
        {
            float next = 0f;

            //-- Discrepancy --
            //- High Discrepancy ("normal" random numbers / white noise) -
            if (!lowDiscrepancy)
            {
                next = simpleRng.GetFloatRange(0f, 1f);
            }
            //- Low Discrepancy (Grid & Jitter) -
            else
            {
                next = NextLowDiscrepancyFloat();
            }

            //-- Probability Distribution --
            //- Custom Distribution -
            if (probabilityDistribution == ProbabilityDistribution.Custom)
            {
                next = animationCurveSampler.Sample(next);
            }
            //- else: Uniform Probability Distribution -

            //-- Min Max Range --
            next = MathW.Remap(next, 0f, 1f, min, max);

            //-- Return final value --
            return(next);
        }