1.実現したいこと
ゲーム画面のスクリーンショットを撮影するときに、非表示にしたUIを再度表示状態にしたい
2.発生している問題
UIが非表示の状態になったスクリーンショットを撮影して、保存先にPNGファイルが保存されますが、UIが消えたままで再表示されません。
3.該当のソースコード
C#
using System; using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; using UnityEngine.UI; public class ScreenShot: MonoBehaviour { // スクリーンショットボタン [SerializeField] private GameObject ScreenpshotButton; // ログパネル [SerializeField] private GameObject logPanel; // 解像度パネル [SerializeField] private GameObject superSizePanel; // 解像度レベルスライダー [SerializeField] private Slider superSizeSlider; // 解像度レベルテキスト [SerializeField] private Text superSizeText; // スクリーンショットを撮ってからの待ち時間 [SerializeField] private float waitTime = 2f; // データの保存先ファイルパス private string saveFilePath = "Assets"; // 保存ファイル名 private string saveFileName = "/scan.PNG"; // その他のUIを定義しておく場所 [SerializeField] private GameObject CameraStartButton; [SerializeField] private GameObject ChangeCameraButton; [SerializeField] private GameObject RawImage; void Start() { // UIの初期設定 ScreenpshotButton.SetActive(true); logPanel.SetActive(false); superSizePanel.SetActive(true); CameraStartButton.SetActive(true); ChangeCameraButton.SetActive(true); SnapshotOpeButton.SetActive(true); GoToRegistraionButton.SetActive(true); ProjectionMappingButton.SetActive(true); RawImage.SetActive(true); // 指定したフォルダがない時はAssetsフォルダに保存 if (!Directory.Exists(Application.dataPath + saveFilePath)) { saveFilePath = ""; } } // スクリーンショットボタンを押す public void ScreenpshotButton() { StartCoroutine(OperationUI()); } // スクリーンショット処理 IEnumerator OperationUI() { // スクリーンショットを撮る前にUIを全部非表示 ScreenpshotButton.SetActive(false); logPanel.SetActive(false); superSizePanel.SetActive(false); CameraStartButton.SetActive(false); ChangeCameraButton.SetActive(false); RawImage.SetActive(false); // スクリーンショットを撮る ScreenCapture.CaptureScreenshot(Application.dataPath + saveFilePath + saveFileName, (int)superSizeSlider.value); // 待ち時間を入れないとlogPanelが表示されるので一定時間待つ yield return new WaitForSeconds(0.1f); logPanel.transform.GetChild(0).GetComponent<Text>().text = "Captured!\n" + Application.dataPath + saveFilePath + saveFileName; // スクリーンショットを撮った旨を表示 logPanel.SetActive(true); yield return new WaitForSeconds(waitTime); // UIを元に戻す ScreenpshotButton.SetActive(true); superSizePanel.SetActive(true); logPanel.SetActive(false); CameraStartButton.SetActive(true); ChangeCameraButton.SetActive(true); } }
4.自分で調べたこと、試したこと
保存先のフォルダを変更したり、保存の待ち時間を変更など試みましたが、変化がありませんでした。教えていただけると幸いです。
5.使用しているUnityのバージョン
Unity.2020.3.22f1
まだ回答がついていません
会員登録して回答してみよう