Exemplo n.º 1
0
    IEnumerator InterceptFullScreen(Rect rect, Action <Texture2D> finishActionFunc = null)
    {
        yield return(new WaitForEndOfFrame());

        nPictureRealWith   = (int)rect.width;
        nPictureRealHeight = (int)rect.height;
        Texture2D screenShot = GetScreenShotTexture2D(rect);

        // Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);
        screenShot.ReadPixels(rect, 0, 0);
        screenShot.Apply();

        //tex2DMainCameraAndUICamerasSreenShot = screenShot;

        if (onCaptureMainCameraAndUICameraFinishedCallback != null)
        {
            onCaptureMainCameraAndUICameraFinishedCallback();
            onCaptureMainCameraAndUICameraFinishedCallback = null;
        }

        if (finishActionFunc != null)
        {
            finishActionFunc.Invoke(screenShot);
            finishActionFunc = null;
            //Destroy(screenShot);
        }
    }
Exemplo n.º 2
0
    IEnumerator CaptureCamera(List <Camera> cameras, Rect rect, Action <Texture2D> finishActionFunc = null)
    {
        yield return(new WaitForEndOfFrame());

        int ratio = 1;

        rect.x      *= ratio;
        rect.y      *= ratio;
        rect.width  *= ratio;
        rect.height *= ratio;

        nPictureRealWith   = (int)rect.width;
        nPictureRealHeight = (int)rect.height;

        RenderTexture currentRT = RenderTexture.active;

        RenderTexture rt = RenderTexture.GetTemporary(Screen.width * ratio, Screen.height * ratio, 24);

        for (int i = 0; i < cameras.Count; i++)
        {
            Camera camera = cameras[i];
            camera.targetTexture = rt;
            camera.Render();
        }

        RenderTexture.active = rt;

        Texture2D screenShot = GetScreenShotTexture2D(rect);

        screenShot.ReadPixels(rect, 0, 0);// 注:这个时候,它是从RenderTexture.active中读取像素
        screenShot.Apply();

        for (int i = 0; i < cameras.Count; i++)
        {
            Camera camera = cameras[i];
            camera.targetTexture = null;
        }

        RenderTexture.active = currentRT;
        RenderTexture.ReleaseTemporary(rt);

        if (onCaptureMainCameraAndUICameraFinishedCallback != null)
        {
            onCaptureMainCameraAndUICameraFinishedCallback();
            onCaptureMainCameraAndUICameraFinishedCallback = null;
        }

        if (finishActionFunc != null)
        {
            finishActionFunc.Invoke(screenShot);
            finishActionFunc = null;
            //Destroy(screenShot);
        }
    }