123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Threading.Tasks;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- namespace WS
- {
-
- public class SceneComponent : SingleComponent<SceneComponent>
- {
-
- public string ThisScene { get { return SceneManager.GetActiveScene().name; } }
-
-
- public void LoadScene(string name)
- {
- Release();
- SceneManager.LoadScene(name);
- }
-
-
-
- public void LoadScene(string name, Action oncallback = null)
- {
- LoadScene(name, null, ViewShowModeType.Screen, oncallback);
- }
-
-
-
-
- public void LoadScene(string name, string describe, Action oncallback = null)
- {
- LoadScene(name, describe, ViewShowModeType.Screen, oncallback);
- }
-
-
-
-
- public void LoadScene(string name, string describe, ViewShowModeType viewShowMode, Action oncallback = null)
- {
-
-
- Release();
- SceneChange change = ComponentFactory.CreateWithParent<SceneChange>(this);
- if (string.IsNullOrEmpty(describe))
- {
- describe = "加载场景中,请稍后...";
- }
- LoadingController controller = FacadeComponent.Instance.CreateController<LoadingController>();
- controller.OpenView(viewShowMode, change, describe);
- Action action = delegate { };
- action += delegate
- {
- controller.CloseView();
-
- change.Dispose();
- };
- if (oncallback != null)
- {
- action += oncallback;
- }
- change.LoadScene(name, action);
- }
-
-
- public async Task LoadSceneAsync(string name)
- {
- await LoadSceneAsync(name, null);
- }
-
-
-
- public async Task LoadSceneAsync(string name, string describe)
- {
-
-
- Release();
- SceneChange change = ComponentFactory.CreateWithParent<SceneChange>(this);
- if (string.IsNullOrEmpty(describe))
- {
- describe = "加载场景中,请稍后...";
- }
- LoadingController controller = FacadeComponent.Instance.CreateController<LoadingController>();
- controller.OpenView(ViewShowModeType.Screen, change, describe);
- Action action = delegate
- {
- controller.CloseView();
-
- change.Dispose();
- };
- await change.LoadSceneAsync(name, action);
- }
-
- private void Release()
- {
- GC.Collect();
- Resources.UnloadUnusedAssets();
- }
- }
- }
|