コード例 #1
0
        private IEnumerator CreateScreenshot()
        {
            yield return(new WaitForEndOfFrame());

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

            screenTexture.ReadPixels(new Rect(0f, 0f, Screen.width, Screen.height), 0, 0);
            screenTexture.Apply();

            string filename    = System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss");
            string pathToImage = Path.Combine(Application.persistentDataPath, filename + ".png");

            byte[] dataToSave = screenTexture.EncodeToPNG();
            File.WriteAllBytes(pathToImage, dataToSave);

            #if UNITY_ANDROID
            if (OnAndroidScreenshotSaved != null)
            {
                OnAndroidScreenshotSaved(pathToImage);
            }
            #endif

            #if UNITY_IOS
            StartCoroutine(IOSPhotoGalleryHandler.SaveExisting(pathToImage));
            #endif
        }
コード例 #2
0
        public void ShareTexture2D(string shareText, Texture2D texture2D)
        {
            tmpCurrentShareText = shareText;

            string filename    = System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss");
            string pathToImage = Path.Combine(Application.persistentDataPath, filename + ".png");

            byte[] dataToSave = texture2D.EncodeToPNG();
            File.WriteAllBytes(pathToImage, dataToSave);

            #if UNITY_ANDROID
            if (OnAndroidScreenshotSaved != null)
            {
                OnAndroidScreenshotSaved(pathToImage);
            }
            #endif

            #if UNITY_IOS
            StartCoroutine(IOSPhotoGalleryHandler.SaveExisting(pathToImage));
            #endif
        }