zoukankan      html  css  js  c++  java
  • 场景同步异步加载

    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();
            }
        }
    }
  • 相关阅读:
    Extjs4 MVC Controller中refs使用
    Mac下下载android4.2源码,进行源码调试
    来博客园一年三个月
    今天写的比较多
    Extjs4 MVC 添加view层
    mac自带vim7配置
    动态测试及调试工具
    等价类划分的延伸
    用javascript进行测试用例的验证
    同行评审在软件测试中的应用
  • 原文地址:https://www.cnblogs.com/DazeJiang/p/14269279.html
Copyright © 2011-2022 走看看