在Unity3D中快速将RenderTexture转换为Texture2D

时间:2016-05-23 21:22:08

标签: c# unity3d screenshot unity5 texture2d

我在游戏结束时有截屏预览。 当我加载屏幕截图时,它会暂停游戏。 我该怎么做,所以当我加载截图时,不会有冻结? 这是我的代码:

private IEnumerator ShowScreeshotPreview()
{
    screenshotTexture = new Texture2D(Screen.height, Screen.height, TextureFormat.RGB24, false);
    for (int i = 0; i < 9; i++)
    {
        yield return null;
    }
    RenderTexture.active = Singletons.Get<SpecialEffectsHelper>().MainCharacterScript.GetComponent<GeneratorScript>().screenshotTexture;
    screenshotTexture.ReadPixels(new Rect(0, 0, Screen.height, Screen.height), 0, 0);
    screenshotTexture.Apply();
    RenderTexture.active = null; //Added to avoid errors

    screenshotPrview.mainTexture = screenshotTexture;
    screenshotPreviewAnimator.SetBool("visible", true);
    screenshotLoaded = true;

    yield return null;
}

0 个答案:

没有答案