コード例 #1
0
        virtual protected IEnumerator Start()
        {
            GameObject quad          = GameObject.CreatePrimitive(PrimitiveType.Quad);
            Transform  quadTransform = quad.GetComponent <Transform>();

            quadTransform.parent        = this.Transform;
            quadTransform.localPosition = Vector3.zero;

            quad.GetComponent <MeshCollider>().enabled = false;

            MeshRenderer quadRenderer = quadTransform.GetComponent <MeshRenderer>();

            quadRenderer.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
            quadRenderer.receiveShadows    = false;
            quadRenderer.material          = CreateMaterial();

            // need to calculate scale to that it fills entire screen
            Bounds  bounds  = quadRenderer.bounds;
            Vector3 pCorner = Camera.main.ViewportToWorldPoint(new Vector3(1.0f, 1.0f, this.Transform.localPosition.z));
            Vector3 pMid    = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, this.Transform.localPosition.z));
            float   xScale  = (pCorner.x - pMid.x) / bounds.extents.x;
            float   yScale  = (pCorner.y - pMid.y) / bounds.extents.y;

            quadTransform.localScale = new Vector3(xScale, yScale, 1.0f);

            // flash black, then white
            // this.State = PhotoFlashState.Black;
            // quadRenderer.material.color = Color.white;
            // yield return new WaitForSeconds(1f / 20.0f);

            this.State = PhotoFlashState.White;
            quadRenderer.material.color = Color.white;
            yield return(new WaitForSeconds(1f / 20.0f));

            this.State = PhotoFlashState.Fade;
            Color color    = Color.white;
            float elapsed  = 0f;
            float duration = 0.5f;

            while (elapsed < duration)
            {
                elapsed += Time.deltaTime;
                color.a  = Cubic.EaseIn(1f, 0f, Mathf.Clamp(elapsed / duration, 0f, 1f));
                quadRenderer.material.color = color;
                yield return(null);
            }

            this.State = PhotoFlashState.Complete;
            if (this.OnComplete != null)
            {
                this.OnComplete();
            }
            Destroy(this.gameObject);
        }
コード例 #2
0
ファイル: Content.cs プロジェクト: p-yboulerice/Assignment1
        /// <summary>
        /// Turns the content off using a coroutine to animate the transition.
        /// </summary>
        virtual protected IEnumerator TurnOffAsync(bool animated)
        {
            this.State          = ContentState.TurnOff;
            this.Button.enabled = false;

            Layout();

            Vector3 initialPosition;

            initialPosition = this.OnPosition;

            Vector3 targetPosition;

            targetPosition = this.OffPosition;

            float duration;

            duration = this.AnimationDuration;

            float elapsed;

            elapsed = 0f;

            float t;

            t = 0;

            if (animated && duration > 0)
            {
                while (elapsed < duration)
                {
                    elapsed += Time.deltaTime;
                    t        = Mathf.Clamp(elapsed / duration, 0f, 1f);
                    this.Button.Transform.localPosition = Cubic.EaseIn(initialPosition, targetPosition, t);
                    yield return(null);
                }
            }

            this.Button.Transform.localPosition = targetPosition;
            this.State = ContentState.Off;
            this.gameObject.SetActive(false);
            yield break;
        }
コード例 #3
0
ファイル: Easing.cs プロジェクト: Slaktus/Tetra
        internal static float Ease(Type ease, float t, float duration)
        {
            switch (ease)
            {
            case Type.Linear:
                return(Linear.EaseNone(t, duration));

            case Type.BackIn:
                return(Back.EaseIn(t, duration));

            case Type.BackOut:
                return(Back.EaseOut(t, duration));

            case Type.BackInOut:
                return(Back.EaseInOut(t, duration));

            case Type.BounceIn:
                return(Bounce.EaseIn(t, duration));

            case Type.BounceOut:
                return(Bounce.EaseOut(t, duration));

            case Type.BounceInOut:
                return(Bounce.EaseInOut(t, duration));

            case Type.CircIn:
                return(Circular.EaseIn(t, duration));

            case Type.CircOut:
                return(Circular.EaseOut(t, duration));

            case Type.CircInOut:
                return(Circular.EaseInOut(t, duration));

            case Type.CubicIn:
                return(Cubic.EaseIn(t, duration));

            case Type.CubicOut:
                return(Cubic.EaseOut(t, duration));

            case Type.CubicInOut:
                return(Cubic.EaseInOut(t, duration));

            case Type.ElasticIn:
                return(Elastic.EaseIn(t, duration));

            case Type.ElasticOut:
                return(Elastic.EaseOut(t, duration));

            case Type.ElasticInOut:
                return(Elastic.EaseInOut(t, duration));

            case Type.Punch:
                return(Elastic.Punch(t, duration));

            case Type.ExpoIn:
                return(Exponential.EaseIn(t, duration));

            case Type.ExpoOut:
                return(Exponential.EaseOut(t, duration));

            case Type.ExpoInOut:
                return(Exponential.EaseInOut(t, duration));

            case Type.QuadIn:
                return(Quadratic.EaseIn(t, duration));

            case Type.QuadOut:
                return(Quadratic.EaseOut(t, duration));

            case Type.QuadInOut:
                return(Quadratic.EaseInOut(t, duration));

            case Type.QuartIn:
                return(Quartic.EaseIn(t, duration));

            case Type.QuartOut:
                return(Quartic.EaseOut(t, duration));

            case Type.QuartInOut:
                return(Quartic.EaseInOut(t, duration));

            case Type.QuintIn:
                return(Quintic.EaseIn(t, duration));

            case Type.QuintOut:
                return(Quintic.EaseOut(t, duration));

            case Type.QuintInOut:
                return(Quintic.EaseInOut(t, duration));

            case Type.SineIn:
                return(Sinusoidal.EaseIn(t, duration));

            case Type.SineOut:
                return(Sinusoidal.EaseOut(t, duration));

            case Type.SineInOut:
                return(Sinusoidal.EaseInOut(t, duration));

            default:
                return(Linear.EaseNone(t, duration));
            }
        }