Unity Screenshots

unity3D 截屏的3种方法:

1.CaptureScreenshot

...

string path;

Application.CaptureScreenshot( path );

StartCoroutine(GetCaptruePicture(path));

....



IEnumerator GetCaptruePicture ( string path ) {

  yield return new WaitForSeconds(1.5f );///对于较大图片是要等待一段时间

  string filePath = "file:///" + path;

      WWW www = new WWW ( filePath ); 

      yield return www; 

    if(www.error == null ){ 

        renderer.material.mainTexture = www.texture;

    }

}

2.如果不想保存屏幕,而是仅仅想将之转化成材质:

private Texture2D m_Texture;

void Start() {

    m_Texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, true);

}



//ReadPixels

StartCoroutine ( GetCaptruePictureByReadPixels() );





IEnumerator GetCaptruePictureByReadPixels() {

        yield return new WaitForEndOfFrame();

        m_Texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0, true);

        PauseTexture.Apply();

}

3.RenderTexture

设置不同camera中内容作为材质。

  

你可能感兴趣的:(screen)