我要用打包webgl,然后再webgl中进行截屏和录屏,录下来的时评并保存。我用的AVPro Movie Capture,这些插件,打包exe能正常截屏或录视频都能正常保存,一旦打包webgl就不能实现这些功能了。老师能提供一些方法吗
这个老师也没有思路
截屏和录制这个不难实现,主要是保存的本地的时候 会出现问题,
File.WriteAllBytes(String, Byte[]) 方法和其他文件流保存的方法好像不能用
private Texture2D CaptureScreen(Camera came, Rect r)
{
RenderTexture rt = new RenderTexture((int)r.width, (int)r.height, 0);
came.targetTexture = rt;
came.Render();
RenderTexture.active = rt;
Texture2D screenShot = new Texture2D((int)r.width, (int)r.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(r, 0, 0);
screenShot.Apply();
came.targetTexture = null;
RenderTexture.active = null;
GameObject.Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
string strTime = string.Concat(DateTime.Now.Year.ToString(), "_", DateTime.Now.Month.ToString(), "_", DateTime.Now.Day.ToString(), "_",
DateTime.Now.Hour.ToString(), "_", DateTime.Now.Minute.ToString(), "_", DateTime.Now.Second.ToString(), ".png");
string filename = Application.streamingAssetsPath + "/" + strTime;
Text1.text = "Start";
System.IO.File.WriteAllBytes(filename, bytes);
Text5.text = "end";
return screenShot;
}
private Texture2D CaptureScreen2(Camera came, Rect r)
{
RenderTexture rt = new RenderTexture((int)r.width, (int)r.height, 0);
came.targetTexture = rt;
came.Render();
RenderTexture.active = rt;
Texture2D screenShot = new Texture2D((int)r.width, (int)r.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(r, 0, 0);
screenShot.Apply();
came.targetTexture = null;
RenderTexture.active = null;
GameObject.Destroy(rt);
byte[] bytes = screenShot.EncodeToPNG();
string strTimePath = string.Concat(DateTime.Now.Year.ToString(), "_", DateTime.Now.Month.ToString(), "_", DateTime.Now.Day.ToString(), "_",
DateTime.Now.Hour.ToString(), "_", DateTime.Now.Minute.ToString(), "_", DateTime.Now.Second.ToString(), ".png");
string filename = Application.streamingAssetsPath + "/" + strTimePath;
FileStream fs = new FileStream(filename, FileMode.Create, FileAccess.ReadWrite);
Text1.text = bytes.Length.ToString();
fs.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
return screenShot;
}