2017-08-28 50 views
1

共有9個場景。全部都在「Build Settings」中添加。 7個場面出9加載,但是當我嘗試加載其他兩個場景就不停地說:現場不裝貨

場景「SceneName」無法加載,因爲它沒有被添加到構建設置或AssetBundle有未加載。到場景添加到構建設置使用菜單文件 - >構建設置... UnityEngine.SceneManagement.SceneManager:LoadSceneAsync(字符串,LoadSceneMode)MoreMountains.CorgiEngine.c__Iterator0:調用MoveNext()(在資產/ CorgiEngine /通用/腳本/經理/ LoadingSceneManager.cs:88)UnityEngine.MonoBehaviour:StartCoroutine(IEnumerator的)MoreMountains.CorgiEngine.LoadingSceneManager:開始()(在資產/ CorgiEngine /通用/腳本/經理/ LoadingSceneManager.cs:67)

Here is my "Scene In Build" Image

我已經添加了場景的場景管理器,但它一直顯示此錯誤。我已經嘗試了很多。請幫我解決問題。這是我的「LoadingSceneManager」腳本:

using UnityEngine; 
using UnityEngine.UI; 
using System.Collections; 
using System.Collections.Generic; 
using MoreMountains.Tools; 
using UnityEngine.SceneManagement; 

namespace MoreMountains.CorgiEngine 
{ 
public class LoadingSceneManager : MonoBehaviour 
{ 
    [Header("Binding")] 
    /// The name of the scene to load while the actual target scene is 
    loading (usually a loading screen) 
    public static string LoadingScreenSceneName="LoadingScreen"; 

    [Header("GameObjects")] 
    /// the text object where you want the loading message to be displayed 
    public Text LoadingText; 
    /// the canvas group containing the progress bar 
    public CanvasGroup LoadingProgressBar; 
    /// the canvas group containing the animation 
    public CanvasGroup LoadingAnimation; 
    /// the canvas group containing the animation to play when loading is complete 
    public CanvasGroup LoadingCompleteAnimation; 

    [Header("Time")] 
    /// the duration (in seconds) of the initial fade in 
    public float StartFadeDuration=0.2f; 
    /// the speed of the progress bar 
    public float ProgressBarSpeed=2f; 
    /// the duration (in seconds) of the load complete fade out 
    public float ExitFadeDuration=0.2f; 
    /// the delay (in seconds) before leaving the scene when complete 
    public float LoadCompleteDelay=0.5f; 

    protected AsyncOperation _asyncOperation; 
    protected static string _sceneToLoad = ""; 
    protected float _fadeDuration = 0.5f; 
    protected float _fillTarget=0f; 
    protected string _loadingTextValue; 

    /// <summary> 
    /// Call this static method to load a scene from anywhere 
    /// </summary> 
    /// <param name="sceneToLoad">Level name.</param> 
    public static void LoadScene(string sceneToLoad) 
    {  
     _sceneToLoad = sceneToLoad;     
     Application.backgroundLoadingPriority = ThreadPriority.High; 
     if (LoadingScreenSceneName!=null) 
     { 
      SceneManager.LoadScene(LoadingScreenSceneName); 
     } 
    } 

    /// <summary> 
    /// On Start(), we start loading the new level asynchronously 
    /// </summary> 
    protected virtual void Start() 
    { 
     _loadingTextValue=LoadingText.text; 
     if (_sceneToLoad != "") 
     { 
      StartCoroutine(LoadAsynchronously()); 
     } 
    } 

    /// <summary> 
    /// Every frame, we fill the bar smoothly according to loading progress 
    /// </summary> 
    protected virtual void Update() 
    { 
     LoadingProgressBar.GetComponent<Image>().fillAmount = MMMaths.Approach(LoadingProgressBar.GetComponent<Image>().fillAmount,_fillTarget,Time.deltaTime*ProgressBarSpeed); 
    } 

    /// <summary> 
    /// Loads the scene to load asynchronously. 
    /// </summary> 
    protected virtual IEnumerator LoadAsynchronously() 
    { 
     // we setup our various visual elements 
     LoadingSetup(); 

     // we start loading the scene 
     _asyncOperation = SceneManager.LoadSceneAsync(_sceneToLoad,LoadSceneMode.Single); 
     _asyncOperation.allowSceneActivation = false; 

     // while the scene loads, we assign its progress to a target that we'll use to fill the progress bar smoothly 
     while (_asyncOperation.progress < 0.9f) 
     { 
      _fillTarget = _asyncOperation.progress; 
      yield return null; 
     } 
     // when the load is close to the end (it'll never reach it), we set it to 100% 
     _fillTarget = 1f; 

     // we wait for the bar to be visually filled to continue 
     while (LoadingProgressBar.GetComponent<Image>().fillAmount != _fillTarget) 
     { 
      yield return null; 
     } 

     // the load is now complete, we replace the bar with the complete animation 
     LoadingComplete(); 
     yield return new WaitForSeconds(LoadCompleteDelay); 

     // we fade to black 
     GUIManager.Instance.FaderOn(true,ExitFadeDuration); 
     yield return new WaitForSeconds(ExitFadeDuration); 

     // we switch to the new scene 
     _asyncOperation.allowSceneActivation = true; 
    } 

    /// <summary> 
    /// Sets up all visual elements, fades from black at the start 
    /// </summary> 
    protected virtual void LoadingSetup() 
    { 
     GUIManager.Instance.Fader.gameObject.SetActive(true); 
     GUIManager.Instance.Fader.GetComponent<Image>().color=new Color(0,0,0,1f); 
     GUIManager.Instance.FaderOn(false,ExitFadeDuration); 

     LoadingCompleteAnimation.alpha=0; 
     LoadingProgressBar.GetComponent<Image>().fillAmount = 0f; 
     LoadingText.text = _loadingTextValue; 

    } 

    /// <summary> 
    /// Triggered when the actual loading is done, replaces the progress bar with the complete animation 
    /// </summary> 
    protected virtual void LoadingComplete() 
    { 
     LoadingCompleteAnimation.gameObject.SetActive(true); 
     StartCoroutine(MMFade.FadeCanvasGroup(LoadingProgressBar,0.1f,0f)); 
     StartCoroutine(MMFade.FadeCanvasGroup(LoadingAnimation,0.1f,0f)); 
     StartCoroutine(MMFade.FadeCanvasGroup(LoadingCompleteAnimation,0.1f,1f)); 

    } 
} 

}

+1

你是什麼意思「我已經添加了場景管理場景」是什麼意思?你在談論構建設置? (菜單「文件」>「生成設置」)。你確定你要加載的場景的名稱是**完全**構建設置中的場景名稱嗎? – Hellium

+0

只是關於樣式的一個側面說明,您不需要在C#中用下劃線爲您的私有/受保護的變量添加前綴。你可以使用'this.sceneToLoad = sceneToLoad'而不是下劃線語法。 – Soviut

+0

@Hellium是的我在談論構建設置,我想要加載的所有場景都在構建設置中,並且名稱正確,但仍然顯示錯誤 – Farooq

回答

3

你有沒有加入你的場景,你嘗試加載到構建設置「場景在Build」節? 這是使用場景管理器切換到項目中的任何場景所必需的。

enter image description here

+0

是的,我已經添加了正確名稱的「Scene In Build」中的所有場景 – Farooq

0

GO文件 - >和構建設置確保你擁有所有的場景在框中。 enter image description here

0

,或者你可以通過它們的索引使用,然後使用字符串

相當重視其更容易的方法

SceneManager.LoadScene(0);

,然後通過打開建立添加所有這些場景設置窗口

0

它看起來像你嘗試用名稱來加載場景:「SceneName」。

  1. 檢查您是否已經對函數的參數正確的價值觀。
  2. 嘗試加載使用索引而不是名稱問題的場景。
0

請檢查你函數 「LoadScene」。

我不確定什麼確切的問題,但從您的日誌中問題是在「LoadScene」功能。