コード例 #1
0
ファイル: WebCommunicator.cs プロジェクト: PluMGMK/Ray1Map
    async UniTaskVoid TakeScreenshot(WebJSON.Screenshot msg)
    {
        if (msg != null)
        {
            TransparencyCaptureBehaviour tcb = Camera.main.GetComponent <TransparencyCaptureBehaviour>();
            if (tcb != null)
            {
                try {
                    if (msg.Type == WebJSON.Screenshot.ScreenshotType.FullLevel)
                    {
                        System.DateTime dateTime        = System.DateTime.Now;
                        byte[]          screenshotBytes = await tcb.CaptureFulllevel(msg.IsTransparent ?? true);

                        SaveFile(screenshotBytes, screenshotBytes.Length, $"Screenshot_{dateTime.ToString("yyyy_MM_dd HH_mm_ss")}.png");
                    }
                    else
                    {
                        Resolution res    = TransparencyCaptureBehaviour.GetCurrentResolution();
                        int        height = msg.Height ?? Mathf.RoundToInt(res.height * (msg.SizeFactor ?? 1));
                        int        width  = msg.Width ?? Mathf.RoundToInt(res.width * (msg.SizeFactor ?? 1));
                        if (width > 0 && height > 0)
                        {
                            System.DateTime dateTime        = System.DateTime.Now;
                            byte[]          screenshotBytes = await tcb.Capture(width, height, msg.IsTransparent ?? true);

                            SaveFile(screenshotBytes, screenshotBytes.Length, $"Screenshot_{dateTime.ToString("yyyy_MM_dd HH_mm_ss")}.png");
                        }
                    }
                } catch (Exception) {
                    Debug.Log("Screenshot failed");
                }
            }
        }
    }
コード例 #2
0
    public override async void OnInspectorGUI()
    {
        DrawDefaultInspector();

        TransparencyCaptureBehaviour pb = (TransparencyCaptureBehaviour)target;

        if (GUILayout.Button("Take screenshot"))
        {
            Resolution      res             = GetCurrentResolution();
            System.DateTime dateTime        = System.DateTime.Now;
            byte[]          screenshotBytes = await pb.Capture(res.width * 4, res.height * 4);

            OpenSpace.Util.ByteArrayToFile(UnitySettings.ScreenshotPath + "/" + dateTime.ToString("yyyy_MM_dd HH_mm_ss") + ".png", screenshotBytes);
        }
    }