答案 0 :(得分:0)
您可以使用此代码段,我用注释解释代码:
int textureWidth = GameObject.find("UnicGroups").GetComponent<BoxCollider>.size.x; // Width of photo
int texturHeight = GameObject.find("UnicGroups").GetComponent<BoxCollider>.size.y; // Height of photo
// You can add EmptyGameObject to your model
// and move that game object to upper left corner of
// your model. Then you can replace x and y value
// with position of that game object
float x = GameObject.find("UnicGroups/YourEmptyGameObject").transform.Position.x; // x position of upper left corner of screenshot
float y = GameObject.find("UnicGroups/YourEmptyGameObject").transform.Position.y; // Y position of upper left corner of screenshot
// create the texture
Texture2D screenTexture = new Texture2D(textureWidth, texturHeight,TextureFormat.RGB24,true);
screenTexture.ReadPixels(new Rect(x, y, textureWidth, texturHeight),0,0);
screenTexture.Apply();
// Save image to file
byte[] dataToSave = screenTexture.EncodeToPNG();
// Set destination path for saving file
string destination = Path.Combine(Application.persistentDataPath,System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png");
File.WriteAllBytes(destination, dataToSave);