mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
init: add project
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
namespace Assets._Project.Develop.Runtime.Utilities.SceneManagement
|
||||
{
|
||||
public interface IInputSceneArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cbe85b26d7f0422449ab0fb3f0443455
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Utilities.SceneManagement
|
||||
{
|
||||
public class SceneLoaderService
|
||||
{
|
||||
public IEnumerator LoadAsync(string sceneName, LoadSceneMode loadSceneMode = LoadSceneMode.Single)
|
||||
{
|
||||
AsyncOperation wait = SceneManager.LoadSceneAsync(sceneName, loadSceneMode);
|
||||
|
||||
yield return new WaitWhile(() => wait.isDone == false);
|
||||
}
|
||||
|
||||
public IEnumerator UnloadAsync(string sceneName)
|
||||
{
|
||||
AsyncOperation wait = SceneManager.UnloadSceneAsync(sceneName);
|
||||
|
||||
yield return new WaitWhile(() => wait.isDone == false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5b398e252187d742ab651dfb1906f35
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using Assets._Project.Develop.Runtime.Infrastructure;
|
||||
using Assets._Project.Develop.Runtime.Infrastructure.DI;
|
||||
using Assets._Project.Develop.Runtime.Utilities.LoadingScreen;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Assets._Project.Develop.Runtime.Utilities.SceneManagement
|
||||
{
|
||||
public class SceneSwitcherService
|
||||
{
|
||||
private readonly SceneLoaderService _sceneLoaderService;
|
||||
private readonly ILoadingScreen _loadingScreen;
|
||||
private readonly DIContainer _projectContainer;
|
||||
|
||||
private DIContainer _currentSceneContainer;
|
||||
|
||||
public SceneSwitcherService(
|
||||
SceneLoaderService sceneLoaderService,
|
||||
ILoadingScreen loadingScreen,
|
||||
DIContainer projectContainer)
|
||||
{
|
||||
_sceneLoaderService = sceneLoaderService;
|
||||
_loadingScreen = loadingScreen;
|
||||
_projectContainer = projectContainer;
|
||||
}
|
||||
|
||||
public IEnumerator ProcessSwitchTo(string sceneName, IInputSceneArgs sceneArgs = null)
|
||||
{
|
||||
_loadingScreen.Show();
|
||||
|
||||
_currentSceneContainer?.Dispose();
|
||||
|
||||
yield return _sceneLoaderService.LoadAsync(Scenes.Empty);
|
||||
yield return _sceneLoaderService.LoadAsync(sceneName);
|
||||
|
||||
SceneBootstrap sceneBootstrap = Object.FindObjectOfType<SceneBootstrap>();
|
||||
|
||||
if (sceneBootstrap == null)
|
||||
throw new NullReferenceException(nameof(sceneBootstrap) + " not found");
|
||||
|
||||
_currentSceneContainer = new DIContainer(_projectContainer);
|
||||
|
||||
sceneBootstrap.ProcessRegistrations(_currentSceneContainer, sceneArgs);
|
||||
|
||||
_currentSceneContainer.Initialize();
|
||||
|
||||
yield return sceneBootstrap.Initialize();
|
||||
|
||||
_loadingScreen.Hide();
|
||||
|
||||
sceneBootstrap.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b42893fbf47ad02419f5a38341c5ddc6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user