场景过度(非黑白交替,非用Shader)

之前写了一篇关于切换场景的黑变白的跳转,但是想更好一点,就做了下面的效果:唯一不足的地方,就是掉帧比较严重,跳转掉了20+帧,有大神如果能优化,麻烦留言告诉下怎么做


image是一个遮挡全屏的2DUI,初始Color的a为0;

代码如下:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;


public class JumpScreenAnimator : MonoBehaviour {
    public Image _image;
    // Use this for initialization
    void Start() {

    }

    // Update is called once per frame
    void Update() {

    }

    IEnumerator GetPictureNow()
    {
        yield return new WaitForEndOfFrame();
        Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);  //创建一个新的Texture2D
        tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);  //读取屏幕像素,并保存
        tex.Apply();
        Sprite sp = Sprite.Create(tex, new Rect(0, 0, Screen.width, Screen.height), Vector2.zero);  //Texture2D转换为Sprite
        _image.sprite = sp;
        print(sp);
        StartCoroutine("spriteAnimator");
    }

    IEnumerator spriteAnimator()
    {
        _image.color = new Color(_image.color.r, _image.color.g, _image.color.b, 1);
        float a = 1;
        while (_image.color.a > 0)
        {
            a -= 0.1f;
            _image.color = new Color(_image.color.r, _image.color.g, _image.color.b, a);
            yield return new WaitForSeconds(0.05f);
        }
    }

    public void JumpTestScreen()
    {
        SceneManager.LoadSceneAsync("Testscene");
        DontDestroyOnLoad(this.gameObject);
        StartCoroutine(GetPictureNow());
    }
    public void JumpFiveScreen()
    {
        SceneManager.LoadSceneAsync("FiveScene");
        DontDestroyOnLoad(this.gameObject);
        StartCoroutine(GetPictureNow());
    }
}


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值