protected void LoadScene(string sceneName) { var foundScenes = AssetDatabase.FindAssets(SceneFilter + sceneName, new string[] { TestScenesFolderPath }); var scenePath = AssetDatabase.GUIDToAssetPath(foundScenes.First()); EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, new LoadSceneParameters(LoadSceneMode.Additive)); }
public void LoadSceneAsync(string sceneName, LoadSceneMode mode, Action onSuccess) { Log.Trace("[ilib-abloader] EditorContainer {0}, LoadSceneAsync {1}. mode{2}", m_Name, sceneName, mode); var paths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(m_Name, sceneName); if (paths.Length == 0) { onSuccess?.Invoke(); return; } LoadSceneParameters parameters = new LoadSceneParameters(mode); EditorSceneManager.LoadSceneAsyncInPlayMode(paths[0], parameters); //Asyncのコールバックが正常に動かないので無理やり実装 var scene = EditorSceneManager.GetSceneByPath(paths[0]); EditorApplication.CallbackFunction onLoad = null; onLoad = () => { if (scene.isLoaded || !scene.IsValid()) { EditorApplication.update -= onLoad; onSuccess?.Invoke(); } }; EditorApplication.update += onLoad; }
public void LoadSceneAsync(string pathAndassetName, Action <string, Scene, Asset> completed, LoadSceneMode mode = LoadSceneMode.Single) { pathAndassetName = CheckAssetPath(pathAndassetName); if (USED_AB_MODE) { Asset asset = LoadAssetAsync(pathAndassetName, eAssetType.SceneAsset, (data) => { AsyncOperation asyncOp = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(pathAndassetName, mode); asyncOp.completed += (operation) => { var sceneName = Path.GetFileName(pathAndassetName); var scene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(sceneName); completed?.Invoke(null, scene, data); }; }); } else { #if UNITY_EDITOR var scenePath = FindAssetPath(pathAndassetName); AsyncOperation asyncOp = EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, new LoadSceneParameters(mode)); asyncOp.completed += (data) => { var sceneName = Path.GetFileName(pathAndassetName); var scene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(sceneName); completed?.Invoke(null, scene, null); }; #endif } }
public IEnumerator SetUp() { // load scene yield return(EditorSceneManager.LoadSceneAsyncInPlayMode(ScenePath, new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive })); Scene scene = SceneManager.GetSceneByPath(ScenePath); SceneManager.SetActiveScene(scene); // wait for NetworkManager awake yield return(null); // load host benchmarker = Object.FindObjectOfType <NetworkManager>(); if (benchmarker == null) { Assert.Fail("Could not find Benchmarker"); yield break; } _ = benchmarker.StartHost(); }
public void NextLevel() { #if UNITY_EDITOR //in editor if we didn't found the current episode or level, mean we are playing a test scene not part of the //game database list, so calling next level is the same as restarting level if (s_CurrentEpisode < 0 || s_CurrentLevel < 0) { var asyncOp = EditorSceneManager.LoadSceneAsyncInPlayMode(EditorSceneManager.GetActiveScene().path, new LoadSceneParameters(LoadSceneMode.Single)); return; } #endif s_CurrentLevel += 1; if (GameDatabase.Instance.episodes[s_CurrentEpisode].scenes.Length <= s_CurrentLevel) { s_CurrentLevel = 0; s_CurrentEpisode += 1; } if (s_CurrentEpisode >= GameDatabase.Instance.episodes.Length) { s_CurrentEpisode = 0; } #if UNITY_EDITOR var op = EditorSceneManager.LoadSceneAsyncInPlayMode(GameDatabase.Instance.episodes[s_CurrentEpisode].scenes[s_CurrentLevel], new LoadSceneParameters(LoadSceneMode.Single)); #else SceneManager.LoadScene(GameDatabase.Instance.episodes[s_CurrentEpisode].scenes[s_CurrentLevel]); #endif }
/// <summary> /// 加载场景(异步) /// </summary> /// <param name="info">资源信息标记</param> /// <param name="loadingAction">加载中事件</param> /// <param name="loadDoneAction">加载完成事件</param> /// <returns>加载协程迭代器</returns> public IEnumerator LoadSceneAsync(SceneInfo info, HTFAction <float> loadingAction, HTFAction loadDoneAction) { float beginTime = Time.realtimeSinceStartup; //单线加载,如果其他地方在加载资源,则等待 if (_isLoading) { yield return(_loadWait); } //轮到本线路加载资源 _isLoading = true; //等待相关依赖资源的加载 yield return(LoadDependenciesAssetBundleAsync(info.AssetBundleName)); float waitTime = Time.realtimeSinceStartup; if (LoadMode == ResourceLoadMode.Resource) { throw new HTFrameworkException(HTFrameworkModule.Resource, "加载场景失败:场景加载不允许使用Resource模式!"); } else { #if UNITY_EDITOR if (IsEditorMode) { LoadSceneParameters parameters = new LoadSceneParameters() { loadSceneMode = LoadSceneMode.Additive, localPhysicsMode = LocalPhysicsMode.None }; yield return(EditorSceneManager.LoadSceneAsyncInPlayMode(info.AssetPath, parameters)); } else { yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); yield return(SceneManager.LoadSceneAsync(info.ResourcePath, LoadSceneMode.Additive)); } #else yield return(LoadAssetBundleAsync(info.AssetBundleName, loadingAction)); yield return(SceneManager.LoadSceneAsync(info.ResourcePath, LoadSceneMode.Additive)); #endif } float endTime = Time.realtimeSinceStartup; Log.Info(string.Format("异步加载场景完成[{0}模式]:{1}\r\n等待耗时:{2}秒 加载耗时:{3}秒" , LoadMode.ToString() , info.ResourcePath , waitTime - beginTime , endTime - waitTime)); loadDoneAction?.Invoke(); //本线路加载资源结束 _isLoading = false; }
public IEnumerator SetUp() { // load scene yield return(EditorSceneManager.LoadSceneAsyncInPlayMode(ScenePath, new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive })); Scene scene = SceneManager.GetSceneByPath(ScenePath); SceneManager.SetActiveScene(scene); // wait for NetworkManager awake yield return(null); // load host benchmarker = Object.FindObjectOfType <NetworkManager>(); if (benchmarker == null) { Assert.Fail("Could not find Benchmarker"); yield break; } System.Threading.Tasks.Task task = benchmarker.server.StartHost(benchmarker.client); while (!task.IsCompleted) { yield return(null); } }
public IEnumerator SetUp() { captureMeasurement = false; // load scene yield return(EditorSceneManager.LoadSceneAsyncInPlayMode(ScenePath, new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive })); Scene scene = SceneManager.GetSceneByPath(ScenePath); SceneManager.SetActiveScene(scene); // wait for NetworkManager awake yield return(null); // load host benchmarker = Object.FindObjectOfType <BenchmarkNetworkManager>(); if (benchmarker == null) { Assert.Fail("Could not find Benchmarker"); yield break; } benchmarker.BeforeLateUpdate = BeforeLateUpdate; benchmarker.AfterLateUpdate = AfterLateUpdate; }
protected override IEnumerator DoLoadSceneAsync(ISceneLoadingPromise <Scene> promise, string path, LoadSceneMode mode = LoadSceneMode.Single) { AssetPathInfo pathInfo = pathInfoParser.Parse(path); if (pathInfo == null) { promise.Progress = 0f; promise.SetException(string.Format("Parses the path info '{0}' failure.", path)); yield break; } var name = string.Format("{0}{1}", ASSETS, pathInfo.AssetName); #if UNITY_2018_3_OR_NEWER AsyncOperation operation = EditorSceneManager.LoadSceneAsyncInPlayMode(name, new LoadSceneParameters(mode)); #else AsyncOperation operation = LoadSceneMode.Additive.Equals(mode) ? EditorApplication.LoadLevelAdditiveAsyncInPlayMode(name) : EditorApplication.LoadLevelAsyncInPlayMode(name); #endif if (operation == null) { promise.SetException(string.Format("Not found the scene '{0}'.", path)); yield break; } operation.allowSceneActivation = false; while (operation.progress < 0.9f) { if (operation.progress == 0f) { operation.priority = promise.Priority; } promise.Progress = operation.progress; yield return(waitForSeconds); } promise.Progress = operation.progress; promise.State = LoadState.SceneActivationReady; while (!operation.isDone) { if (promise.AllowSceneActivation && !operation.allowSceneActivation) { operation.allowSceneActivation = promise.AllowSceneActivation; } promise.Progress = operation.progress; yield return(waitForSeconds); } Scene scene = SceneManager.GetSceneByName(Path.GetFileNameWithoutExtension(pathInfo.AssetName)); if (!scene.IsValid()) { promise.SetException(string.Format("Not found the scene '{0}'.", path)); yield break; } promise.Progress = 1f; promise.SetResult(scene); }
/// <summary> /// 异步加载场景 /// </summary> /// <param name="sceneName"></param> public Task <AsyncOperation> LoadSceneAsync(string assetBundleName, string sceneName, LoadSceneMode mode = LoadSceneMode.Additive) { TaskCompletionSource <AsyncOperation> task = new TaskCompletionSource <AsyncOperation>(); task.SetResult(EditorSceneManager.LoadSceneAsyncInPlayMode(sceneName, new LoadSceneParameters(mode))); return(task.Task); // return UnitySceneManager.LoadSceneAsync(sceneName, mode); }
public static AsyncOperation LoadLevelAdditiveAsyncInPlayMode(string path) { LoadSceneParameters parameters = new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive }; return(EditorSceneManager.LoadSceneAsyncInPlayMode(path, parameters)); }
public void LoadScene(string sceneName) { var scenePath = SceneRef.GetScenePath(sceneName); if (scenePath != string.Empty) { Debug.Log($"found scene: {scenePath}"); EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, new LoadSceneParameters(LoadSceneMode.Single)); } }
public IEnumerator SetUp() { this.TestInstructionExecutor = new UnityTestInstructionExecutor(); this.mockInput = new MockInput(); PlayerInput.Instance = this.mockInput; yield return(EditorSceneManager.LoadSceneAsyncInPlayMode( this.scenePath, new LoadSceneParameters(LoadSceneMode.Additive))); }
public IEnumerator Setup() { SceneManager.sceneLoaded += OnSceneLoaded; var execAssembly = Assembly.GetExecutingAssembly(); var packagePath = PackageInfo.FindForAssembly(execAssembly).assetPath; var scenePath = Path.Combine(packagePath, $"Tests/Runtime/GlobalObjectIdHash/{nameof(NetworkObjectGlobalObjectIdHashTests)}.unity"); yield return(EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, new LoadSceneParameters(LoadSceneMode.Additive))); }
public IEnumerator LoadSceneAsync(string scenePath, bool isAdditive) { scenePath = FormatScenePath(scenePath); LoadSceneParameters param = new LoadSceneParameters(isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); AsyncOperation operation = EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, param); while (!operation.isDone) { yield return(null); } }
public IEnumerator SetUp() => UniTask.ToCoroutine(async() => { #if UNITY_EDITOR await EditorSceneManager.LoadSceneAsyncInPlayMode(ScenePath, new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive }); #else throw new System.NotSupportedException("Test not supported in player"); #endif var scene = SceneManager.GetSceneByPath(ScenePath); SceneManager.SetActiveScene(scene); #if UNITY_EDITOR MonsterPrefab = AssetDatabase.LoadAssetAtPath <NetworkIdentity>(MonsterPath); #else throw new System.NotSupportedException("Test not supported in player"); #endif // load host Server = Object.FindObjectOfType <NetworkServer>(); ServerObjectManager = Object.FindObjectOfType <ServerObjectManager>(); Server.Authenticated.AddListener(conn => ServerObjectManager.SpawnVisibleObjects(conn, true)); var started = new UniTaskCompletionSource(); Server.Started.AddListener(() => started.TrySetResult()); // wait 1 frame before Starting server to give time for Unity to call "Start" await UniTask.Yield(); Server.StartServer(); await started.Task; socketFactory = Server.GetComponent <SocketFactory>(); Debug.Assert(socketFactory != null, "Could not find socket factory for test"); // connect from a bunch of clients for (var i = 0; i < ClientCount; i++) { await StartClient(i, socketFactory); } // spawn a bunch of monsters for (var i = 0; i < MonsterCount; i++) { SpawnMonster(i); } while (Object.FindObjectsOfType <MonsterBehavior>().Count() < MonsterCount * (ClientCount + 1)) { await UniTask.Delay(10); } });
void nextOnClick() { pge++; if (pge < 8) { storyBook.sprite = s[pge]; } else { EditorSceneManager.LoadSceneAsyncInPlayMode("Assets/Builder/Scenes/MainScene.unity", new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.None)); } }
public IEnumerator SetUp() => UniTask.ToCoroutine(async() => { // load scene await EditorSceneManager.LoadSceneAsyncInPlayMode(ScenePath, new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive }); Scene scene = SceneManager.GetSceneByPath(ScenePath); SceneManager.SetActiveScene(scene); // load host benchmarker = Object.FindObjectOfType <NetworkManager>(); benchmarker.Server.StartHost(benchmarker.Client).Forget(); });
private static void CheckLevelEnterPlayModeForLoadingMainScene() { if (!ProjectEditorConfig.Instance.AutoTestLevelScenes) { return; } // No game exists var game = FindAllObjects.InScene <GameBase>().FirstOrDefault(); if (game) { return; } // Found level helper var sceneRef = FindAllObjects.InScene <LevelSceneRefBase>(); if (sceneRef.Length <= 0) { return; } ManagedLog.Log($"Loading main scene to test {SceneManager.GetActiveScene().name}"); var testingScene = AssetDatabase.LoadAssetAtPath <SceneAsset>(SceneManager.GetActiveScene().path); GameWindow.TestLevel = AssetDatabase.LoadAssetAtPath <SceneAsset>(SceneManager.GetActiveScene().path); _asyncOperation = EditorSceneManager.LoadSceneAsyncInPlayMode(GameWindow.MainSceneAssetPath, new LoadSceneParameters(LoadSceneMode.Single)); _asyncOperation.completed += OnloadComplete; void OnloadComplete(AsyncOperation obj) { game = FindAllObjects.InScene <GameBase>().FirstOrDefault(); _asyncOperation.completed -= OnloadComplete; Assert.IsNotNull(game); #if USING_SHAPES WorldLog.OnScreen($"Testing {testingScene.name}"); #endif new Operation(delay: 1f, action: () => { game.StartGame(); }).Start(); } }
private AsyncOperation LoadSceneAsync(string name) { var loadParams = new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive, localPhysicsMode = LocalPhysicsMode.None }; #if UNITY_EDITOR var path = $"Assets/{name}.unity"; return(EditorSceneManager.LoadSceneAsyncInPlayMode(path, loadParams)); #else return(SceneManager.LoadSceneAsync(name, loadParams)); #endif // UNITY_EDITOR }
public AssetBundleLoadLevelSimulationOperation(string assetBundleName, string levelName, bool isAdditive) { string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, levelName); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + levelName + "\" in " + assetBundleName); return; } LoadSceneParameters parms = new LoadSceneParameters(isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); m_Operation = EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], parms); }
public async UniTask <Scene> LoadSceneAsync(string name, LoadSceneMode loadSceneMode, IProgress <float> progress, CancellationToken token) { string[] guids = AssetDatabase.FindAssets($"t: Scene {name}"); if (guids.Length == 0) { throw new Exception($"Scene {name} not found!"); } string scenePath = AssetDatabase.GUIDToAssetPath(guids.First()); await EditorSceneManager .LoadSceneAsyncInPlayMode(scenePath, new LoadSceneParameters(loadSceneMode)) .ToUniTask(progress, cancellationToken: token); return(SceneManager.GetSceneByName(name)); }
/// <summary> /// 加载场景 /// 场景名 /// </summary> /// <param name="sceneName">场景名大小写要和场景名一致</param> /// <param name="isAdditive">是否叠加场景</param> /// <param name="cbProgress">进度回调</param> public void LoadScene(string sceneName, bool isAdditive = false, Action <float> cbProgress = null) { string sceen = sceneName; string assetBundleName = "scene/" + sceneName.ToLower(); if (!assetBundleName.EndsWith(AppSetting.ExtName)) { assetBundleName += AppSetting.ExtName; } #if UNITY_EDITOR if (SimulateAssetBundleInEditor == false) { string[] levelPaths = UnityEditor.AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundleName, sceen); if (levelPaths.Length == 0) { ///@TODO: The error needs to differentiate that an asset bundle name doesn't exist // from that there right scene does not exist in the asset bundle... Debug.LogError("There is no scene with name \"" + sceen + "\" in " + assetBundleName); return; } if (isAdditive) { EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], new LoadSceneParameters(LoadSceneMode.Additive)); } else { EditorSceneManager.LoadSceneAsyncInPlayMode(levelPaths[0], new LoadSceneParameters(LoadSceneMode.Single)); } return; } else #endif { assetBundleName = RemapVariantName(assetBundleName); AssetBundle assetBundle = LoadAssetBundle(assetBundleName); if (assetBundle != null) { SceneManager.LoadSceneAsync(sceen, isAdditive ? LoadSceneMode.Additive : LoadSceneMode.Single); } else { Debug.LogError($"加载场景失败:{sceen} AssetName:{assetBundleName}"); } } }
public IEnumerator LoadAndUnloadScene_SceneThatWasAlreadyLoaded() { var asyncOperation = EditorSceneManager.LoadSceneAsyncInPlayMode(m_TestSceneWithSubScenePath, new LoadSceneParameters(LoadSceneMode.Additive)); yield return(asyncOperation); var scene = EditorSceneManager.GetSceneByPath(m_TestSceneWithSubScenePath); Assert.IsTrue(scene.IsValid(), "GameObject Scene was not valid"); Assert.IsTrue(scene.isLoaded, "GameObject Scene was not loaded"); using (var worldA = TestWorldSetup.CreateEntityWorld("World A", false)) { var sceneSystemA = worldA.GetExistingSystem <SceneSystem>(); Assert.IsTrue(m_TestSceneWithSubSceneGUID.IsValid, "Scene guid is invalid"); var worldAScene = sceneSystemA.LoadSceneAsync(m_TestSceneWithSubSceneGUID, new SceneSystem.LoadParameters { Flags = SceneLoadFlags.LoadAsGOScene }); Assert.IsFalse(sceneSystemA.IsSceneLoaded(worldAScene), "Scene is apparently immediately loaded"); while (!sceneSystemA.IsSceneLoaded(worldAScene)) { worldA.Update(); yield return(null); } var worldAQuery = worldA.EntityManager.CreateEntityQuery(typeof(SharedWithMaterial)); Assert.AreEqual(1, worldAQuery.CalculateEntityCount()); sceneSystemA.UnloadScene(worldAScene); worldA.Update(); while (sceneSystemA.IsSceneLoaded(worldAScene)) { worldA.Update(); yield return(null); } // Unload of entity scenes can take a few frames worldA.Update(); worldA.Update(); Assert.AreEqual(0, worldAQuery.CalculateEntityCount()); Assert.IsFalse(scene.isLoaded, "GameObject Scene was still loaded"); } }
/// <summary> /// 异步加载场景 /// </summary> /// <param name="abName"></param> /// <param name="sceneName"></param> /// <param name="loadCompleted"></param> /// <param name="loadSceneMode"></param> public static void LoadSceneAsync(string abName, string sceneName, Action <AsyncOperation> loadCompleted = null, LoadSceneMode loadSceneMode = LoadSceneMode.Single) { #if UNITY_EDITOR // 是否设置了使用assetbundle资源 if (AssetBundleFramework.DeveloperSetting.GetUseAssetBundleAsset()) { AssetBundleFramework.AssetBundleMgr.Instance.LoadBundle(abName, (succeed, bundleName) => { AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); if (loadCompleted != null) { loadCompleted(operation); } }); } else { // 根据包名获取资源路径,因为后缀名可能不一样所以获取的是数组 string[] paths = AssetDatabase.GetAssetPathsFromAssetBundle(abName); if (paths.Length == 0) { Debug.LogError("AB包路径有误:" + abName); if (loadCompleted != null) { loadCompleted(null); } return; } LoadSceneParameters param = new LoadSceneParameters(loadSceneMode); AsyncOperation operation = EditorSceneManager.LoadSceneAsyncInPlayMode(paths[0], param); if (loadCompleted != null) { loadCompleted(operation); } } #else AssetBundleFramework.AssetBundleMgr.Instance.LoadBundle(abName, (succeed, bundleName) => { AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName, loadSceneMode); if (loadCompleted != null) { loadCompleted(operation); } }); #endif }
protected override void OnLoad() { #if UNITY_EDITOR if (DLCConfig.Ins.IsEditorMode) { asyncOperation = EditorSceneManager.LoadSceneAsyncInPlayMode(assetFullPath, new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.None)); // UnityEditor.EditorApplication.LoadLevelAdditiveAsyncInPlayMode(assetFullPath); loadState = LoadStateType.Loading; loadCount = 0; return; } #endif { request = DLCAssetMgr.LoadBundle(realBundleName, dlcName, true); loadState = LoadStateType.Loading; loadCount = 0; } }
public void OnClickGetUsername() { if (username.text == "") { redText.text = "Please enter your username!"; } else if (username.text.Contains(" ")) { redText.text = "No spaces please!"; } else { userDataName = username.text; flag = 1; EditorSceneManager.LoadSceneAsyncInPlayMode("Assets/Builder/Scenes/StoryScene.unity", new LoadSceneParameters(LoadSceneMode.Single, LocalPhysicsMode.None)); } }
public IEnumerator LoadSceneAsync_sceneNotInBuild_success() { yield return(EditorSceneManager.LoadSceneAsyncInPlayMode( "Packages/com.nowsprinting.sceneinpackage/Tests/Scenes/SceneInPackage.unity", // Projectウィンドウ上のパス new LoadSceneParameters(LoadSceneMode.Single))); yield return(EditorSceneManager.LoadSceneAsyncInPlayMode( "Packages/com.nowsprinting.sceneinpackage/Tests/Scenes/SceneInPackage2.unity", // Projectウィンドウ上のパス new LoadSceneParameters(LoadSceneMode.Additive))); var cube = GameObject.Find("Cube"); Assert.That(cube, Is.Not.Null); var capsule = GameObject.Find("Capsule"); Assert.That(capsule, Is.Not.Null); }
public IEnumerator SetUp() => UniTask.ToCoroutine(async() => { // load scene await EditorSceneManager.LoadSceneAsyncInPlayMode(ScenePath, new LoadSceneParameters { loadSceneMode = LoadSceneMode.Additive }); Scene scene = SceneManager.GetSceneByPath(ScenePath); SceneManager.SetActiveScene(scene); MonsterPrefab = AssetDatabase.LoadAssetAtPath <NetworkIdentity>(MonsterPath); // load host Server = Object.FindObjectOfType <NetworkServer>(); ServerObjectManager = Object.FindObjectOfType <ServerObjectManager>(); Server.Authenticated.AddListener(conn => ServerObjectManager.SetClientReady(conn)); var started = new UniTaskCompletionSource(); Server.Started.AddListener(() => started.TrySetResult()); // wait 1 frame before Starting server to give time for Unity to call "Start" await UniTask.Yield(); Server.ListenAsync().Forget(); await started.Task; Transport = Object.FindObjectOfType <Transport>(); // connect from a bunch of clients for (int i = 0; i < ClientCount; i++) { await StartClient(i, Transport); } // spawn a bunch of monsters for (int i = 0; i < MonsterCount; i++) { SpawnMonster(i); } while (Object.FindObjectsOfType <MonsterBehavior>().Count() < MonsterCount * (ClientCount + 1)) { await UniTask.Delay(10); } });
public IEnumerator LoadScenes(params string[] scenePaths) { Assert.That(!_hasLoadedScene, "Attempted to load scene twice!"); _hasLoadedScene = true; // Clean up any leftovers from previous test ZenjectTestUtil.DestroyEverythingExceptTestRunner(false); Assert.That(SceneContainers.IsEmpty()); for (var i = 0; i < scenePaths.Length; i++) { var scenePath = scenePaths[i]; Log.Info("Loading scene '{0}' for testing", scenePath); var loader = EditorSceneManager.LoadSceneAsyncInPlayMode(scenePath, new LoadSceneParameters( i == 0 ? LoadSceneMode.Single : LoadSceneMode.Additive )); while (!loader.isDone) { yield return(null); } SceneContext sceneContext = null; // ProjectContext might be null if scene does not have a scene context if (ProjectContext.HasInstance) { var scene = SceneManager.GetSceneByPath(scenePath); sceneContext = ProjectContext.Instance.Container.Resolve <SceneContextRegistry>() .TryGetSceneContextForScene(scene); } _sceneContainers.Add(sceneContext == null ? null : sceneContext.Container); } SceneContainer = _sceneContainers.LastOrDefault(x => x != null); SceneContainer?.Inject(this); }