コード例 #1
0
        public delegate void OnComplete(string errorMessage);         // エラーがなく成功すればnull

        // この関数だけはStartCoroutineで呼ばないと動かない
        public IEnumerator CoPostScreenshot(
            System.Action onImageCaptured = null, // 画像が取れた後で呼ぶコールバック(デバグUIを復活させるなど)
            string message                = null,
            OnComplete onComplete         = null, // 完了コールバック(ポップアップを出す、ログを出す、等々)
            string channel                = null, // チャネル名を変更したければここに与える(与えなければdefaultChannel)
            int waitFrameCount            = 0,    // デバグUIを消すなどがすぐに済まない場合、ここにフレーム数を指定
            bool withAlpha                = false,
            TextureUtil.FileType fileType = TextureUtil.FileType.Png)
        {
            var coRet = new CoRetVal <byte[]>();

            yield return(TextureUtil.CoGetScreenshot(coRet, withAlpha, waitFrameCount, fileType));

            if (onImageCaptured != null)
            {
                onImageCaptured();
            }

            if (channel == null)
            {
                channel = _defaultChannel;
            }

            var    now      = System.DateTime.Now;
            string filename = now.ToString("yyyyMMdd_HHmmss");

            filename += (fileType == TextureUtil.FileType.Jpeg) ? ".jpg" : ".png";
            yield return(CoPostBinary(coRet.value, filename, message, onComplete, channel));
        }
コード例 #2
0
        public static IEnumerator CoGetScreenshot(
            CoRetVal <byte[]> retVal,
            bool withAlpha     = true,
            int waitFrameCount = 0,             // デバグUIを消すなどがすぐに済まない場合、ここにフレーム数を指定
            FileType fileType  = FileType.Png)
        {
            for (int i = 0; i < waitFrameCount; i++)
            {
                yield return(null);
            }
            yield return(new WaitForEndOfFrame());

            var width   = Screen.width;
            var height  = Screen.height;
            var format  = withAlpha ? TextureFormat.RGBA32 : TextureFormat.RGB24;
            var texture = new Texture2D(width, height, format, mipChain: false);

            texture.ReadPixels(new Rect(0, 0, width, height), 0, 0);

            var bytes = ConvertReadableTextureToFile(texture, fileType);

            retVal.Succeed(bytes);
        }