예제 #1
0
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="sceneName"></param>
        /// <param name="displayTime"></param>
        public void LoadScene(string sceneName, float displayTime = 0, IList <IAsyncTask> additiveTask = null, float additiveWeight = 1, System.Action complateCallback = null)
        {
            if (mLoadingScene == sceneName)
            {
#if UNITY_EDITOR
                Debug.LogWarning(string.Format("Scene:{0} is loading, don't need to load it agin.", sceneName));
#endif
                if (complateCallback != null)
                {
                    mLoadEndCallback += complateCallback;
                }
                if (additiveTask != null)
                {
                    mLoader.AddTasks(additiveTask, additiveWeight);
                }
                return;
            }
            Scene scene = SceneManager.GetSceneByName(sceneName);
            if (scene.isLoaded)
            {
#if UNITY_EDITOR
                Debug.LogWarning(string.Format("Scene:{0} was loaded, don't need to load it agin.", scene.name));
#endif
                return;
            }
            mLoadingScene = sceneName;
            mLoader.Reset();
            mLoadEndCallback = complateCallback;
            mLoader.AddTask(new LoadSceneTask(mLoadingScene));
            if (displayTime > 0)
            {
                mLoader.AddTask(new TimeDisplayTask(displayTime), m_WaitForTimeWeight);
            }
            if (additiveTask != null)
            {
                mLoader.AddTasks(additiveTask, additiveWeight);
            }
            mLoader.OnStart();
            OnLoadBegin(mLoadingScene);
            mLoading = true;
        }