将相机合并到一个

时间:2015-12-14 14:05:53

标签: unity3d camera

我的场景中有两个摄像头 - 一个用于跟踪2D对象,另一个用于3D模型(第二个摄像头具有除第一个以外的其他视角)。

我想创建第三个相机,它结合了这两个相机的视图(因此,相机应该"看"用户"看游戏")。可能吗?

为什么我要这样的相机?我想截图。我知道我可以使用Application.CaptureScreenshot但它也可以捕获UI元素。为什么我只能在捕获屏幕时禁用几秒内的UI元素?因为效果很难看(用户看到UI消失了一段时间)。所以我的想法是创建第三个忽略UI层的相机(但确切地看到用户看到的内容)。使渲染帧成为文件并销毁该相机。

到目前为止我的代码:

private IEnumerator CaptureScreenCoroutine()
{
    // Wait till the last possible moment before screen rendering to hide the UI
    yield return null;

    this.EnableUi(false);

    // Wait for screen rendering to complete
    yield return new WaitForEndOfFrame();

    // Take screenshot 
    Application.CaptureScreenshot("SomeScreenShor.png");
    this.EnableUi(true);    
}

1 个答案:

答案 0 :(得分:1)

如果Monobehaviour连接到最后渲染的相机,你将需要这样的东西。

void LateUpdate(){
    Texture2D tex = new Texture2D(Screen.width, Screen.height);
    tex.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);
    tex.Apply();
}

这会将屏幕上的所有像素转储到" tex"然后你可以用它做你想做的事。这可能会导致故障,具体取决于您渲染摄像机的分辨率。