Esempio n. 1
0
        private IEnumerator ToggleShapeSmooth(ShapeToggle shapeToggle)
        {
            PlaySound(shapeToggleClip);

            Keyframe[] keys = shapeToggleAnimation.keys;
            float      shapeToggleTiming = keys[1].time; //Changing shape when reaching amximum height of the curve

            bool  shapeToggled = false;
            float elapsedTime  = 0;

            while (elapsedTime < 1)//AnimationCurve´s max time set to 1s
            {
                float height = shapeToggleAnimation.Evaluate(elapsedTime) * shapeToggleHeight;
                shapeParent.localPosition = new Vector3(0, height, 0);

                //if (!shapeToggled && Mathf.Abs( - elapsedTime) <= 0.05f)
                if (!shapeToggled && elapsedTime >= shapeToggleTiming)
                {
                    ToggleShape(shapeToggle);

                    shapeToggled = true;
                }

                elapsedTime += Time.deltaTime * shapeToggleSpeed;
                yield return(null);
            }

            //Control mechanism: Force toggle shape on animation end in case of failure
            if (!shapeToggled)
            {
                ToggleShape(shapeToggle);
                shapeToggled = true;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Moves to next shape
        /// </summary>
        private void StartToggleShape(ShapeToggle shapeToggle)
        {
            if (shapeToggleCoroutine != null)
            {
                StopCoroutine(shapeToggleCoroutine);
            }

            shapeToggleCoroutine = StartCoroutine(ToggleShapeSmooth(shapeToggle));
        }
Esempio n. 3
0
 private void ToggleShape(ShapeToggle shapeToggle)
 {
     HideShape(currentShapeIndex);
     currentShapeIndex = CorrectShapeIndex((shapeToggle == ShapeToggle.Next) ? ++currentShapeIndex : --currentShapeIndex);
     ShowShape(currentShapeIndex);
 }