U3d to capture the game screen with Capturescreenshot

Source: Internet
Author: User

Sun Guangdong 2015.4.27

In- game testers when testing, we would like to be able to capture the moment of the problem, rather than simply describe it in words.
Account Unity provides a screenshot of the game, now let's implement this stuff. Application.capturescreenshot
static void Capturescreenshot (string filename, int supersize = 0); The file is saved in this path by default: Persistent data path So where do we store the picture? On the mobile device path, we have a few of the following: Application.datapath:
This property is used to return the path to the folder where the program's data file resides. For example, in editor it is assets.
Application.streamingassetspath:
This property is used to return the cache directory for stream data, and the return path is relative to the path that is appropriate for setting up some external data files.
Application.persistentdatapath:
This property is used to return a path to a persisted data store directory where persisted data files can be stored. This path is readable and writable.
Application.temporarycachepath:
This property is used to return a cached directory of temporary data.

Android PlatformApplication.datapath:
/data/app/xxx.xxx.xxx.apk
Application.streamingassetspath:
Jar:file:///data/app/xxx.xxx.xxx.apk/!/assets
Application.persistentdatapath:
/data/data/xxx.xxx.xxx/files
Application.temporarycachepath:
/data/data/xxx.xxx.xxx/cache

iOS Platform
Application.datapath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/data
Application.streamingassetspath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/xxx.app/data/raw
Application.persistentdatapath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/documents
Application.temporarycachepath:
Application/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/library/caches
We just draw a button in the game interface (the position to choose not to be in the way), the script is best never destroyed, so it can be used all the time.
Click the button to catch the problem in a timely manner the screen is OK. (I've written a similar code in this article before: http://blog.csdn.net/u010019717/article/details/43113305)


Using unityengine;using system.collections;using system;///<summary>///is used to capture the screen of the game, which is a screenshot///test can be used to capture the problem /</summary>public class screenshoter:monobehaviour{public    string FilePath  = Application.datapath;    void Awake ()    {        dontdestroyonload (transform.gameobject);    }    void Ongui ()    {        if (GUI. button (New Rect ((screen.width-60) * 0.5f, 0, 60, 30), "screenshot"))        {            application.capturescreenshot (string. Format ("{0}\\ss_{1}x{2}_{3}.jpg", FilePath, Screen.width, Screen.height, System.DateTime.UtcNow.Subtract (new DateTime (1970, 1, 1, 0, 0, 0, DATETIMEKIND.UTC)). totalseconds));}}}    



U3d to capture the game screen with Capturescreenshot

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.