前提・実現したいこと
シーン移動するときにプログレスバーでNowLoading画面を出したい。
発生している問題
プログレスバーは読み込み完了と表示されてから急に動かなくなり、固まってしまう。
しばらく画面が固まった状態が続き、いきなり次のシーンに移動する。
疑問点
読み込み完了と表示されているのにすぐに次のシーンへ行かないのはなぜか。
現在の状態
Scene1にScene2の読み込みを始めるボタンを置いた。
Sene2にはキャラクターを動的に2500体設置する命令を記述したプログラムを関連づけた。
試したこと
下記「Load.cs」ファイルをScene1に関連づけました。
C#
1using System.Collections; 2using UnityEngine; 3using UnityEngine.SceneManagement; 4using UnityEngine.UI; 5 6public class Load : MonoBehaviour 7{ 8 public Text m_Text; 9 public Button m_Button; 10 public Slider m_Slider; 11 12 void Start() 13 { 14 m_Button.onClick.AddListener(LoadButton); 15 } 16 17 void LoadButton() 18 { 19 m_Button.gameObject.SetActive (false); 20 StartCoroutine(LoadScene()); 21 } 22 23 IEnumerator LoadScene() 24 { 25 yield return null; 26 27 AsyncOperation asyncOperation = SceneManager.LoadSceneAsync("Scene2"); 28 asyncOperation.allowSceneActivation = false; 29 while (!asyncOperation.isDone) 30 { 31 m_Text.text = "Loading progress: " + (asyncOperation.progress * 100) + "%"; 32 m_Slider.value = Mathf.Clamp01(asyncOperation.progress / 0.9f); 33 34 if (asyncOperation.progress >= 0.9f) 35 { 36 m_Text.text = "読み込み完了"; 37 asyncOperation.allowSceneActivation = true; 38 } 39 40 yield return null; 41 } 42 } 43}
下記「Sample.cs」ファイルをScene2に関連づけました。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using UnityEngine.UI; 5using UnityEngine.SceneManagement; 6 7public class sample : MonoBehaviour 8{ 9 10 public GameObject prefabUnityChan; 11 12 13 // Start is called before the first frame update 14 void Start() 15 { 16 17 for(int i=0; i<50; i++){ 18 for(int j=0; j<50; j++){ 19 Vector2 unityChanPosition = new Vector2(i,j); 20 Quaternion q = new Quaternion(); 21 q = Quaternion.identity; 22 Instantiate(prefabUnityChan ,unityChanPosition , q); 23 } 24 } 25 } 26 27 // Update is called once per frame 28 void Update() 29 { 30 31 } 32} 33
仮説
「SceneManager.LoadSceneAsync」はUnityソフトのScene画面でドラッグ&ドロップでステージに設置したリソースだけを読み込み、動的に読み込むリソースまでは読み込んでくれない?
→移動先シーンで動的に読み込むリソースを1つのフォルダにまとめておき、そのフォルダ内のリソースの読み込みも監視する必要がある?
参考サイト
https://www.youtube.com/watch?v=7Vcf7l-Ywi0
https://docs.unity3d.com/ScriptReference/AsyncOperation-progress.html
https://gametukurikata.com/program/nowloading
補足情報(FW/ツールのバージョンなど)
unity = 2018.3.14f1 Personal
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2019/07/15 14:31
2019/07/15 14:32