• 场景同步异步加载


    using System;
    using System.Collections;
    using UnityEngine;
    using UnityEngine.Events;
    using UnityEngine.SceneManagement;
    
    public class SceneComponent : GameComponent
    {
        public UnityAction beginLoad;
        public float LoadProgress { get; private set; }
    
        public void Awake()
        {
            Initinalize();
        }
        public override void Initinalize()
        {
            base.Initinalize();
        }
        public override void Release()
        {
    
        }
        public override void Update()
        {
    
        }
        public void LoadScene(string name)
        {
            SceneManager.LoadScene(name);
            if (beginLoad!=null)
            {
                beginLoad();
            }
        }
        public void LoadSceneAsync(string name, bool showLoadingUI=false, Action onComplete = null)
        {
            StartCoroutine(LoadSceneAsyn(name,showLoadingUI,onComplete));
        }
        private IEnumerator LoadSceneAsyn(string name,bool showLoadingUI=false,Action onComplete=null)
        {
            AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(name);
            asyncOperation.allowSceneActivation = false;
            if (beginLoad!=null)
            {
                beginLoad();
            }
            if (showLoadingUI)
            {
                m_GameManager.GetGameSystem<UISystem>().GetUIView<LoadingView>().Show();
                yield return null;
            }
            LoadProgress = 0;
            while (asyncOperation.progress<0.9f)
            {
                LoadProgress = asyncOperation.progress;
                yield return null;
            }
            yield return new WaitForSeconds(2);
            while (LoadProgress < 1)
            {
                LoadProgress += 0.1f;
                yield return null;
            }
            asyncOperation.allowSceneActivation = true;
            if (showLoadingUI)
            {
                m_GameManager.GetGameSystem<UISystem>().GetUIView<LoadingView>().Hide();
            }
            if (onComplete != null)
            {
                onComplete();
            }
        }
    }
  • 相关阅读:
    VS2013搭建wxWidgets开发环境
    LinuxSystemProgramming-Syllabus
    Python入门2(Python与C语言语法的不同、Notepad++运行Python代码)
    Python入门1(简介、安装)
    面试题收集---grep和find的区别
    浅拷贝 和深拷贝
    使用 system.io.filesysteminfo 来查找文件。
    使用FileSystemWatcher捕获系统文件状态
    system.io.file创建
    Javascript诞生记 [转载]
  • 原文地址:https://www.cnblogs.com/DazeJiang/p/14269279.html
Copyright © 2020-2023  润新知