1.実現したいこと
ゲーム画面のスクリーンショットを撮影するときに、非表示にしたUIを再度表示状態にしたい
2.発生している問題
UIが非表示の状態になったスクリーンショットを撮影して、保存先にPNGファイルが保存されますが、UIが消えたままで再表示されません。
3.該当のソースコード
C#
1using System; 2using System.Collections; 3using System.Collections.Generic; 4using System.IO; 5using UnityEngine; 6using UnityEngine.UI; 7 8public class ScreenShot: MonoBehaviour 9{ 10 // スクリーンショットボタン 11 [SerializeField] 12 private GameObject ScreenpshotButton; 13 // ログパネル 14 [SerializeField] 15 private GameObject logPanel; 16 // 解像度パネル 17 [SerializeField] 18 private GameObject superSizePanel; 19 // 解像度レベルスライダー 20 [SerializeField] 21 private Slider superSizeSlider; 22 // 解像度レベルテキスト 23 [SerializeField] 24 private Text superSizeText; 25 // スクリーンショットを撮ってからの待ち時間 26 [SerializeField] 27 private float waitTime = 2f; 28 // データの保存先ファイルパス 29 private string saveFilePath = "Assets"; 30 // 保存ファイル名 31 private string saveFileName = "/scan.PNG"; 32 // その他のUIを定義しておく場所 33 [SerializeField] 34 private GameObject CameraStartButton; 35 [SerializeField] 36 private GameObject ChangeCameraButton; 37 [SerializeField] 38 private GameObject RawImage; 39 40 void Start() 41 { 42 // UIの初期設定 43 ScreenpshotButton.SetActive(true); 44 logPanel.SetActive(false); 45 superSizePanel.SetActive(true); 46 CameraStartButton.SetActive(true); 47 ChangeCameraButton.SetActive(true); 48 SnapshotOpeButton.SetActive(true); 49 GoToRegistraionButton.SetActive(true); 50 ProjectionMappingButton.SetActive(true); 51 RawImage.SetActive(true); 52 53 54 // 指定したフォルダがない時はAssetsフォルダに保存 55 if (!Directory.Exists(Application.dataPath + saveFilePath)) 56 { 57 saveFilePath = ""; 58 } 59 } 60 61 // スクリーンショットボタンを押す 62 public void ScreenpshotButton() 63 { 64 StartCoroutine(OperationUI()); 65 } 66 // スクリーンショット処理 67 IEnumerator OperationUI() 68 { 69 // スクリーンショットを撮る前にUIを全部非表示 70 ScreenpshotButton.SetActive(false); 71 logPanel.SetActive(false); 72 superSizePanel.SetActive(false); 73 CameraStartButton.SetActive(false); 74 ChangeCameraButton.SetActive(false); 75 RawImage.SetActive(false); 76 77 // スクリーンショットを撮る 78 ScreenCapture.CaptureScreenshot(Application.dataPath + saveFilePath + saveFileName, (int)superSizeSlider.value); 79 80 // 待ち時間を入れないとlogPanelが表示されるので一定時間待つ 81 yield return new WaitForSeconds(0.1f); 82 logPanel.transform.GetChild(0).GetComponent<Text>().text = "Captured!\n" + Application.dataPath + saveFilePath + saveFileName; 83 84 // スクリーンショットを撮った旨を表示 85 logPanel.SetActive(true); 86 yield return new WaitForSeconds(waitTime); 87 88 // UIを元に戻す 89 ScreenpshotButton.SetActive(true); 90 superSizePanel.SetActive(true); 91 logPanel.SetActive(false); 92 CameraStartButton.SetActive(true); 93 ChangeCameraButton.SetActive(true); 94 } 95}
4.自分で調べたこと、試したこと
保存先のフォルダを変更したり、保存の待ち時間を変更など試みましたが、変化がありませんでした。教えていただけると幸いです。
5.使用しているUnityのバージョン
Unity.2020.3.22f1
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/01/27 02:16
2022/01/27 06:13
2022/01/27 14:16
2022/02/01 06:14
2022/02/01 10:29
2022/02/03 03:32