コード例 #1
0
ファイル: TransitionForm.cs プロジェクト: Lotusly/LastNight
        /// <summary>
        /// The 5th transfer method. RadialBlur fade-out. Should apply to background.
        /// </summary>
        /// <param name="tran"></param>
        /// <param name="newPosition"></param>
        /// <param name="inScreen"></param>
        /// <param name="destroy"> Redundant. Tran will be destroyed anyway.</param>
        /// <param name="speed"></param>
        /// <param name="delay"></param>
        /// <returns></returns>
        public IEnumerator RadialBlur(BatchNode tran, Vector3 newPosition, bool inScreen, bool destroy = true,
                                      float speed = 1, float delay = 0)
        {
            Debug.Log("RadialBlur");
            yield return(new WaitForSecondsRealtime(delay));


            Background b = tran.GetComponentInChildren <Background>();

            if (b != null)
            {
                // MODIFYING
                //b.gameObject.GetComponent<Renderer>().material =
                Renderer rend = b.gameObject.GetComponentInChildren <Renderer>();
                MaterialPropertyBlock matBlock = new MaterialPropertyBlock();
                matBlock.Clear();
                matBlock.SetTexture("tDiffuse", rend.material.mainTexture);
                rend.material = Instantiate(Resources.Load <Material>("Material/0"));
                //rend.SetPropertyBlock(matBlock);

                //matBlock.Clear();
                if (speed <= 0)
                {
                    speed = 1;
                }
                float alpha       = 1;
                float density     = 0;
                float alphaStep   = -1 * speed;
                float densityStep = 2 * speed;
                while (alpha > 0)
                {
                    alpha   += alphaStep * Time.deltaTime;
                    density += densityStep * Time.deltaTime;
                    matBlock.SetFloat("_alpha", alpha);
                    matBlock.SetFloat("fDensity", density);
                    rend.SetPropertyBlock(matBlock);
                    yield return(new WaitForEndOfFrame());
                }

                DestroyTran(tran);
            }
            else
            {
                tran.SetPosition(newPosition, inScreen);
                DestroyTran(tran);
            }
        }