87 lines
2.7 KiB
C#
87 lines
2.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Accessibility;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class SceneOverlayManager : MonoBehaviour
|
|
{
|
|
public static SceneOverlayManager Instance;
|
|
|
|
public string _normal_scene = "深圳市民中心_白天_HD";
|
|
string _last_loaded_scene;
|
|
|
|
private List<AsyncOperation> operations = new List<AsyncOperation>();
|
|
|
|
private void Awake()
|
|
{
|
|
if (Instance == null)
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject);
|
|
}
|
|
else
|
|
{
|
|
if (Instance != this)
|
|
{
|
|
Debug.Log("warning: multiple Manager creating!");
|
|
GameObject.Destroy(gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
//if (!string.IsNullOrEmpty(_normal_scene))
|
|
//{
|
|
// LoadSceneAsync(_normal_scene);
|
|
//}
|
|
//if (GameInit.Instance == null)
|
|
// LoadSceneAsync("深圳市民中心_白天_HD", true, (_async) =>
|
|
// {
|
|
// LoadSceneAsync("无人机组件控制器", false);
|
|
// });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 异步加载场景
|
|
/// </summary>
|
|
/// <param name="_load_scene_name">场景名</param>
|
|
/// <param name="_unload_last_scene">是否卸载上一个加载的场景</param>
|
|
/// <param name="_load_complete_callback">加载完成回调事件</param>
|
|
/// <param name="_unload_complete_callback">卸载完成回调事件</param>
|
|
/// <param name="_load_scene_mode">加载模式</param>
|
|
public void LoadSceneAsync(string _load_scene_name, bool _unload_last_scene = true, Action<AsyncOperation> _load_complete_callback = null, Action<AsyncOperation> _unload_complete_callback = null, LoadSceneMode _load_scene_mode = LoadSceneMode.Additive)
|
|
{
|
|
try
|
|
{
|
|
//卸载上一个场景
|
|
if (_unload_last_scene)
|
|
{
|
|
if (!string.IsNullOrEmpty(_last_loaded_scene) && _load_scene_name != _last_loaded_scene)
|
|
{
|
|
var _unload_async = SceneManager.UnloadSceneAsync(_last_loaded_scene);
|
|
_unload_async.completed += _unload_complete_callback;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
|
|
}
|
|
|
|
//加载目标场景
|
|
var _load_scene = SceneManager.GetSceneByName(_load_scene_name);
|
|
if (_load_scene != null && !_load_scene.isLoaded)
|
|
{
|
|
var _load_async = SceneManager.LoadSceneAsync(_load_scene_name, _load_scene_mode);
|
|
_load_async.completed += _load_complete_callback;
|
|
}
|
|
|
|
if (_unload_last_scene)
|
|
_last_loaded_scene = _load_scene_name;
|
|
}
|
|
}
|