C# 在Unity3D中将RenderTexture快速转换为纹理2D

C# 在Unity3D中将RenderTexture快速转换为纹理2D,c#,unity3d,screenshot,unity5,texture2d,C#,Unity3d,Screenshot,Unity5,Texture2d,我有一个截图预览在游戏的水平结束。 当我加载屏幕截图时,它会使游戏冻结片刻。 当我加载截图时,我该怎么做,这样就不会冻结? 这是mycode: private IEnumerator ShowScreeshotPreview() { screenshotTexture = new Texture2D(Screen.height, Screen.height, TextureFormat.RGB24, false); for (int i = 0; i < 9; i++)

我有一个截图预览在游戏的水平结束。 当我加载屏幕截图时,它会使游戏冻结片刻。 当我加载截图时,我该怎么做,这样就不会冻结? 这是mycode:

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;
}
private IEnumerator ShowScreeshotPreview()
{
screenshotTexture=新纹理2D(Screen.height,Screen.height,TextureFormat.RGB24,false);
对于(int i=0;i<9;i++)
{
收益返回空;
}
RenderTexture.active=singleton.Get().MainCharacterScript.GetComponent().screenshotTexture;
screenshotTexture.ReadPixels(新矩形(0,0,Screen.height,Screen.height),0,0);
screenshotTexture.Apply();
RenderTexture.active=null;//添加以避免错误
screenshotPrview.mainTexture=screenshotTexture;
ScreenShotPreviewImator.SetBool(“可见”,为真);
screenshotload=true;
收益返回空;
}

为什么不使用Application.CaptureScreenshot(“Screenshot.png”)@joreldraw我需要加载屏幕截图,而不是制作它我不明白你想用你的循环做什么。对于(int i=0;i<9;i++){yield return null;}协同程序不冻结游戏,你确定这是脚本造成的吗?@joreldraw它使冻结时间更短为什么不使用Application.CaptureScreenshot(“Screenshot.png”)@joreldraw我需要加载屏幕截图,而不是制作它我不明白你想用你的循环做什么。对于(inti=0;i<9;i++){yield return null;}协同程序不能冻结游戏,你确定这是脚本造成的吗?@joreldraw它使冻结变得不那么滞后