From e0e9ca94ce5e18d09c25fd352cf5ad2af7fe757f Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 23 Aug 2021 17:53:16 -0500 Subject: [PATCH 01/20] Squashed commit of the following: commit 1e733823da0772d185f21bc11bd2d9c027cddab0 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 19:54:59 2021 -0500 test fix Make sure we deregister when unloading/scene transitioning but not when quitting. commit 02f18928eb296437287c91fdfbce7352ce3268ab Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 19:48:51 2021 -0500 refactor and fix Refactoring some of the test project scripts, fixing an issue in the editor where ScenesInBuild count could become 0 but not populated, slight geometry level tweaks to help prevent corner edge cases, and merging the prefab handler with the prefab pool to reduce code complexity. (really need to merge the prefab pools together) Also some minor tweaks to the random movement when not the owner for temporary adjustment (this needs to become velocity based). commit 1c4eb3013261b3ea3c79145dfc50d6fcb9bba3fe Merge: 018ff78e bf5ddd4b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 18:11:39 2021 -0500 Merge branch 'test/AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit bf5ddd4b057a5e6189ef749de757d138c8aba49b Merge: 961ad0a9 b5afae7b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 18:10:01 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit b5afae7b1fa600eff56640d3a3445a1167e2828b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 17:57:48 2021 -0500 refactor Removes returning bool to determine if NetworkPrefabHandler should destroy an object with Fatih's awesome fixes from PR-1068 https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/pull/1068 commit cf4d249a86ef10921eb8afd386fce8241251a293 Merge: f80e853e 00a0e051 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 17:44:35 2021 -0500 Merge remote-tracking branch 'origin/fix/bad-netobj-dest-fixes' into feat/MTT-820-AdditiveSceneLoading commit f80e853efb297036d7feed5855aafab6c613b3cf Merge: cf06cf02 0db6789a Author: M. Fatih MAR Date: Wed Aug 18 23:00:01 2021 +0100 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 00a0e051165b96d6e19c5aa530a1d72811d9350b Author: M. Fatih MAR Date: Wed Aug 18 22:58:56 2021 +0100 remove obsolete comment commit d2dc3212bf8c4321b2f76b38cc21456718859299 Author: M. Fatih MAR Date: Wed Aug 18 22:53:19 2021 +0100 fix: eliminate bad use-after-free(destroy) pattern commit cf06cf02b2ce89ff3311c12586ce8a14ea3850f1 Merge: 3f76dc18 8e9900b5 Author: M. Fatih MAR Date: Wed Aug 18 21:27:09 2021 +0100 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 3f76dc187744744a519e82174400efbf4e493b17 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 14:27:24 2021 -0500 fix unit test Fixing the change in exception thrown when trying to call NetworkSceneManager.Load or NetworkSceneManager.Unload without having set NetworkConfig.EnableSceneManagement. commit 6aaaa5499ef3e5662f612637fb733c1bcdcebdba Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 14:21:30 2021 -0500 fix Fixing committed suggested change bug. commit a1f5ae3c532cc94ef1ba628bb13d8cd1b403ce3f Merge: 4f71b1c2 db097ee1 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 14:15:59 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' of https://github.com/Unity-Technologies/com.unity.netcode.gameobjects into feat/MTT-820-AdditiveSceneLoading commit 4f71b1c2ec24c033ec909a130911b8ea750c95af Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 14:15:34 2021 -0500 test fix Fixing an issue that can occur in a testproject helper script where the wrong scene could be applied to the wrong "toggler" when loaded. commit db097ee10db1029ffd17dadac0bfa28f4de060d6 Author: Noel Stephens Date: Wed Aug 18 13:57:35 2021 -0500 Update Applying Fatih's super-nit. Co-authored-by: M. Fatih MAR commit 018ff78ecf9b59e9392df159a7cda0f0f89d3144 Merge: 709b2154 961ad0a9 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 13:00:41 2021 -0500 Merge branch 'test/AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 961ad0a9ca77d4979d0f24541018131bf6a39065 Merge: 93051e3a 8acb31cc Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 12:58:42 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 8acb31cc8f9d7ef45d168d14321d024345661f5f Merge: 75817ed5 43d4494c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 12:55:58 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 75817ed5c1168596b4989436e7a338b605eceed8 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 12:55:48 2021 -0500 refactor and style Removing a check that is no longer needed. Improved an exception message. Improved some comments. Removed a CR commit 39005dd31bc0f7ad98d423655e75509ea11096d8 Author: M. Fatih MAR Date: Wed Aug 18 14:06:54 2021 +0100 `./standards.py --fix` commit 27d8f50699718261856f87b874762bc217fdc171 Author: M. Fatih MAR Date: Wed Aug 18 14:00:47 2021 +0100 minor editor UI polish commit 709b215407405fc29eed202997f3866f0fcd2076 Merge: d7f1f67d a5f0a795 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 07:06:23 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 93051e3af782802bf9ac23f59d1a9d943103e969 Merge: 3a490018 a5f0a795 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 07:05:12 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit a5f0a795076155718b0fde587e38785207a505c1 Merge: cc83d1cc 19e6d3ca Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 18 07:02:37 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit cc83d1ccfb47082a0c385442ba9297b95022b3d3 Merge: 536a8e5c d30f6170 Author: M. Fatih MAR Date: Wed Aug 18 12:48:11 2021 +0100 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit d7f1f67dbbccd6a632179e2e8ad9ca5c902806b4 Merge: 610c2ec4 536a8e5c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 18:10:05 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 3a4900184e84e05fd800de8edf83f6989b25357d Merge: e7813baf 536a8e5c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 18:09:48 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 536a8e5c4b19a69037f88f046434e789a8ebe135 Merge: ecc1083d e89f05db Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 18:09:23 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 610c2ec447c8d23e6018a274813642ec34dfca09 Merge: fe51176e ecc1083d Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 18:07:00 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit e7813baf7709be9b005ece115dbe7aa0cc68ec59 Merge: b2d5a0f6 ecc1083d Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 18:06:41 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit ecc1083d7ff00de3bcd565776eb11be708509e1b Merge: 831c3a3b 85f84fbc Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 18:05:50 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 831c3a3b2480a3391b4acff76b39d5805c46cc6a Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 17:52:47 2021 -0500 style Adding additional comment to further clarify usage of a multidimensional dictionary commit 747f1f73711d2cd07bf172f6da2b7fd80cbe3180 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 17:49:43 2021 -0500 refactor removing unused m_ObservedObjects. commit fe51176ecc5a0257f666f9170e04a95b23212ce7 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 16:05:40 2021 -0500 fix This fixes the scenario where you open a scene in the editor that does not have a NetworkManager instance (i.e. MainMenu in testproject) and then while still in play mode navigate to a scene that does have a NetworkManager instance, then (editor only) the ScenesInBuild asset will be created (if one doesn't exist), refreshed/repopulated, and assigned to the NetworkManager instance. commit 8bef1fc92e6e5af6f6c1b91db73f6dcc4accfd2f Merge: a644105c 7f559f5a Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 14:31:34 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit b2d5a0f60e9b46060a11ec931c6fa5800fb3658b Merge: 19ba7ae5 7f559f5a Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 14:31:13 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 7f559f5afa6cd0868fb602cd6e1f21261c61dc7e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 14:29:52 2021 -0500 stle Renamed NotifyPlayerConnected to ApprovedPlayerSpawn commit a644105c6d9e073d3b839bcb5c783a1864a3132c Merge: 8afc9f3e 1b421007 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 12:19:15 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 19ba7ae5eaa47c4dbd16e7dea6162cf6ead43450 Merge: 715b73bc 1b421007 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 12:15:30 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 1b42100741c8a1aba6ef5d45b51a0359b50ccd71 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 12:14:52 2021 -0500 fix Minor stats display issue with another sneaky resources meta file that somehow made it into a previous commit. commit 670166b4da352ef054f0e9c44d93ac9722417add Merge: 581adfa0 24cebfb2 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 12:09:28 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 8afc9f3e2c44953f0d4c518ecdbb7309ab70cd53 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 11:56:20 2021 -0500 fix Reverting tail end of MultiInstance test NetworkObject destruction to Destroy and not DestroyImmediate (some might be in the process of being destroyed which can cause an exception after unit test is done). commit c3c482ac0511d28a85f99c9f43351f192181a330 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 11:48:45 2021 -0500 refactor removing Resources.meta file that was accidently added in previous commit. commit cb180d4e0505aeac876a35cb53fe54cd7807f504 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 17 11:43:35 2021 -0500 fix Applying some fixes from the PR-955 merged changes. Adding some additional fixes that avoid loading scenes on the client side during multiInstance unit tests. commit 581adfa0401b87c80969a62eb49fe6c21436a8cc Author: Noel Stephens Date: Tue Aug 17 08:41:47 2021 -0500 Update com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs Co-authored-by: Luke Stampfli <43687322+LukeStampfli@users.noreply.github.com> commit 237dd02d4baf29a23570ce4fcb8d891296c37570 Merge: b7fa2386 715b73bc Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 16 13:56:53 2021 -0500 Merge branch 'test/AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 715b73bc933e71d65b68eb15dc04a5669c885012 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 16 13:36:44 2021 -0500 refactor Refactoring unit test for most recent NetworkSeneManager updates. commit 497670bc012550a01c185bee719c6b125bf4733c Merge: d3b9a202 d1902c8c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 16 12:50:39 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit d1902c8c46fd2f6cdef0ef697af30b97a6c74fb0 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 16 09:21:00 2021 -0500 test updating test projects build settings scenes in build list with new scene to work with additive scene manual testing levels commit 51198d547f980caaac12cf3692f5ee6c1d943cf4 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 20:41:30 2021 -0500 style updated comments and added some xml doc see refs. commit 1130fe1e804cc1cd3a18ea6c7c1430ca19d5f576 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 19:14:34 2021 -0500 Test For real, this is my last fix test and then I will ask Tools team about the issues involved in trying to debug their tests locally. commit 1618a13afaca2c6e00b3337f697855c03fa7fdae Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 18:31:13 2021 -0500 fix test Last try of the day... just delete every NetworkObject that exists when we start a mutli-instance test. commit 84c513a7732ed11e3a1219940362a4e89488e163 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 17:19:33 2021 -0500 fix Removing my tools fix as that was the wrong place to fix that issues. The error causing issue actually came before those two tests where something was being instantiated but never destroyed. If this fails then I might need to do the same thing with the Setup side of things as well. commit 2e1ce677f60b79ba018f29a654a2d372f340a4f7 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 16:54:29 2021 -0500 fix Fixing some tools unit test related issues. commit 2485c89ca0d7a5b521c6015dad8ee1149aa99ae7 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 16:19:10 2021 -0500 fix and style removed the unused namespace from NetworkPrefabHandlerTests commit 20874b406ba000e052c09ec5065482ef71a002a8 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 16:16:11 2021 -0500 fix Fixing minor issue with the standard NetworkPrefabPool (really need to merge these two classes) where it wasn't removing the registration from NetworkPrefabHandler when a scene was unloaded (only in the traditional SceneTransitioningTest without additive scene loading). commit 7fd53e62462b86a5badb7f524d1f11835a6cbe8e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 15:25:15 2021 -0500 Fix Lots of fixes with the new requirements. We will need to come up with a better way to instantiate NetworkObjects for unit tests, but this includes all of the fixes required to get all current unit tests working again. commit 1c12d7c11d6e4f66588a441494777e23e81007be Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 15 14:02:08 2021 -0500 refactor and feat This includes several updates: We now load all scenes first and then we synchronize all NetworkObjects after all scenes have loaded (during the client synchronization process). This means users no longer have to register any form of dependency with NetworkObjects. This includes the additional modifications to support loading the same additive scene (within scene placed NetworkObjects) multiple times. This did require a bit of refactoring and some improvements in how we organize our InScenePlacedObjects. The SceneTransitioningAdditive manual tests (SceneTransitioningBase1 is root scene) include demonstration of loading/unloading the same additive scene repeatedly. commit b7fa2386f41602b161e1e6a7f2fe91f684a24b75 Merge: 8ba63115 0d074688 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 13 11:37:02 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit d3b9a20239d5cff6d4cf33cf0367810c5b8ccc1e Merge: fdb9caa4 0d074688 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 13 11:36:02 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 0d07468841474fae1bc99b6fab4d7268b6dd8cdd Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 13 11:35:44 2021 -0500 style removing MLAPI from sceneIndex commit 8ba63115f48d954601bc34210aa9770cc81ee377 Merge: 0af58abb 2a8ea862 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 13 09:26:27 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit fdb9caa4245e01fa841074909ca3482f1eb23197 Merge: b438aa31 2a8ea862 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 13 09:26:15 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 2a8ea86295bd13d56196855ff49baac3922d378c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 13 09:25:52 2021 -0500 refactor Assigning the TargetClientId for NetworkVariable writing. This could change with the snapshot stuff and the up-and-coming change in read/write permissions, but for the time being making sure this is set only for S2C_Sync events. commit 0af58abb20012b257b2993fad4c4128a72ba8c66 Merge: 9cdb5d66 36e89c25 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 17:25:24 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit b438aa31d33f45f6111b37c69d5245e4e00e063f Merge: 7e7c1735 36e89c25 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 17:25:06 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 36e89c25228067ee87dd93a8d9e5ff821251baf8 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 17:24:52 2021 -0500 style Added or updated some comments for better clarity. commit 9cdb5d6650093fd57904ab5f109cc3ab5764209f Merge: a30592ab def25430 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 17:06:26 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 7e7c1735b0b67c3f9025636755f00f0944bc1206 Merge: bc9598b3 def25430 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 17:06:08 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit def254305d196105df8ce997a9aff1a007cc51e7 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 17:05:46 2021 -0500 style removing the TODO and my initials from MTT-860 comments and providing a bit more of an explanation commit a30592ab1ae3edc8df7d0b7e761ceb4bb2c1bdc6 Merge: 44590cde e5a98164 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 15:55:24 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit bc9598b3d6ca69075de11fd1916423953fd381c5 Merge: 49a4d492 e5a98164 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 15:54:59 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit e5a9816443042c90b22ef39c42d613c0964975e9 Merge: 68789d99 5deae108 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 15:54:42 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 44590cde9d9e6fd44a54a69f676d4297191f39da Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 15:05:46 2021 -0500 fix Manual Test Fix: AdditiveSceneToggleHandler needed to check for SceneFailedVerification status, otherwise it would fail to exit the coroutine but never finish its change in state. commit a803802368e8d60ca2c0995a2a18bb6b7fddacfc Merge: 1fc19dbe 68789d99 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 10:21:03 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 49a4d49234cc8a12484db7a6856f375c4726d16e Merge: 4df10130 68789d99 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 10:16:13 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 68789d99042c8cb144510efa807c8aac451867e0 Merge: 3a7a0e4e 6b58eeb0 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 12 10:07:12 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 1fc19dbeacbcd86c3ccd51ef7e2a946d0f04cbf3 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 11 17:26:01 2021 -0500 update Forgot to move the number of clients back up to 9. commit 0500c3ff7aa8174aed20e3f86f24e1bbd39faf38 Merge: 9a7208d6 3a7a0e4e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 11 17:03:26 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 4df10130abaed35af44890bc2fecf76aed40531d Merge: 2a279af5 3a7a0e4e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 11 17:02:44 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 3a7a0e4ec6c9d470d45c442d43f84ea4372ba87a Merge: f4778085 87f9ec96 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 11 17:02:25 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 9a7208d6c6327d213ae2edaa90d7b713c3b85cfb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 11 16:51:54 2021 -0500 refactor fix and test Removed the client event notification as it wasn't needed. Fixed a minor bug in scene validation that was discovered via the unit test. Added another unit test to the NetworkSceneManagerTests that verifies the NetworkSceneManager scene validation process works and that users can control which scenes are loaded (test covers both client and server). Updated and added XML document comments for methods and properties. commit 24b782d3898ac415912342c71c7f8b92e6cac4c9 Merge: 499a6073 f4778085 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 11 09:27:37 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 2a279af51c8ffd7b4fdd25db0cef0964f1849b2f Merge: af243af5 f4778085 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 11 09:27:13 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit f4778085f474fdcd57966ad475fe3b8901f32dbb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 19:53:20 2021 -0500 style added comment commit d3ff2e4c64ad648b9eb8f45afe273567ff321fe3 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 17:57:27 2021 -0500 fix Seconds vs frame count Mac failed. commit 499a6073b71b3a34fdb37f893d70689570c663d2 Merge: af604487 1387b1fa Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 17:20:34 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit af243af56ddc68dbfd26d5cefb320d1aa72c857b Merge: 80e50fff 1387b1fa Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 17:20:08 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 1387b1fa7f046cecaf20ead6c88480602a959095 Merge: d38145ba 589882c0 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 17:19:45 2021 -0500 Merge remote-tracking branch 'origin/develop' into feat/MTT-820-AdditiveSceneLoading commit af6044871e9f83328a3ddb867f646f56333d947c Merge: f96bcd28 d38145ba Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 17:18:03 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 80e50fffb3ff940aa9701d2f6ea65b2fe5e2329e Merge: bb941b6d d38145ba Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 17:17:22 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit d38145bae0ede16a081c63c912b2af0366346336 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 17:16:43 2021 -0500 refactor Removing check for NetworkObject being null in NetworkBehaviourUpdater, this is no longer needed. Removing artifact debug output (testing purposes) that was missed. commit f96bcd28fb63279a96d5a13857dec7c1229c18bb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 16:18:08 2021 -0500 feat and style Added a client side notification for scene verification failure. Added some xml documentation in pertinent places. commit 60fd08318d7245497a5b8d04f5c1a88582a98c76 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 15:05:09 2021 -0500 style One last namespace not being used. commit 99e42f91bb6abc1da95cfe9d16f06c6bd704250c Merge: 1404ca2f 9f1e05fd Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:47:26 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit bb941b6deb3bb28912bfdf42e51a19ed63e059fb Merge: cca47688 9f1e05fd Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:47:06 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 9f1e05fde6b477df6b2919140921d9b05739e22e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:46:53 2021 -0500 refactor Removing the target frame rate check in the SetUp. commit 1404ca2f0eb447527f14d2c6652dca6752177a9d Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:41:49 2021 -0500 style Removed unused namespaces for compliance/standards purposes. commit bed3c30a73e880a27de729c1bdd1fd9d2fe89fb8 Merge: 6559ec97 b9be4739 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:10:14 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit cca476882e569faafd9d6691640fc7f1a2f102a4 Merge: 33b1bd8a b9be4739 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:08:15 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit b9be47391f9068d770abf7f159df38fe46beb493 Merge: 925e02e0 01ad0c21 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:07:46 2021 -0500 Merge remote-tracking branch 'origin/develop' into feat/MTT-820-AdditiveSceneLoading commit 6559ec97153e8fadf8a9fda001cf94f883428cd8 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 14:05:35 2021 -0500 refactor Updated to most recent PR-955 and develop namespace changes. commit 99b6e2b30b94ed2e684914e556caba37a6cfaa8f Merge: 9d8c0b79 33b1bd8a Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 12:15:44 2021 -0500 Merge branch 'test/AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit 33b1bd8a6c99654c868a03f9cdb4688c1e9a3700 Merge: 93a31da3 925e02e0 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 11:20:13 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 925e02e0ac388afc6cc9b2a413027f8fa104aec8 Merge: 79fd5b25 dce2e54d Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 10 11:11:56 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 93a31da3abbfd4c75b0ddc7d44172accc597de26 Merge: 34a6db48 79fd5b25 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 17:09:10 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 79fd5b2519b003c7c2126c2984ef75a5f1e48cc0 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 17:08:36 2021 -0500 refactor reverting timeouts to 5 seconds each. commit 34a6db48cd8a5fd78be866a86fdf253197f7b3d5 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 17:07:07 2021 -0500 refactor Removing the target frame rate, reducing the wait times commit 77f15b54a36fe5e5c1379d1b8b4a58a737a717b6 Merge: 2e7f9b40 0db23c32 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 15:51:30 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 0db23c324ef43d5044555f38b85557258abc7e64 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 15:37:40 2021 -0500 fix Message ordering seemed to have issues with application target frame rate. Checking this and setting it prior to running a test seems to fix the issue with failing on the FixedUpdate side of things. commit 84b4d04d85864d9b4dc9a0d29414b9121f337cfb Merge: 6b9b4c05 40a6aec0 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 15:09:57 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 2e7f9b4096a1846182fbfd92563a050508e3f76e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 13:46:28 2021 -0500 fix Aligning the exception messages for client trying to start Load or Unload scene events. commit b12c168eae6991bba8eb616b4839b642cb1efe3f Merge: b08f5b57 6b9b4c05 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 13:38:11 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit 6b9b4c05a74362a4976806d3ff409a02008bc4bd Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 13:36:42 2021 -0500 fix and style replacing exception message reference to scene switch with scene event. Fixing check for scene not being loaded check in UnloadScene. commit b08f5b5722d2219527d7d4195d412ecac8a31c83 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 9 13:33:31 2021 -0500 test Added the following checks: Loading during an existing scene event in progress returns SceneEventProgressStatus.SceneEventInProgress. Client trying to start a Load scene event throws an exception Client trying to start an Unload scene event throws an exception Unloading a scene that is not loaded returns SceneEventProgressStatus.SceneNotLoaded. Loading a scene that does not exist returns SceneEventProgressStatus.InvalidSceneName. commit a0f6b39e09846c013fa6d218fe537ac44c377725 Merge: 1fe70247 bac7f416 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat Aug 7 09:42:02 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit bac7f416ae29624277984c6d2d1eee07bf4afb77 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat Aug 7 09:41:24 2021 -0500 style and refactor Minor clean up on some comments. Minor refactoring of property and method accessibility. commit 1fe70247b384fefb36a7488a3f9f7966528161aa Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat Aug 7 09:22:03 2021 -0500 style updated comment commit 82d356c485e76b51a70010db921d6d168a448978 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 6 18:43:01 2021 -0500 refactor Removing the no longer used SceneLoadingTest commit 34ec78646a2e50327dd28ed761405336c2215d4c Merge: 06e96f2d adc58d89 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 6 18:41:25 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into test/AdditiveSceneLoading commit adc58d8944458b0ffdd60439f9d115570474aebb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 6 18:11:08 2021 -0500 refactor Removed debug information from SceneEventData. commit 06e96f2d1ebef652c5b5b575cd075548e37db7df Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 6 18:05:59 2021 -0500 refactor Moved code from legacy NetworkSceneManagerTest for assert when trying to load a scene with EnableSceneManagement set to false into the new NetworkSceneManagerTest. Removed the legacy NetworkSceneManagerTests script. commit f1c0b21096468587002162573269b56d363a0995 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 6 17:45:42 2021 -0500 test This is a multi-instance unit test with 1 host and 9 clients. This tests the entire scene event notification sequence for loading and unloading additive scenes. This includes some changes to the new NetworkSceneManager required to do multi-instance unit tests. commit c1d299aac76811154880826b2d366e5b7c483d15 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 6 15:39:29 2021 -0500 refactor Added the ability to disable the re-synchronization for future snapshot development purposes. commit 98354515fe7f0ff83fc9eb70afe757ce99cd0f66 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Aug 6 08:21:03 2021 -0500 refactor Removing two exceptions that will not be needed. commit cfa48e63e63298dfef8aeb7a5139ec471536c35f Merge: 831fd1da d89e2f2f Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 5 19:55:02 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 831fd1da8a9d88cc082abd2ef11ef5de598c4032 Merge: 37be5bc4 8919c1ed Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 5 15:35:46 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 37be5bc455300f633a3fd622e30cded02fa0e8d2 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 5 15:35:31 2021 -0500 style Did one last XML Documentation pass. commit fa2aaaa9396d03421df81423d8297f513febab1f Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 5 14:29:21 2021 -0500 feat Finalized replacing all notification related events with scene events. SceneEvent now includes two additional types: S2C_LoadComplete: Server to client(s) all clients loaded scene S2C_UnLoadComplete: Server to client(s) all clients unloaded scene These replace the event notifications that specified all clients have loaded a specific scene, with the additional functionality that this notification is sent for both loading and unloading for all loading modes. Removed the legacy internal messages and related methods for all clients done loading a scene. This should mark the final overhaul for notifications commit 139edff30404111537efddf47426a36b591e6dfa Merge: 06e8a58a 1da76b29 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Aug 5 10:16:31 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 06e8a58a70441c8548cd40b7f57381dad62c767c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 23:57:43 2021 -0500 feat SwitchSceneProgress changed to SceneEventProgress and is no longer a returned value when starting a scene event (load or unload). This is still used internally to track when all clients have loaded the scene in question, but that is primarily used for SceneLoadingMode.Single. Removed the coroutine callback from NetworkManager and placed it within the SceneEventProgress class. commit a608797972a5f5c09221610b53af9e84b5f940d8 Merge: 8495d1f8 d71dd1b8 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 22:50:53 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 8495d1f85538fff40895fdd6e478c89fb7a2dd61 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 20:03:08 2021 -0500 fix, refactor, and style re-fixing an issue with sending spawn calls to every client (n) times based on the number of clients connected (until it is re-fixed by the offender) Started the removal of certain NetworkSceneManager event notifications that are no longer required due to the more recent SceneEvent notifications. Removed the set active scene scene event for MS-1 (just not enough time to implement and be sure that it works perfectly) Removed a manual test for SceneManager callbacks that won't be used any longer. Updated XML documentation in various areas. commit af56bdd2c4eb348cd19a8a1c04ce65a40bfcf0ad Merge: 6d4d52fa f881d338 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 18:46:54 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 6d4d52fac651e6c1b4824f7d427e514c131d1d37 Merge: 277292e6 95886c59 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 18:28:55 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 277292e690dc8750e54d8be4f7a4faafc82ba6fa Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 18:08:13 2021 -0500 feat Improved notifications and detection of notifications for manual verification that they are triggering properly. Added a SceneEventNotificationQueue test project script that is to be used with the NetworkManager to detect edge case notifications (i.e. in the middle of a scene transition). Fixed an edge case scenario with NetworkObject.Despawn that could occur during exiting the application and the SpawnManager no longer exists. commit 978e8de133dd39692bead7ca23f24b9370e3aaf1 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 16:14:41 2021 -0500 style slightly increased the player prefab size commit c30251b1579182171a25e70051bbc54c2c36d367 Merge: 5cffe56f 5b9f953b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 16:07:47 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 5cffe56f7873507b9674d78bc3c05a55b81b32cb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 16:06:20 2021 -0500 feat Implemented the full scene event notification system that provides detailed information for both client(s) and server. Made some modifications to the StatsDisplay that provides visual queues for when each scene event occurs. commit 69a4751a1590dfe6f5c4d98c2f5f7a7a94153d18 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 12:56:22 2021 -0500 refactor Updates to account for the namespace change...again. commit 6a41cb8ce49f86099bc8fb49bd09ab7ccd333c61 Merge: c31c119c 838c6e5b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 12:51:28 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit c31c119c4e18f1dbdc6f9828648600bfc0011dc7 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 12:33:06 2021 -0500 refactor Removing completely irrelevant code... commit 3f98c0ab0a32c7e27d128babcfefa9cb9c64f218 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Aug 4 12:23:49 2021 -0500 refactor and style Refactored the prefab pool examples for the changed INetworkPrefabInstanceHandler interface. Made some adjustments to the code based on suggestions. In particular added a prefix to the SceneEventData.SceneEventTypes to help identify which is server to client and client to server. commit ea747d3b887a621fde343725d4a61cb7e5deac7d Merge: 5c4de91f f5c51f25 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 20:54:17 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 5c4de91ff5878b18a941dc2b500e3802f95d0f90 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 17:21:25 2021 -0500 style Fixing non-required using statements. commit 3274c561ebfbb12e22c58de4bd7c426d073a6603 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 17:08:13 2021 -0500 refactor and fix Refactoring the Stats Display a bit. Added check for NetworkBehaviour Updater to not try to access the NetworkObject if it is null. This can happen under scenarios where too many objects are being spawned and destroyed at the same time. commit fd90a507320960aadcd094168ccd5c9502d67cc7 Merge: d7822d6c f8a7ef01 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 16:22:50 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit d7822d6cd7d874c029abe07da0f329ffaf77f8a6 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 16:20:50 2021 -0500 fix merge fix. commit d708f5e9a858ce84b1077b8f63340983b107e041 Merge: 22112987 6b78f322 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 16:14:21 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 221129870538e7987348e00052de0268ec19e960 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 15:52:32 2021 -0500 refactor Updating additive pooling with additive scene unloading. Added the ability to specify whether NetworkObjects should be destroyed on scene unload or not. If the SpawnInSourceScene is set to true and the DestroyOnUnload is not set, then the already spawned NetworkObjects are moved to the currently active scene to allow them to persist until they naturally are destroyed. Fixed issues with most objects already destroyed messages. Still have a few that pop up from time to time. Fixed issue with client not sending responses back to server. Refactored NetworkPrefabHandler and INetworkPrefabInstanceHandler so that the destroy method returns a bool value which determines if the NetworkObject should actually be destroyed or not (there are edge case scenarios this fixes). Updated several tests to reflect these changes. commit 77e9e07e9014e8a3816bd9d8d0e37d06c78b35b6 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 10:12:38 2021 -0500 fix temporary fix for scene loading test. commit c9fb565ce54e2fff3b9d9772c249e1bd1bf102a1 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Aug 3 09:19:42 2021 -0500 fix Standards check for no longer needed using statments commit 49a0b3d3528792bf9a2e904f49d1bba1ac9ae0d8 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 2 22:12:07 2021 -0500 fix This includes fixes for the namespace changes. commit 4aa60b2fc8b6c12f285e5d29c9e247036f938ebc Merge: ccd659e3 c8eb5fca Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 2 22:04:05 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit ccd659e3363f4d40e39adeaa0530ffcdb3046a4c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Aug 2 11:36:47 2021 -0500 fix Checking for NetworkManager to exist before disabling. commit c67dc73de9ac0dbf425ff1b94331fbd4708f08b4 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 1 20:26:00 2021 -0500 refactor Work in progress for local notifications, how network prefab handler pools destroy objects, and how NetworkObjects marked for or not marked for do not destroy on load are handled. commit c0da88954bc06e3b9455958061ba134787789d2f Merge: f092e45a cbe74c2e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Aug 1 19:06:59 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit f092e45a056851d2a459b69c01031469368020a2 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 29 17:54:37 2021 -0500 refactor Cleaning up merge from develop. Starting to work on the local notification side of things. commit 67057603f230748166aed262a9f928ddf5009cc2 Merge: d369c1c8 d6b2a486 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 29 14:33:25 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit d369c1c80baba35dd7dee11a5a1078e44db08a91 Merge: 26e94bb2 4b900723 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 29 14:08:13 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 26e94bb23918b0c39eb6cf2ab7343024fb65ab7f Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 28 11:39:43 2021 -0500 test Forgot to remove the applied frame rate. commit 3bb2dc6ff5caf3cc5862a35aae16dfff6012d206 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 28 11:34:25 2021 -0500 test Updating this adjustment to see if this makes it through the mac tests. commit 44365744aae26d95057df01d9db9c43ccfdb85ff Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 19:00:06 2021 -0500 refactor Removing temporary fix for issue with NetworkBuffer. Adding a test to the NetworkTransformTests to see if frame rate has anything to do with the seemingly random failures only on MAC. commit b2157b97fcd723d246a44581417802738cdefd6e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 18:17:27 2021 -0500 refactor Reverted minor modifications to transform test. commit 0aacdfe8ae871ad60788901a8c8c6d514e2e9483 Merge: 039ca2c8 c25821d2 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 18:14:36 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 039ca2c84cf6ff55cacb5f84a04076153066930f Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 16:53:00 2021 -0500 refactor Increasing timeout for one at a time. commit 28eb59ed6c0898db2ce05bb44c6476031f7ea147 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 16:25:36 2021 -0500 refactor removed and re-added scenes in build list commit b65203e04b9d36b04dbb7ae826636150e40de82b Merge: 217748a1 82e1c33e Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 16:24:54 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 217748a1b78281798d2fda6f04609f46dbfd802d Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 16:10:53 2021 -0500 fix Removing some adjustments I did not intend on checking in. commit 28545c3e7aaa6fbe19aea5701455cdecc4e8ae75 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 27 08:07:12 2021 -0500 refactor and fix Refactoring things based on more recent changes. Predominantly the Message Ordering changes and the time synchronization. commit 7b5fb895c4d74dc6c0d1c820c4dd30f8417f3ee2 Merge: a1fdf5bb b9ffc1f1 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Jul 23 18:26:57 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 9d8c0b7992dd0227e526584259dbf55db56f0c97 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 22 15:58:34 2021 -0500 style this comment was left out of last commit. commit 510226d12f1bb06e27a71587f4c7f57904e1b9b9 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 22 15:57:33 2021 -0500 feat and refactor Added ValidateSceneBeforeLoading delegate and method to provide users with a way to validate a scene before it is loaded for security and/or validation purposes. Removed AllowRuntimeSceneChanges Updated some comments commit 444263ebca3ba51bebe0a1f2006e4b273c60baeb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 21 18:49:23 2021 -0500 fix There were two issues: Assets outside of the primary project domain, which I had to put some checks to prevent from populating under specific scenarios (i.e. first time loading test project with no ScenesInBuildList asset). Then with testing I had to bypass these checks so dynamically created NetworkManagers would be assigned the ScenesInBuildList asset automatically. This should fix the later issue and fix previous yamato failed builds. commit 8ccc6d343f51afb44b571aff2c0b9c2e3ceb2654 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 21 16:30:08 2021 -0500 Fix Found a potential issue with having references in a different assembly and/or first time loading the testproject. commit 29c5360fe29651047a936532f56728fe563d9386 Merge: d8eb7e55 a1fdf5bb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 21 16:01:42 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit a1fdf5bb4df736192a9e0e31c9cc684285f6543b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 21 15:59:09 2021 -0500 FIx and Style Fix for client side where during resync the GameObject was being destroyed but the spawn manager's lists tracking spawned NetworkObjects was not being updated. The symptom was when a NetworkObjectId was recycled for a new NetoworkObject the client would still have that NetworkObjectId registered. This also includes some style updates. commit d8eb7e55f06b396eee9f7940d01b2e7c6dcb0ad3 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 21 15:51:52 2021 -0500 Fix Removing re-syncd NetworkObject from spawn manager, this was causing delayed NetworkObjectId assignment issues on the client side. Also, added check to not populate the scenes in build when transitioning into or out of play mode. commit 39313ebd3c3d10f70841afcdc8e961143a2092de Merge: 707c3273 c890f06c Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 21 14:38:43 2021 -0500 Merge branch 'feat/MTT-820-AdditiveSceneLoading' into feat/ScenesInBuildMLAPISceneRegistration commit c890f06ce8cc266b9eb742391ef4bb3045a95c32 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 21 14:38:01 2021 -0500 Refactor and Fix Fixed issue with rogue dynamically spawned NetowrkObjects that were spawned during a client scene synchronization sequence where it required a Custom NetworkPrefab hanler to spawn properly but the scene containing that custom network prefab handler had yet to be loaded so it was never associated with the pool. Migrated the additive scene loading scene transitioning tests into the manual tests region of TestProject commit 707c32738a0f0e088d7d7a7e86874f45b60370d9 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 20 17:45:50 2021 -0500 feat This creates a ScenesInBuild asset if one does not exist as well as populates it with the names of the scenes in the build to keep the same types of checks done within the NetworkSceneManager (i.e. does the scene index exist etc). The ScenesInBuild asset can detect if it is moved around, however it is created in the root assets folder initially. It also updates itself to the scenes in build list via the serialization process. All NetworkManager instances reference this asset. In turn, the NetworkSceneManager access the ScenesInBuild.Scenes list now. Adjusted all unit tests and helpers for this update as well (except multiprocessor). TestRunner passes all tests in editor and play modes. commit e798cc27ee9227c39d5e231c2c2cfdd81d2708ac Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 20 12:29:15 2021 -0500 WIP Work in progress commit 28d9df4c1a0818ce1d7e6529780024c1ed604c6c Merge: 55ffbd3b fa2be6f1 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 20 08:59:06 2021 -0500 Merge remote-tracking branch 'origin/develop' into feat/MTT-820-AdditiveSceneLoading commit 55ffbd3b48cccba178e2a72e1a3d9f3bbf21a188 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 20 08:58:41 2021 -0500 style comments and naming commit 9ac6a86ed982de93044347c116e45db94f7ebc58 Merge: e16628cf bdd7d714 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 15 17:21:03 2021 -0500 Merge remote-tracking branch 'origin/develop' into feat/MTT-820-AdditiveSceneLoading commit e16628cf7886f1810d0d2e887b49cb05bfd25846 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 15 17:18:20 2021 -0500 refactor and feat Did some minor refactoring to make Load and Unload the only two methods that need to be called. Removed the switch event related enum types since they are no longer used. Added a re-synchronization step to handle edge case scenarios where a late joining client might miss destroy messages during the initial synchronization process. This includes adding an additional DependentSceneName property to NetworkObject. This lets the NetworkSceneManager know that a scene other than the NetworkObject's current scene is dependent upon this NetworkObject and to not instantiate it until that dependent scene is loaded. Removed a bunch of user-side code (i.e. test project) from GenericNetworkObject that was required to handle the above edge case scenarios regarding scene dependencies. Adjusted the NetworkPrefabPool and NetworkPrefabPoolAdditive to account for this addition, and removed a chunk of user-side code that would be required to handle this scenario. Refactored SceneEventData to not implement INetworkSerializable which removes additional allocation for the NetworkSerializer during read and write operations. Also adjusted the constructor to accept a NetworkManager instance to make it multi-instance compatible. Set the SceneTransitioningBase1 NetworkManager config to not recycle NetworkObjectIds due to an issue in how they are recycled. (topic for discussion) commit c686eee1e9bc207d4f5b251406a59da34cb16b2f Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 14 16:41:19 2021 -0500 fix Removing Scene Loading Test: This test needs to be completely refactored and no longer is valid. WIP commit 4bcd93154defca41b6f7d77900aa47957b3a8b61 Merge: d1670b79 13e2b7f1 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 14 15:57:48 2021 -0500 Merge remote-tracking branch 'origin/develop' into feat/MTT-820-AdditiveSceneLoading commit d1670b79f9bb4b27c561d84452369ff96a9445cc Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 14 15:45:20 2021 -0500 refactor and fix Minor test project fixes and additional tests for the AdditiveSceneToggleHandler to test back to back scene loading during a scene transition. Removed the distinguishing difference between switchscene and loadscene, left the switchscene as a wrapper around loadscene. Updated existing profiling code base to remove legacy scene manager profiler checks. commit 3a7a0e9ccd1de3d74f1616a042dc6533000adade Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 17:02:02 2021 -0500 style PascalCased my enums and added event in front to avoid any NDA complications for the time being. commit d7846f82def8d9bfe2d1757fdd025569fbc6d017 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 16:33:06 2021 -0500 fix Adding missing scene assets for the multiprocess test. Making sure the SceneLoading test destroys the network manager instance. commit d8828190dd12983d0282bda55d7b7d5bdc158db9 Merge: a5c3bf84 089c2065 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 15:42:50 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit a5c3bf845c4be027869c870361a9b03b672f7c91 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 15:41:11 2021 -0500 fix Two issues were discovered while getting the parenting test working: 1.) t was doing a move objects to scene during the client side synchronization process (which doesn't need to happen) and as such was setting all parents to null which was throwing an exception. 2.) The server side wasn't filtering out any pre-loaded scenes during the synchronization process. commit 35a46b746ce85aea925148717ec2681eb6283ed6 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 13:15:59 2021 -0500 fix Fixing other unit test issues. Removing the temporary block for clients to receive messages (it was an artifact from testing). Still have a few tests that are failing. commit 729a2ce09aef653fdc5371f9437333b796d62a72 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 12:02:53 2021 -0500 fix Fixes the basic scene transitioning test failure. commit ef7736903aad357db46ec7133f148e16754f04a4 Merge: 5d10e276 833f1faf Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 09:55:26 2021 -0500 Merge branch 'develop' into feat/MTT-820-AdditiveSceneLoading commit 5d10e276e8e6ef54e87876d6df9494d09c968fa2 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon Jul 12 09:21:19 2021 -0500 refactor Minor checks for an object still being around during clean up. commit df9bc79286977e56c04890d80bf0c8bec913e72b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Jul 11 21:24:49 2021 -0500 feat and refactor Some temporary fixes for message ordering and buffering during late-join until this gets merged with the message ordering updates and we add the ability to buffer messages while a player is late-joining. Primarily in the GenericNetworkObjectBehaviour class. Added a proposed solution to handle order of operations if user decides to allow all NetworkObjects from a prefab pool to be spawned in the active scene. This requires the ability to separate NetworkObjects (server side) by associated scene so that they will be synchronized properly with their spawn generator's pool. Now tracking which additive scenes have been loaded to be assured they are unloaded when doing a full scene switch (i.e. singlemode loading), otherwise there can be issues that arise with currently loaded additive scenes. commit 88617d2e56586e63917936fc8216ce45e1862f8a Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sun Jul 11 15:06:37 2021 -0500 feat Improved the NetworkPrefabPool and NetworkPrefabPoolAdditive implementations to properly handle the various potential use case scenarios. These changes assure that both the client and the server leverage from the pool. This also takes into account NetworkManager defined NetworkPrefab overrides. Added temporary LoadSceneEvent callback that notifies if an additive scene is being loaded or unloaded. Updated the NetworkPrefabPoolAdditive sample to demonstrate how a user can assure their NetworkObjects are "spawned" in the same additive scene as their spawn generator. This pattern will always destroy all NetworkObjects if the additive scene is unloaded. Added sorting of NetworkObjects just prior to the server side serializing them in order to assure INetworkPrefabInstanceHandler implementations are registered first, this is required in order to assure that the handler is registered before any NetworkObjects associated with it are spawned. commit d41b8d37d88949a111428616c9b189578b0bcada Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat Jul 10 17:19:28 2021 -0500 refactor Removed static properties in NetworkSceneManager that were no longer being used. Fixed issue with host not having the proper network prefab override (i.e. running as host vs running as server). Moved SceneEventData into its own .cs file. Excluding the local notification events, this is very close to being finalized, with the exception of custom prefab overrides and additive scene loading. This still has issues with late joining (most likely this has to do with the NetworkPrefabPool code base, still investigating this issue). commit de0012ece6d41156a28774dbe5ce104c54a1534d Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Jul 9 19:00:24 2021 -0500 feat Joining with additive scenes already loaded as well as late joining players are synchronizing properly. The handle approval process is no longer directly tied to scene loading. Minor updates to stats display to show the currently active scene commit bda84f3c9c657039a303cfaf8ad85c1729c11c1d Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Jul 9 14:48:00 2021 -0500 wip Closer to decoupling approval from the approval process. There are still some issues with regards to the active scene and this could potentially be fixed by doing client synchronization first and then finalizing the approval. Fixed an issue with NetworkManager replicating upon exiting. commit cafdc9d5710980c9b9cd743078608db72443dc55 Merge: ec62ae50 69b43dc2 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Jul 9 12:17:41 2021 -0500 Merge branch 'experimental/additivescenes' into experimental/late-join-additivescenes commit 69b43dc236696cfb76e700425dcf548785f3a78b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Jul 9 12:16:04 2021 -0500 refactor naming issue and making sure we scope the pooled network reader. commit ec62ae50e86c57951fcbebf076af1773268185d1 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri Jul 9 10:18:04 2021 -0500 wip A wip commit that is progress towards removing scene and object synchronization from the approval process. commit cdc6a5057c61403108a486ce76f8002b6a2d93d7 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 7 15:44:32 2021 -0500 feat This includes new assets to demonstrate additive scene loading and scene switching. Known issues are when additive scenes have been loaded that they are not synchronized with clients when they join. commit 9f2c6f41ea767953ff5498b592c595c53ead0d58 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 7 15:08:32 2021 -0500 refactor Swapped out the switch scene cycle hack for actual toggle buttons that allow one to load each sample additive scene or unload it based on the state of the toggle button. commit 4c8a822c8a1e4961dd937df5d0fd189692422a8b Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Wed Jul 7 13:51:47 2021 -0500 refactor and feat Added additive scene unloading into the mix. Currently no events are wired for additive loading complete or additive unloading complete, but console logging on the server side verifies that the client sends the appropriate scene event notification once finished loading or unloading. Cleaned up some of the test project code to make sure the client isn't creating a pool to make sure the client is only replicating what the server is telling it to as well as various other minor test project tweaks for additive scene loading demonstration purposes. commit c4138b01dd4531e0eaf90bcf17991e5eab360442 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 6 18:13:21 2021 -0500 style Just comment and style adjustments commit 969123a98c25f35cfcfc35c7850a91822fea4ac3 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 6 18:08:47 2021 -0500 refactor Just cleaning up the code, putting place holder notes, and adding some comments commit 728764a352a5cd686b2576a364e9d67abbb1e1cd Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 6 17:48:47 2021 -0500 refactor Created the LoadScene method which will only load scenes additively. Broke up some of the commonly shared initializations and checks. This helps to show what the real differences between single and additive scene loading are. (like two method calls) commit 7f228a33f619a427fd8637c9c5c1bee65b13e7b9 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue Jul 6 17:07:01 2021 -0500 feat Added new SCENE_EVENT that will handle "all things scene relative" with the only exception of the approval process. That will need to be handled in a different PR as that requires a bunch of additional changes. Focus for this branch is to get additive scene loading and unloading working. commit 19bd9c3ca99ac9e2e498777feb9f8e76b22388eb Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat Jul 3 16:27:53 2021 -0500 refactor - wip Adjusting scene related commands. Keeping the original commands in place, but providing two new commands: SCENE_EVENT: This will contain sub-commands and additional information specific to the command. SCENE_NOTIFICATION: This is more for providing a mechanism to send various notifications (i.e. scene switch complete, scene loaded, scene unloaded, errors, etc) with the ability to include additional information about the event. commit 000319b86b0a4dd0c1c9079ac25c13d8f45e4dd6 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat Jul 3 16:12:47 2021 -0500 refactor Removing the automatic addition of a scene asset to NetworkConfig. This has been a problematic approach to assuring the scene containing the NetworkManager is included. commit 8f7227bf707e0c99a37ab4cb395d40c09d25e7ca Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Sat Jul 3 16:03:07 2021 -0500 refator Updating basic scene registration to accept SceneAssets as opposed to string based names. commit 039e4ab39ad22a0509f18d5d5dff6a15d86efb05 Author: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Thu Jul 1 17:47:48 2021 -0500 feat This is a quick and dirty additive scene loading implementation example with minimal changes to the develop branch. --- .../Editor/NetworkManagerEditor.cs | 38 +-- .../Runtime/Configuration/NetworkConfig.cs | 50 ---- .../Runtime/Core/NetworkManager.cs | 64 +++-- .../Runtime/Core/NetworkObject.cs | 6 +- .../SceneManagement/SceneEventProgress.cs | 6 +- .../Runtime/SceneManagement/ScenesInBuild.cs | 97 ++++++++ .../SceneManagement/ScenesInBuild.cs.meta | 15 ++ ...NetworkManagerCustomMessageManagerTests.cs | 13 +- .../NetworkManagerMessageHandlerTests.cs | 14 +- .../Editor/NetworkManagerSceneManagerTests.cs | 14 +- .../Tests/Runtime/BaseMultiInstanceTest.cs | 3 +- .../Tests/Runtime/ConnectionApproval.cs | 1 + .../NetworkPrefabGlobalObjectIdHashTests.cs | 2 + .../Runtime/Helpers/NetworkManagerHelper.cs | 11 +- .../Tests/Runtime/MultiInstanceHelpers.cs | 22 +- .../NetworkObjectOnSpawnTests.cs | 3 +- .../NetworkObjectSceneSerializationTests.cs | 3 +- .../NetworkObjectParentingTests.cs | 12 + .../Assets/Prefabs/SceneLevelGeometry.prefab | 196 ++++++++++++++- .../PrefabPoolOverrideExample.unity | 19 +- .../AdditiveSceneMultiInstance.unity | 224 +++++++++++++++++- .../AdditiveSceneToggleHandler.cs | 87 +++++-- .../SceneTransitioningBase1.unity | 40 ++++ .../Manual/Scripts/IndependentMover.cs.meta | 4 + .../Tests/Manual/Scripts/NetworkPrefabPool.cs | 55 +++-- .../Scripts/NetworkPrefabPoolAdditive.cs | 37 +-- .../Tests/Manual/Scripts/RandomMovement.cs | 6 +- .../Assets/Tests/Runtime/MessageOrdering.cs | 1 - .../Runtime/MultiClientConnectionApproval.cs | 2 + .../Tests/Runtime/NetworkSceneManagerTests.cs | 136 ++++++++++- .../Runtime/NetworkSceneManagerTests.cs.meta | 2 +- 31 files changed, 917 insertions(+), 266 deletions(-) create mode 100644 com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs create mode 100644 com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta diff --git a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs index 563a2eeabd..0f6f162c70 100644 --- a/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs +++ b/com.unity.netcode.gameobjects/Editor/NetworkManagerEditor.cs @@ -21,7 +21,6 @@ public class NetworkManagerEditor : UnityEditor.Editor // NetworkConfig fields private SerializedProperty m_PlayerPrefabProperty; private SerializedProperty m_ProtocolVersionProperty; - private SerializedProperty m_AllowRuntimeSceneChangesProperty; private SerializedProperty m_NetworkTransportProperty; private SerializedProperty m_TickRateProperty; private SerializedProperty m_MaxObjectUpdatesPerTickProperty; @@ -37,7 +36,6 @@ public class NetworkManagerEditor : UnityEditor.Editor private SerializedProperty m_LoadSceneTimeOutProperty; private ReorderableList m_NetworkPrefabsList; - private ReorderableList m_RegisteredSceneAssetsList; private NetworkManager m_NetworkManager; private bool m_Initialized; @@ -91,8 +89,7 @@ private void Initialize() // NetworkConfig properties m_PlayerPrefabProperty = m_NetworkConfigProperty.FindPropertyRelative(nameof(NetworkConfig.PlayerPrefab)); - m_ProtocolVersionProperty = m_NetworkConfigProperty.FindPropertyRelative("ProtocolVersion"); - m_AllowRuntimeSceneChangesProperty = m_NetworkConfigProperty.FindPropertyRelative("AllowRuntimeSceneChanges"); + m_ProtocolVersionProperty = m_NetworkConfigProperty.FindPropertyRelative("ProtocolVersion"); m_NetworkTransportProperty = m_NetworkConfigProperty.FindPropertyRelative("NetworkTransport"); m_TickRateProperty = m_NetworkConfigProperty.FindPropertyRelative("TickRate"); m_ClientConnectionBufferTimeoutProperty = m_NetworkConfigProperty.FindPropertyRelative("ClientConnectionBufferTimeout"); @@ -121,7 +118,6 @@ private void CheckNullProperties() // NetworkConfig properties m_PlayerPrefabProperty = m_NetworkConfigProperty.FindPropertyRelative(nameof(NetworkConfig.PlayerPrefab)); m_ProtocolVersionProperty = m_NetworkConfigProperty.FindPropertyRelative("ProtocolVersion"); - m_AllowRuntimeSceneChangesProperty = m_NetworkConfigProperty.FindPropertyRelative("AllowRuntimeSceneChanges"); m_NetworkTransportProperty = m_NetworkConfigProperty.FindPropertyRelative("NetworkTransport"); m_TickRateProperty = m_NetworkConfigProperty.FindPropertyRelative("TickRate"); m_ClientConnectionBufferTimeoutProperty = m_NetworkConfigProperty.FindPropertyRelative("ClientConnectionBufferTimeout"); @@ -200,30 +196,6 @@ private void OnEnable() } }; m_NetworkPrefabsList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "NetworkPrefabs"); - - m_RegisteredSceneAssetsList = new ReorderableList(serializedObject, serializedObject.FindProperty(nameof(NetworkManager.NetworkConfig)).FindPropertyRelative(nameof(NetworkConfig.RegisteredSceneAssets)), true, true, true, true); - m_RegisteredSceneAssetsList.elementHeightCallback = index => - { - return EditorGUIUtility.singleLineHeight + 8; - }; - m_RegisteredSceneAssetsList.drawElementCallback = (rect, index, isActive, isFocused) => - { - rect.y += 5; - - var sceneAsset = m_RegisteredSceneAssetsList.serializedProperty.GetArrayElementAtIndex(index); - int firstLabelWidth = 24; - int padding = 2; - - EditorGUI.LabelField(new Rect(rect.x, rect.y, firstLabelWidth, EditorGUIUtility.singleLineHeight), index.ToString()); - EditorGUI.PropertyField(new Rect(rect.x + firstLabelWidth, rect.y, rect.width - firstLabelWidth - padding, EditorGUIUtility.singleLineHeight), sceneAsset, GUIContent.none); - }; - - m_RegisteredSceneAssetsList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, "NetworkScenes"); - - m_RegisteredSceneAssetsList.onAddCallback = (registeredList) => - { - m_NetworkManager.NetworkConfig.RegisteredSceneAssets.Add(null); - }; } public override void OnInspectorGUI() @@ -257,13 +229,6 @@ public override void OnInspectorGUI() m_NetworkPrefabsList.DoLayoutList(); EditorGUILayout.Space(); - using (new EditorGUI.DisabledScope(!m_NetworkManager.NetworkConfig.EnableSceneManagement)) - { - m_RegisteredSceneAssetsList.DoLayoutList(); - EditorGUILayout.Space(); - } - - EditorGUILayout.LabelField("General", EditorStyles.boldLabel); EditorGUILayout.PropertyField(m_ProtocolVersionProperty); @@ -330,7 +295,6 @@ public override void OnInspectorGUI() using (new EditorGUI.DisabledScope(!m_NetworkManager.NetworkConfig.EnableSceneManagement)) { EditorGUILayout.PropertyField(m_LoadSceneTimeOutProperty); - EditorGUILayout.PropertyField(m_AllowRuntimeSceneChangesProperty); } serializedObject.ApplyModifiedProperties(); diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs index 28567c0725..336a67f150 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs @@ -26,25 +26,6 @@ public class NetworkConfig [Tooltip("The NetworkTransport to use")] public NetworkTransport NetworkTransport = null; - /// - /// The list of SceneNames built from the RegisteredSceneAssets list - /// - [HideInInspector] - public List RegisteredScenes = new List(); - -#if UNITY_EDITOR - [Tooltip("The Scenes that can be switched to by the server")] - public List RegisteredSceneAssets = new List(); -#endif - - /// - /// Whether or not runtime scene changes should be allowed and expected. - /// If this is true, clients with different initial configurations will not work together. - /// - [Tooltip("Whether or not runtime scene changes should be allowed and expected.\n " + - "If this is true, clients with different initial configurations will not work together.")] - public bool AllowRuntimeSceneChanges = false; - /// /// The default player prefab /// @@ -173,12 +154,6 @@ public class NetworkConfig public const int RttAverageSamples = 5; // number of RTT to keep an average of (plus one) public const int RttWindowSize = 64; // number of slots to use for RTT computations (max number of in-flight packets) - - private void Sort() - { - RegisteredScenes.Sort(StringComparer.Ordinal); - } - /// /// Returns a base64 encoded version of the configuration /// @@ -190,13 +165,6 @@ public string ToBase64() using (var writer = PooledNetworkWriter.Get(buffer)) { writer.WriteUInt16Packed(config.ProtocolVersion); - writer.WriteUInt16Packed((ushort)config.RegisteredScenes.Count); - - for (int i = 0; i < config.RegisteredScenes.Count; i++) - { - writer.WriteString(config.RegisteredScenes[i]); - } - writer.WriteInt32Packed(config.TickRate); writer.WriteInt32Packed(config.ClientConnectionBufferTimeout); writer.WriteBool(config.ConnectionApproval); @@ -209,7 +177,6 @@ public string ToBase64() writer.WriteBool(RecycleNetworkIds); writer.WriteSinglePacked(NetworkIdRecycleDelay); writer.WriteBool(EnableNetworkVariable); - writer.WriteBool(AllowRuntimeSceneChanges); writer.WriteBool(EnableNetworkLogs); buffer.PadBuffer(); @@ -231,12 +198,6 @@ public void FromBase64(string base64) config.ProtocolVersion = reader.ReadUInt16Packed(); ushort sceneCount = reader.ReadUInt16Packed(); - config.RegisteredScenes.Clear(); - - for (int i = 0; i < sceneCount; i++) - { - config.RegisteredScenes.Add(reader.ReadString().ToString()); - } config.TickRate = reader.ReadInt32Packed(); config.ClientConnectionBufferTimeout = reader.ReadInt32Packed(); @@ -250,7 +211,6 @@ public void FromBase64(string base64) config.RecycleNetworkIds = reader.ReadBool(); config.NetworkIdRecycleDelay = reader.ReadSinglePacked(); config.EnableNetworkVariable = reader.ReadBool(); - config.AllowRuntimeSceneChanges = reader.ReadBool(); config.EnableNetworkLogs = reader.ReadBool(); } } @@ -270,22 +230,12 @@ public ulong GetConfig(bool cache = true) return m_ConfigHash.Value; } - Sort(); - using (var buffer = PooledNetworkBuffer.Get()) using (var writer = PooledNetworkWriter.Get(buffer)) { writer.WriteUInt16Packed(ProtocolVersion); writer.WriteString(NetworkConstants.PROTOCOL_VERSION); - if (EnableSceneManagement && !AllowRuntimeSceneChanges) - { - for (int i = 0; i < RegisteredScenes.Count; i++) - { - writer.WriteString(RegisteredScenes[i]); - } - } - if (ForceSamePrefabs) { var sortedDictionary = NetworkPrefabOverrideLinks.OrderBy(x => x.Key); diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 953f1c13f1..7e0a45d92a 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -238,6 +238,16 @@ internal void InvokeConnectionApproval(byte[] payload, ulong clientId, Connectio /// [HideInInspector] public NetworkConfig NetworkConfig; + /// + /// Reference to the ScenesInBuild asset that contains a list of the scenes in the build list + /// + [HideInInspector] + [SerializeField] + internal ScenesInBuild ScenesInBuild; + + [HideInInspector] + [SerializeField] + internal string DefaultScenesInBuildAssetNameAndPath = "Assets/ScenesInBuildList.asset"; /// /// The current host name we are connected to, used to validate certificate /// @@ -247,7 +257,34 @@ internal void InvokeConnectionApproval(byte[] payload, ulong clientId, Connectio internal static event Action OnSingletonReady; + + #if UNITY_EDITOR + /// + /// Assures the ScenesInBuild asset exists and that it is always up to date + /// + /// + internal void PopulateScenesInBuild(bool isTesting = false) + { + // If we are testing or we are playing (in editor) and ScenesInBuild is null then we want to initialize and populate the ScenesInBuild asset. + // Otherwise, there are special edge case scenarios where we might want to repopulate this list + // The scenario with EditorApplication.isPlaying and ScenesInBuild being null is where we loaded a scene that did not have a NetworkManager but + // we transition to a scene with a NetworkManager while playing in the editor. Under this condition we have to assign and populate. + if ( (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating) || isTesting + || ( (ScenesInBuild == null || ScenesInBuild != null && ScenesInBuild.Scenes.Count == 0) && EditorApplication.isPlaying)) + { + if (ScenesInBuild == null) + { + ScenesInBuild = ScenesInBuild.InitializeScenesInBuild(this); + ScenesInBuild.PopulateScenesInBuild(); + } + else + { + ScenesInBuild.PopulateScenesInBuild(); + } + } + } + private void OnValidate() { if (NetworkConfig == null) @@ -255,6 +292,8 @@ private void OnValidate() return; // May occur when the component is added } + PopulateScenesInBuild(); + if (GetComponentInChildren() != null) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) @@ -263,17 +302,6 @@ private void OnValidate() } } - if (NetworkConfig.EnableSceneManagement) - { - foreach (var sceneAsset in NetworkConfig.RegisteredSceneAssets) - { - if (!NetworkConfig.RegisteredScenes.Contains(sceneAsset.name)) - { - NetworkConfig.RegisteredScenes.Add(sceneAsset.name); - } - } - } - var activeScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene(); // If the scene is not dirty or the asset database is currently updating then we can skip updating the NetworkPrefab information @@ -443,18 +471,6 @@ private void Initialize(bool server) // Register INetworkUpdateSystem (always register this after messageQueueContainer has been instantiated) this.RegisterNetworkUpdate(NetworkUpdateStage.PreUpdate); - if (NetworkConfig.EnableSceneManagement) - { - NetworkConfig.RegisteredScenes.Sort(StringComparer.Ordinal); - - for (int i = 0; i < NetworkConfig.RegisteredScenes.Count; i++) - { - SceneManager.RegisteredSceneNames.Add(NetworkConfig.RegisteredScenes[i]); - SceneManager.SceneIndexToString.Add((uint)i, NetworkConfig.RegisteredScenes[i]); - SceneManager.SceneNameToIndex.Add(NetworkConfig.RegisteredScenes[i], (uint)i); - } - } - // This is used to remove entries not needed or invalid var removeEmptyPrefabs = new List(); @@ -1449,8 +1465,6 @@ internal void HandleApproval(ulong ownerClientId, bool createPlayerObject, uint? } } - - /// /// Spawns the newly approved player /// diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs index 9b60dc3862..1d27bdc1cb 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs @@ -539,7 +539,11 @@ public void SpawnAsPlayerObject(ulong clientId, bool destroyWithScene = false) /// (true) the will be destroyed (false) the will persist after being despawned public void Despawn(bool destroy = false) { - NetworkManager.SpawnManager.DespawnObject(this, destroy); + // An edge case scenario can occur that will throw an exception due to the fact that SpawnManager is null. + if (NetworkManager.SpawnManager != null) + { + NetworkManager.SpawnManager.DespawnObject(this, destroy); + } } /// diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs index d8db7d3476..63d8033c5b 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs @@ -37,7 +37,11 @@ public enum SceneEventProgressStatus /// or is invalid /// InvalidSceneName, - + /// + /// Server side: Returned if the delegate handler returns false + /// (i.e. scene is considered not valid/safe to load) + /// + SceneFailedVerification, /// /// This is used for internal error notifications. /// If you receive this event then it is most likely due to a bug. diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs new file mode 100644 index 0000000000..9e5c3c3f8a --- /dev/null +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs @@ -0,0 +1,97 @@ +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; +#if UNITY_EDITOR +using UnityEditor; +#endif + + +namespace Unity.Netcode +{ + /// + /// This replaces the need to register scenes and contains the Scenes in Build list (as strings) + /// Scenes are ordered identically to the Scenes in Build list indices values + /// For refined control over which scenes can be loaded or unloaded during a netcode game session, + /// use the event to add additional + /// constraints over which scenes are considered valid. + /// In order for clients to get this notification you must subscribe to the event. + /// + public class ScenesInBuild : ScriptableObject + { + static internal bool IsTesting; + + [HideInInspector] + [SerializeField] + internal List Scenes; + +#if UNITY_EDITOR + /// + /// This will create a new ScenesInBuildList asset if one does not exist and will adjust the path to the ScenesInBuildList + /// asset if the asset is moved. This will also notify the user if more than one ScenesInBuildList asset exists. + /// + /// The relative network manager instance + /// + internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkManager) + { + var foundScenesInBuildList = AssetDatabase.FindAssets("ScenesInBuildList"); + if (foundScenesInBuildList.Length > 0) + { + if (foundScenesInBuildList.Length > 1) + { + var message = "There are multiple instances of your ScenesInBuildList:\n"; + + foreach (var entry in foundScenesInBuildList) + { + message += $"{AssetDatabase.GUIDToAssetPath(entry)}\n"; + } + message += "Using first entry. Please remove one of the instances if that is not the right asset path!"; + Debug.LogError(message); + } + networkManager.DefaultScenesInBuildAssetNameAndPath = AssetDatabase.GUIDToAssetPath(foundScenesInBuildList[0]); + } + var scenesInBuild = (ScenesInBuild)AssetDatabase.LoadAssetAtPath(networkManager.DefaultScenesInBuildAssetNameAndPath, typeof(ScenesInBuild)); + if(scenesInBuild == null) + { + scenesInBuild = CreateInstance(); + AssetDatabase.CreateAsset(scenesInBuild, networkManager.DefaultScenesInBuildAssetNameAndPath); + } + return scenesInBuild; + } + + /// + /// Populates the scenes from the Scenes in Build list. + /// If testing, then this is ignored (i.e. some tests require loading of scenes not in the Scenes in Build list) + /// + internal void PopulateScenesInBuild() + { + if(Scenes != null && Scenes.Count > 0 && IsTesting) + { + return; + } + Scenes = new List(); + for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) + { + if(IsTesting && i >= EditorBuildSettings.scenes.Length) + { + continue; + } + var scene = EditorBuildSettings.scenes[i]; + var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); + Scenes.Add(sceneAsset.name); + } + AssetDatabase.SaveAssets(); + } + + /// + /// Depending upon the current editor state, this will refresh the Scenes in Build list + /// + private void OnValidate() + { + if (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating || IsTesting) + { + PopulateScenesInBuild(); + } + } +#endif + } +} diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta new file mode 100644 index 0000000000..273da91fcf --- /dev/null +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta @@ -0,0 +1,15 @@ +fileFormatVersion: 2 +<<<<<<< HEAD:testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneToggleHandler.cs.meta +guid: 475de064003ff104fb88b1fbccd0f417 +======= +guid: 6e6dff048b3e7e84b9535cdb6517cf39 +>>>>>>> feat/scenesinbuild-mlapi-sceneregistration:com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs index 2da24c6d38..4300faff33 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using NUnit.Framework; using UnityEngine; using UnityEngine.SceneManagement; @@ -14,19 +13,15 @@ public void CustomMessageManagerAssigned() var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - // Netcode sets this in validate - networkManager.NetworkConfig = new NetworkConfig() - { - // Set the current scene to prevent unexpected log messages which would trigger a failure - RegisteredScenes = new List() { SceneManager.GetActiveScene().name } - }; - + networkManager.PopulateScenesInBuild(true); + networkManager.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; CustomMessagingManager preManager = networkManager.CustomMessagingManager; - // Start server to cause init + // Start server to cause initialization networkManager.StartServer(); Debug.Assert(preManager == null); diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs index 3641cc7836..7eca8311c4 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using NUnit.Framework; using Unity.Netcode.Editor; using UnityEngine; @@ -14,18 +13,15 @@ public class NetworkManagerMessageHandlerTests [Test] public void MessageHandlerReceivedMessageServerClient() { + ScenesInBuild.IsTesting = true; // Init var gameObject = new GameObject(nameof(MessageHandlerReceivedMessageServerClient)); var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - // Netcode sets this in validate - networkManager.NetworkConfig = new NetworkConfig() - { - // Set the current scene to prevent unexpected log messages which would trigger a failure - RegisteredScenes = new List() { SceneManager.GetActiveScene().name } - }; - + networkManager.PopulateScenesInBuild(true); + networkManager.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; @@ -250,6 +246,8 @@ public void MessageHandlerReceivedMessageServerClient() // Full cleanup networkManager.StopClient(); + + ScenesInBuild.IsTesting = false; } // Ensure no missmatches with expectations diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs index c641b2f4b1..f0a096b029 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using NUnit.Framework; using UnityEngine; using UnityEngine.SceneManagement; @@ -13,20 +12,15 @@ public void SceneManagerAssigned() var gameObject = new GameObject(nameof(SceneManagerAssigned)); var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - - // Netcode sets this in validate - networkManager.NetworkConfig = new NetworkConfig() - { - // Set the current scene to prevent unexpected log messages which would trigger a failure - RegisteredScenes = new List() { SceneManager.GetActiveScene().name } - }; - + networkManager.PopulateScenesInBuild(true); + networkManager.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; NetworkSceneManager preManager = networkManager.SceneManager; - // Start server to cause init + // Start server to cause initialization process networkManager.StartServer(); Debug.Assert(preManager == null); diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/BaseMultiInstanceTest.cs b/com.unity.netcode.gameobjects/Tests/Runtime/BaseMultiInstanceTest.cs index df3d8d30ee..50ea181a9f 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/BaseMultiInstanceTest.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/BaseMultiInstanceTest.cs @@ -45,8 +45,7 @@ public virtual IEnumerator Teardown() // Make sure any NetworkObject with a GlobalObjectIdHash value of 0 is destroyed // If we are tearing down, we don't want to leave NetworkObjects hanging around var networkObjects = Object.FindObjectsOfType().ToList(); - var networkObjectsList = networkObjects.Where(c => c.GlobalObjectIdHash == 0); - foreach (var networkObject in networkObjectsList) + foreach (var networkObject in networkObjects) { Object.DestroyImmediate(networkObject); } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs index 3b48766df3..189f20b4b4 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs @@ -59,6 +59,7 @@ private void NetworkManagerObject_ConnectionApprovalCallback(byte[] connectionDa [TearDown] public void TearDown() { + // Stop, shutdown, and destroy NetworkManagerHelper.ShutdownNetworkManager(); } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs index 556be87c37..2cfedb249e 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs @@ -25,6 +25,7 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode) [UnitySetUp] public IEnumerator Setup() { + ScenesInBuild.IsTesting = true; SceneManager.sceneLoaded += OnSceneLoaded; var execAssembly = Assembly.GetExecutingAssembly(); @@ -37,6 +38,7 @@ public IEnumerator Setup() [UnityTearDown] public IEnumerator Teardown() { + ScenesInBuild.IsTesting = false; SceneManager.sceneLoaded -= OnSceneLoaded; if (m_TestScene.isLoaded) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs index 91cbe0a571..8bb53dd583 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs @@ -51,6 +51,7 @@ public enum NetworkManagerOperatingMode /// true if it was instantiated or is already instantiate otherwise false means it failed to instantiate public static bool StartNetworkManager(out NetworkManager networkManager, NetworkManagerOperatingMode managerMode = NetworkManagerOperatingMode.Host, NetworkConfig networkConfig = null) { + ScenesInBuild.IsTesting = true; // If we are changing the current manager mode and the current manager mode is not "None", then stop the NetworkManager mode if (CurrentNetworkManagerMode != managerMode && CurrentNetworkManagerMode != NetworkManagerOperatingMode.None) { @@ -71,19 +72,16 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ Debug.Log($"{nameof(NetworkManager)} Instantiated."); var unetTransport = NetworkManagerGameObject.AddComponent(); - if (networkConfig == null) { networkConfig = new NetworkConfig { EnableSceneManagement = false, - RegisteredScenes = new List() { SceneManager.GetActiveScene().name } }; } - else - { - networkConfig.RegisteredScenes.Add(SceneManager.GetActiveScene().name); - } + + NetworkManagerObject.PopulateScenesInBuild(true); + NetworkManagerObject.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); NetworkManagerObject.NetworkConfig = networkConfig; @@ -234,6 +232,7 @@ private static void StopNetworkManagerMode() // This is called, even if we assert and exit early from a test public static void ShutdownNetworkManager() { + ScenesInBuild.IsTesting = false; // clean up any game objects created with custom unit testing components foreach (var entry in InstantiatedGameObjects) { diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs index e765a184ff..2687d30421 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs @@ -31,7 +31,7 @@ public static class MultiInstanceHelpers public static bool Create(int clientCount, out NetworkManager server, out NetworkManager[] clients, int targetFrameRate = 60) { s_NetworkManagerInstances = new List(); - + ScenesInBuild.IsTesting = true; CreateNewClients(clientCount, out clients); // Create gameObject @@ -44,11 +44,11 @@ public static bool Create(int clientCount, out NetworkManager server, out Networ // Set the NetworkConfig server.NetworkConfig = new NetworkConfig() { - // Set the current scene to prevent unexpected log messages which would trigger a failure - RegisteredScenes = new List() { SceneManager.GetActiveScene().name }, // Set transport NetworkTransport = go.AddComponent() }; + server.PopulateScenesInBuild(true); + server.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); s_OriginalTargetFrameRate = Application.targetFrameRate; Application.targetFrameRate = targetFrameRate; @@ -65,7 +65,7 @@ public static bool Create(int clientCount, out NetworkManager server, out Networ public static bool CreateNewClients(int clientCount, out NetworkManager[] clients) { clients = new NetworkManager[clientCount]; - + var activeSceneName = SceneManager.GetActiveScene().name; for (int i = 0; i < clientCount; i++) { // Create gameObject @@ -76,11 +76,16 @@ public static bool CreateNewClients(int clientCount, out NetworkManager[] client // Set the NetworkConfig clients[i].NetworkConfig = new NetworkConfig() { - // Set the current scene to prevent unexpected log messages which would trigger a failure - RegisteredScenes = new List() { SceneManager.GetActiveScene().name }, // Set transport NetworkTransport = go.AddComponent() }; + + clients[i].PopulateScenesInBuild(true); + + if (!clients[i].ScenesInBuild.Scenes.Contains(activeSceneName)) + { + clients[i].ScenesInBuild.Scenes.Add(activeSceneName); + } } NetworkManagerInstances.AddRange(clients); @@ -131,7 +136,7 @@ public static void Destroy() // Destroy the network manager instances foreach (var networkManager in NetworkManagerInstances) { - Object.Destroy(networkManager.gameObject); + Object.DestroyImmediate(networkManager.gameObject); } NetworkManagerInstances.Clear(); @@ -139,7 +144,8 @@ public static void Destroy() // Destroy the temporary GameObject used to run co-routines if (s_CoroutineRunner != null) { - Object.Destroy(s_CoroutineRunner); + s_CoroutineRunner.StopAllCoroutines(); + Object.DestroyImmediate(s_CoroutineRunner); } Application.targetFrameRate = s_OriginalTargetFrameRate; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectOnSpawnTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectOnSpawnTests.cs index 37d262d516..835f852625 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectOnSpawnTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectOnSpawnTests.cs @@ -57,7 +57,6 @@ public override IEnumerator Setup() [UnityTearDown] public override IEnumerator Teardown() { - yield return base.Teardown(); if (m_TestNetworkObjectPrefab != null) { @@ -68,6 +67,8 @@ public override IEnumerator Teardown() { Object.Destroy(m_TestNetworkObjectInstance); } + yield return base.Teardown(); + } /// diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs index 6984baf2cc..3b32321098 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs @@ -132,7 +132,6 @@ public void NetworkObjectSceneSerializationFailure() invalidNetworkObjectCount++; } - NetworkManagerHelper.NetworkManagerObject.SceneManager.SetTheSceneBeingSynchronized(reader.ReadInt32Packed()); var deserializedNetworkObject = NetworkObject.DeserializeSceneObject(pooledBuffer, reader, NetworkManagerHelper.NetworkManagerObject); @@ -172,6 +171,7 @@ public void NetworkObjectSceneSerializationFailure() [SetUp] public void Setup() { + NetworkSceneManager.IsUnitTesting = true; // Create, instantiate, and host NetworkManagerHelper.StartNetworkManager(out NetworkManager networkManager, NetworkManagerHelper.NetworkManagerOperatingMode.None); networkManager.NetworkConfig.EnableSceneManagement = true; @@ -182,6 +182,7 @@ public void Setup() [TearDown] public void TearDown() { + NetworkSceneManager.IsUnitTesting = false; // Stop, shutdown, and destroy NetworkManagerHelper.ShutdownNetworkManager(); } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index 9f1386bae7..8d2036e6bb 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -43,6 +43,8 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode) [UnitySetUp] public IEnumerator Setup() { + ScenesInBuild.IsTesting = true; + NetworkSceneManager.IsUnitTesting = true; SceneManager.sceneLoaded += OnSceneLoaded; var execAssembly = Assembly.GetExecutingAssembly(); @@ -60,6 +62,14 @@ public IEnumerator Setup() Assert.That(m_ServerNetworkManager, Is.Not.Null); Assert.That(m_ClientNetworkManagers, Is.Not.Null); Assert.That(m_ClientNetworkManagers.Length, Is.EqualTo(k_ClientInstanceCount)); + m_ServerNetworkManager.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); + foreach(var entry in m_ClientNetworkManagers) + { + if(!m_ServerNetworkManager.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) + { + m_ServerNetworkManager.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); + } + } m_Dude_NetObjs = new Transform[setCount]; m_Dude_LeftArm_NetObjs = new Transform[setCount]; @@ -189,6 +199,8 @@ public void SetupSet(Transform rootTransform, int setIndex, NetworkManager netwo [UnityTearDown] public IEnumerator Teardown() { + NetworkSceneManager.IsUnitTesting = false; + ScenesInBuild.IsTesting = false; SceneManager.sceneLoaded -= OnSceneLoaded; MultiInstanceHelpers.Destroy(); diff --git a/testproject/Assets/Prefabs/SceneLevelGeometry.prefab b/testproject/Assets/Prefabs/SceneLevelGeometry.prefab index 680403c8f0..da9864d139 100644 --- a/testproject/Assets/Prefabs/SceneLevelGeometry.prefab +++ b/testproject/Assets/Prefabs/SceneLevelGeometry.prefab @@ -1,5 +1,93 @@ %YAML 1.1 %TAG !u! tag:unity3d.com,2011: +--- !u!1 &910007655143077103 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6283120762215196916} + - component: {fileID: 3739510624437302406} + m_Layer: 0 + m_Name: CornerBumper (1) + m_TagString: Boundary + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6283120762215196916 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 910007655143077103} + m_LocalRotation: {x: -0, y: -0.9244967, z: -0, w: -0.38119} + m_LocalPosition: {x: -29.72, y: 0.98, z: 29.82} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4012615692778511849} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: -224.815, z: 0} +--- !u!65 &3739510624437302406 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 910007655143077103} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 4, y: 2, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!1 &1854705290947220173 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2290144462706082272} + - component: {fileID: 4559046433245738380} + m_Layer: 0 + m_Name: CornerBumper (2) + m_TagString: Boundary + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &2290144462706082272 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1854705290947220173} + m_LocalRotation: {x: -0, y: -0.3771283, z: -0, w: -0.92616105} + m_LocalPosition: {x: -29.53, y: 0.98, z: -29.71} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4012615692778511849} + m_RootOrder: 7 + m_LocalEulerAnglesHint: {x: 0, y: -315.688, z: 0} +--- !u!65 &4559046433245738380 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1854705290947220173} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 4, y: 2, z: 1} + m_Center: {x: 0, y: 0, z: 0} --- !u!1 &4012615691354089848 GameObject: m_ObjectHideFlags: 0 @@ -190,8 +278,8 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} + m_Size: {x: 2, y: 1, z: 1} + m_Center: {x: -0.5, y: 0, z: 0} --- !u!1 &4012615691965054905 GameObject: m_ObjectHideFlags: 0 @@ -286,8 +374,8 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} + m_Size: {x: 1, y: 1, z: 2} + m_Center: {x: 0, y: 0, z: 0.5} --- !u!1 &4012615692269653858 GameObject: m_ObjectHideFlags: 0 @@ -382,8 +470,8 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} + m_Size: {x: 1, y: 1, z: 2} + m_Center: {x: 0, y: 0, z: -0.5} --- !u!1 &4012615692778511854 GameObject: m_ObjectHideFlags: 0 @@ -394,7 +482,7 @@ GameObject: m_Component: - component: {fileID: 4012615692778511849} m_Layer: 0 - m_Name: Level + m_Name: SceneLevelGeometry m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -416,6 +504,10 @@ Transform: - {fileID: 4012615692269653854} - {fileID: 4012615691503252839} - {fileID: 4012615692791378778} + - {fileID: 3910294717376836327} + - {fileID: 6283120762215196916} + - {fileID: 2290144462706082272} + - {fileID: 6959258897999621209} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -513,5 +605,93 @@ BoxCollider: m_IsTrigger: 0 m_Enabled: 1 serializedVersion: 2 - m_Size: {x: 1, y: 1, z: 1} + m_Size: {x: 2, y: 1, z: 1} + m_Center: {x: 0.5, y: 0, z: 0} +--- !u!1 &4674276234353933548 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3910294717376836327} + - component: {fileID: 3136259738973340924} + m_Layer: 0 + m_Name: CornerBumper + m_TagString: Boundary + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &3910294717376836327 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4674276234353933548} + m_LocalRotation: {x: 0, y: -0.38268343, z: 0, w: 0.92387956} + m_LocalPosition: {x: 29.7, y: 0.98, z: -29.61} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4012615692778511849} + m_RootOrder: 5 + m_LocalEulerAnglesHint: {x: 0, y: -45, z: 0} +--- !u!65 &3136259738973340924 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4674276234353933548} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 4, y: 2, z: 1} + m_Center: {x: 0, y: 0, z: 0} +--- !u!1 &7080625901286762351 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6959258897999621209} + - component: {fileID: 7672408768716900064} + m_Layer: 0 + m_Name: CornerBumper (3) + m_TagString: Boundary + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6959258897999621209 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7080625901286762351} + m_LocalRotation: {x: -0, y: 0.93588465, z: -0, w: -0.35230666} + m_LocalPosition: {x: 29.26, y: 0.98, z: 29.45} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 4012615692778511849} + m_RootOrder: 8 + m_LocalEulerAnglesHint: {x: 0, y: -498.74298, z: 0} +--- !u!65 &7672408768716900064 +BoxCollider: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7080625901286762351} + m_Material: {fileID: 0} + m_IsTrigger: 0 + m_Enabled: 1 + serializedVersion: 2 + m_Size: {x: 4, y: 2, z: 1} m_Center: {x: 0, y: 0, z: 0} diff --git a/testproject/Assets/Samples/PrefabPool/PrefabPoolOverrideExample.unity b/testproject/Assets/Samples/PrefabPool/PrefabPoolOverrideExample.unity index d3ffd1e1ec..d358a72d23 100644 --- a/testproject/Assets/Samples/PrefabPool/PrefabPoolOverrideExample.unity +++ b/testproject/Assets/Samples/PrefabPool/PrefabPoolOverrideExample.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.44657874, g: 0.49641275, b: 0.5748172, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -265,6 +265,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -563,6 +564,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -850,7 +852,7 @@ GameObject: - component: {fileID: 1024114719} - component: {fileID: 1024114718} m_Layer: 0 - m_Name: '[NetworkManager]' + m_Name: NetworkManager m_TagString: Untagged m_Icon: {fileID: 0} m_NavMeshLayer: 0 @@ -874,10 +876,6 @@ MonoBehaviour: NetworkConfig: ProtocolVersion: 0 NetworkTransport: {fileID: 1024114719} - RegisteredScenes: - - PrefabPoolExample - - PrefabPoolOverrideExample - AllowRuntimeSceneChanges: 0 PlayerPrefab: {fileID: 4079352819444256614, guid: c16f03336b6104576a565ef79ad643c0, type: 3} NetworkPrefabs: @@ -905,6 +903,10 @@ MonoBehaviour: LoadSceneTimeOut: 120 MessageBufferTimeout: 20 EnableNetworkLogs: 1 + UseSnapshotDelta: 0 + UseSnapshotSpawn: 0 + ScenesInBuild: {fileID: 11400000, guid: bf58cb10b5121b843991aa419917e22c, type: 2} + DefaultScenesInBuildAssetNameAndPath: Assets/ScenesInBuildList.asset --- !u!114 &1024114719 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1091,6 +1093,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -1464,6 +1467,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -1684,6 +1688,7 @@ MeshRenderer: m_CastShadows: 1 m_ReceiveShadows: 1 m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 m_MotionVectors: 1 m_LightProbeUsage: 1 m_ReflectionProbeUsage: 1 @@ -1781,6 +1786,8 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_ClientServerToggle: {fileID: 1588117327} + m_TrackSceneEvents: 0 + m_LogSceneEventsToConsole: 1 --- !u!114 &2107482023 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneMultiInstance.unity b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneMultiInstance.unity index 5e2a4dcbf1..6ea9d5e74b 100644 --- a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneMultiInstance.unity +++ b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneMultiInstance.unity @@ -123,6 +123,154 @@ NavMeshSettings: debug: m_Flags: 0 m_NavMeshData: {fileID: 0} +--- !u!1001 &151772428 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: -5591000292386890817, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: GlobalObjectIdHash + value: 2264043126 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360811, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_Name + value: RandomMoverObject (1) + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_RootOrder + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.x + value: 4.08 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: ea906834639fa3f4ba65c95db6181d6b, type: 3} +--- !u!1001 &365996112 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: -5591000292386890817, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: GlobalObjectIdHash + value: 179273863 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360811, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_Name + value: RandomMoverObject (3) + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_RootOrder + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.z + value: -5.45 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: ea906834639fa3f4ba65c95db6181d6b, type: 3} --- !u!850595691 &903034822 LightingSettings: m_ObjectHideFlags: 0 @@ -184,6 +332,80 @@ LightingSettings: m_PVRFilteringAtrousPositionSigmaDirect: 0.5 m_PVRFilteringAtrousPositionSigmaIndirect: 2 m_PVRFilteringAtrousPositionSigmaAO: 1 +--- !u!1001 &1152084533 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 0} + m_Modifications: + - target: {fileID: -5591000292386890817, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: GlobalObjectIdHash + value: 860074760 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360811, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_Name + value: RandomMoverObject (2) + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_RootOrder + value: 2 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.y + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalPosition.z + value: 8.05 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, + type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: ea906834639fa3f4ba65c95db6181d6b, type: 3} --- !u!1001 &1247056486 PrefabInstance: m_ObjectHideFlags: 0 @@ -209,7 +431,7 @@ PrefabInstance: - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, type: 3} propertyPath: m_LocalPosition.x - value: 0 + value: -3.8 objectReference: {fileID: 0} - target: {fileID: 771575417923360822, guid: ea906834639fa3f4ba65c95db6181d6b, type: 3} diff --git a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneToggleHandler.cs b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneToggleHandler.cs index b1e24eb859..ef13b2dc9f 100644 --- a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneToggleHandler.cs +++ b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneToggleHandler.cs @@ -1,4 +1,5 @@ using System.Collections; +using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; @@ -100,7 +101,7 @@ private void SceneManager_OnSceneEvent(SceneEvent sceneEvent) } else if (sceneEvent.SceneEventType == SceneEventData.SceneEventTypes.C2S_UnloadComplete) { - if (sceneEvent.ClientId == NetworkManager.Singleton.ServerClientId && !m_SceneLoaded.isLoaded) + if (sceneEvent.ClientId == NetworkManager.Singleton.ServerClientId && !m_SceneLoaded.isLoaded ) { m_SceneLoaded = new Scene(); m_WaitForSceneLoadOrUnload = false; @@ -126,19 +127,22 @@ public void OnToggle() if (m_ToggleObject) { m_ToggleObject.enabled = false; - StartCoroutine(SceneEventCoroutine(m_ToggleObject.isOn)); + ToggleSceneManager.AddNewToggleHandler(this); } } } + private bool m_WaitForSceneLoadOrUnload; - private IEnumerator SceneEventCoroutine(bool isLoading) + public IEnumerator SceneEventCoroutine() { + var isLoading = m_ToggleObject.isOn; var sceneEventProgressStatus = SceneEventProgressStatus.None; var continueCheck = true; + NetworkManager.Singleton.SceneManager.OnSceneEvent += SceneManager_OnSceneEvent; - while (continueCheck && sceneEventProgressStatus != SceneEventProgressStatus.Started) + while (continueCheck && sceneEventProgressStatus != SceneEventProgressStatus.Started && sceneEventProgressStatus != SceneEventProgressStatus.SceneFailedVerification) { if (isLoading) { @@ -148,31 +152,31 @@ private IEnumerator SceneEventCoroutine(bool isLoading) { sceneEventProgressStatus = NetworkManager.Singleton.SceneManager.UnloadScene(m_SceneLoaded); } - if (sceneEventProgressStatus == SceneEventProgressStatus.SceneEventInProgress) - { - yield return new WaitForSeconds(0.25f); - } - else + + switch (sceneEventProgressStatus) { - switch (sceneEventProgressStatus) + case SceneEventProgressStatus.SceneEventInProgress: { - case SceneEventProgressStatus.Started: - { - continueCheck = false; - break; - } - case SceneEventProgressStatus.InternalNetcodeError: - case SceneEventProgressStatus.InvalidSceneName: - case SceneEventProgressStatus.SceneNotLoaded: - { - continueCheck = false; - break; - } + yield return new WaitForSeconds(0.25f); + break; } + case SceneEventProgressStatus.Started: + { + continueCheck = false; + break; + } + case SceneEventProgressStatus.InternalNetcodeError: + case SceneEventProgressStatus.InvalidSceneName: + case SceneEventProgressStatus.SceneNotLoaded: + { + Debug.Log($"Scene Event Error: {sceneEventProgressStatus}"); + continueCheck = false; + break; + } } } m_WaitForSceneLoadOrUnload = true; - var timeOutAfter = Time.realtimeSinceStartup + 10.0f; + var timeOutAfter = Time.realtimeSinceStartup + 5.0f; while (m_WaitForSceneLoadOrUnload) { if (timeOutAfter < Time.realtimeSinceStartup) @@ -183,11 +187,46 @@ private IEnumerator SceneEventCoroutine(bool isLoading) yield return new WaitForSeconds(0.5f); } - NetworkManager.Singleton.SceneManager.OnSceneEvent -= SceneManager_OnSceneEvent; m_ToggleObject.isOn = isLoading; m_ToggleObject.enabled = true; + ToggleSceneManager.CurrentQueueItem = null; yield return null; } } + + + public static class ToggleSceneManager + { + + private static Queue s_QueueUpForLoadUnload = new Queue(); + public static AdditiveSceneToggleHandler CurrentQueueItem; + static private IEnumerator GlobalQueueToggleRoutine() + { + while (s_QueueUpForLoadUnload.Count > 0) + { + CurrentQueueItem = s_QueueUpForLoadUnload.Dequeue(); + CurrentQueueItem.StartCoroutine(CurrentQueueItem.SceneEventCoroutine()); + while (CurrentQueueItem != null) + { + yield return new WaitForSeconds(0.25f); + } + } + yield return null; + } + + + public static void AddNewToggleHandler(AdditiveSceneToggleHandler handler) + { + if (s_QueueUpForLoadUnload.Count == 0 && CurrentQueueItem == null) + { + s_QueueUpForLoadUnload.Enqueue(handler); + NetworkManager.Singleton.StartCoroutine(GlobalQueueToggleRoutine()); + } + else + { + s_QueueUpForLoadUnload.Enqueue(handler); + } + } + } } diff --git a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneTransitioningBase1.unity b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneTransitioningBase1.unity index 54c12bae18..9fdb0b1d3b 100644 --- a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneTransitioningBase1.unity +++ b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneTransitioningBase1.unity @@ -5053,6 +5053,46 @@ PrefabInstance: propertyPath: m_Name value: ExitButton objectReference: {fileID: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_Text + value: X + objectReference: {fileID: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_FontData.m_Font + value: + objectReference: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_FontData.m_MaxSize + value: 40 + objectReference: {fileID: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_FontData.m_MinSize + value: 10 + objectReference: {fileID: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_FontData.m_FontSize + value: 14 + objectReference: {fileID: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_FontData.m_RichText + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_FontData.m_Alignment + value: 4 + objectReference: {fileID: 0} + - target: {fileID: 2848221157716786269, guid: 3200770c16e3b2b4ebe7f604154faac7, + type: 3} + propertyPath: m_FontData.m_LineSpacing + value: 1 + objectReference: {fileID: 0} - target: {fileID: 5266522511616468950, guid: 3200770c16e3b2b4ebe7f604154faac7, type: 3} propertyPath: m_SceneMenuToLoad diff --git a/testproject/Assets/Tests/Manual/Scripts/IndependentMover.cs.meta b/testproject/Assets/Tests/Manual/Scripts/IndependentMover.cs.meta index 37294f1a0e..1e4e5b2879 100644 --- a/testproject/Assets/Tests/Manual/Scripts/IndependentMover.cs.meta +++ b/testproject/Assets/Tests/Manual/Scripts/IndependentMover.cs.meta @@ -1,5 +1,9 @@ fileFormatVersion: 2 +<<<<<<< HEAD:com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta +guid: c4152da5a2f4e7746aecdcd815f6616b +======= guid: c552ef0ccf6ff8148a9c9606e7d3fc15 +>>>>>>> test/AdditiveSceneLoading:testproject/Assets/Tests/Manual/Scripts/IndependentMover.cs.meta MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPool.cs b/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPool.cs index ec09ba7f6b..f4334eb4c4 100644 --- a/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPool.cs +++ b/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPool.cs @@ -7,7 +7,7 @@ namespace TestProject.ManualTests { - public class NetworkPrefabPool : NetworkBehaviour + public class NetworkPrefabPool : NetworkBehaviour, INetworkPrefabInstanceHandler { [Header("General Settings")] public bool AutoSpawnEnable = true; @@ -42,8 +42,6 @@ public class NetworkPrefabPool : NetworkBehaviour private GameObject m_ObjectToSpawn; private List m_ObjectPool; - private MyCustomPrefabSpawnHandler m_MyCustomPrefabSpawnHandler; - /// /// Called when enabled, if already connected we register any custom prefab spawn handler here /// @@ -55,24 +53,37 @@ private void OnEnable() } } + private bool m_IsQuitting; + private void OnApplicationQuit() + { + m_IsQuitting = true; + } + + private void OnDisable() + { + if (!m_IsQuitting) + { + DeregisterCustomPrefabHandler(); + } + } + /// /// Handles registering the custom prefab handler /// private void RegisterCustomPrefabHandler() { // Register the custom spawn handler? - if (m_MyCustomPrefabSpawnHandler == null && EnableHandler) + if (EnableHandler) { if (NetworkManager && NetworkManager.PrefabHandler != null) { - m_MyCustomPrefabSpawnHandler = new MyCustomPrefabSpawnHandler(this); if (RegisterUsingNetworkObject) { - NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool.GetComponent(), m_MyCustomPrefabSpawnHandler); + NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool.GetComponent(), this); } else { - NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool, m_MyCustomPrefabSpawnHandler); + NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool, this); } } else if (!IsServer) @@ -82,15 +93,10 @@ private void RegisterCustomPrefabHandler() } } - private void OnDisable() - { - OnUnloadScene(); - } - private void DeregisterCustomPrefabHandler() { // Register the custom spawn handler? - if (EnableHandler && NetworkManager && NetworkManager.PrefabHandler != null && m_MyCustomPrefabSpawnHandler != null) + if (EnableHandler && NetworkManager && NetworkManager.PrefabHandler != null) { NetworkManager.PrefabHandler.RemoveHandler(ServerObjectToPool); if (IsClient && m_ObjectToSpawn != null) @@ -132,12 +138,18 @@ private void OnUnloadScene() DeregisterCustomPrefabHandler(); CleanNetworkObjects(); + + if (NetworkManager != null && NetworkManager.SceneManager != null) + { + NetworkManager.SceneManager.OnSceneEvent -= OnSceneEvent; + } } } public override void OnNetworkDespawn() { + DeregisterCustomPrefabHandler(); if (NetworkManager != null) { NetworkManager.SceneManager.OnSceneEvent -= OnSceneEvent; @@ -392,18 +404,10 @@ private IEnumerator SpawnObjects() } } } - } - - /// - /// The custom prefab handler that returns an object from the prefab pool - /// - public class MyCustomPrefabSpawnHandler : INetworkPrefabInstanceHandler - { - private NetworkPrefabPool m_PrefabPool; public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) { - var obj = m_PrefabPool.GetObject(); + var obj = GetObject(); if (obj != null) { obj.transform.position = position; @@ -421,13 +425,8 @@ public void Destroy(NetworkObject networkObject) } else { - Object.Destroy(networkObject.gameObject); + Destroy(networkObject.gameObject); } } - - public MyCustomPrefabSpawnHandler(NetworkPrefabPool objectPool) - { - m_PrefabPool = objectPool; - } } } diff --git a/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPoolAdditive.cs b/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPoolAdditive.cs index b4c0c2f515..0fd3cc8f5f 100644 --- a/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPoolAdditive.cs +++ b/testproject/Assets/Tests/Manual/Scripts/NetworkPrefabPoolAdditive.cs @@ -6,7 +6,7 @@ namespace TestProject.ManualTests { - public class NetworkPrefabPoolAdditive : NetworkBehaviour + public class NetworkPrefabPoolAdditive : NetworkBehaviour, INetworkPrefabInstanceHandler { [Header("General Settings")] public bool RandomMovement = true; @@ -43,26 +43,23 @@ public class NetworkPrefabPoolAdditive : NetworkBehaviour private GameObject m_ObjectToSpawn; private List m_ObjectPool; - private MyAdditiveCustomPrefabSpawnHandler m_AdditiveCustomPrefabSpawnHandler; - /// /// Handles registering the custom prefab handler /// private void RegisterCustomPrefabHandler() { // Register the custom spawn handler? - if (m_AdditiveCustomPrefabSpawnHandler == null && EnableHandler) + if (EnableHandler) { if (NetworkManager && NetworkManager.PrefabHandler != null) { - m_AdditiveCustomPrefabSpawnHandler = new MyAdditiveCustomPrefabSpawnHandler(this); if (RegisterUsingNetworkObject) { - NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool.GetComponent(), m_AdditiveCustomPrefabSpawnHandler); + NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool.GetComponent(), this); } else { - NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool, m_AdditiveCustomPrefabSpawnHandler); + NetworkManager.PrefabHandler.AddHandler(ServerObjectToPool, this); } } } @@ -71,7 +68,7 @@ private void RegisterCustomPrefabHandler() private void DeregisterCustomPrefabHandler() { // Register the custom spawn handler? - if (EnableHandler && NetworkManager && NetworkManager.PrefabHandler != null && m_AdditiveCustomPrefabSpawnHandler != null) + if (EnableHandler && NetworkManager && NetworkManager.PrefabHandler != null) { NetworkManager.PrefabHandler.RemoveHandler(ServerObjectToPool); if (IsClient && m_ObjectToSpawn != null) @@ -108,7 +105,6 @@ private void Start() } - /// /// For additive scenes, we only clear out our pooled NetworkObjects if we are migrating them from the ActiveScene /// to the scene where this NetworkPrefabPoolAdditive component is instantiated. @@ -368,6 +364,12 @@ public void UpdateSpawnsPerSecond() } + + private void OnDisable() + { + StopCoroutine(SpawnObjects()); + } + /// /// Coroutine to spawn boxes /// @@ -425,18 +427,10 @@ private IEnumerator SpawnObjects() } } } - } - - /// - /// The custom prefab handler that returns an object from the prefab pool - /// - public class MyAdditiveCustomPrefabSpawnHandler : INetworkPrefabInstanceHandler - { - private NetworkPrefabPoolAdditive m_PrefabPool; public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) { - var obj = m_PrefabPool.GetObject(); + var obj = GetObject(); if (obj != null) { obj.transform.position = position; @@ -455,13 +449,8 @@ public void Destroy(NetworkObject networkObject) } else { - Object.Destroy(networkObject.gameObject); + Destroy(networkObject.gameObject); } } - - public MyAdditiveCustomPrefabSpawnHandler(NetworkPrefabPoolAdditive objectPool) - { - m_PrefabPool = objectPool; - } } } diff --git a/testproject/Assets/Tests/Manual/Scripts/RandomMovement.cs b/testproject/Assets/Tests/Manual/Scripts/RandomMovement.cs index 5d1e1f1422..7134251686 100644 --- a/testproject/Assets/Tests/Manual/Scripts/RandomMovement.cs +++ b/testproject/Assets/Tests/Manual/Scripts/RandomMovement.cs @@ -46,7 +46,11 @@ public void Move(int speed) else if (!IsServer && IsOwner) { // Client must sent Rpc - MovePlayerServerRpc(m_Direction * speed); + MovePlayerServerRpc(m_Direction * speed*1.05f); + } + else if (IsServer && !IsOwner) + { + m_MoveTowardsPosition = Vector3.Lerp(m_MoveTowardsPosition, Vector3.zero, 0.01f); } } diff --git a/testproject/Assets/Tests/Runtime/MessageOrdering.cs b/testproject/Assets/Tests/Runtime/MessageOrdering.cs index 70506cdd08..d9adab8575 100644 --- a/testproject/Assets/Tests/Runtime/MessageOrdering.cs +++ b/testproject/Assets/Tests/Runtime/MessageOrdering.cs @@ -167,7 +167,6 @@ public IEnumerator SpawnRpcDespawn([Values] NetworkUpdateStage testStage) var nextFrameNumber = Time.frameCount + 1; yield return new WaitUntil(() => Time.frameCount >= nextFrameNumber); } - Assert.AreEqual(testStage, Support.SpawnRpcDespawn.StageExecutedByReceiver); Assert.AreEqual(Support.SpawnRpcDespawn.ServerUpdateCount, Support.SpawnRpcDespawn.ClientUpdateCount); Assert.True(handler.WasSpawned); diff --git a/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs b/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs index da85f8b9ab..f002e4d745 100644 --- a/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs +++ b/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs @@ -52,6 +52,7 @@ public IEnumerator ConnectionApprovalPrefabOverride() /// private IEnumerator ConnectionApprovalHandler(int numClients, int failureTestCount = 1, bool prefabOverride = false) { + ScenesInBuild.IsTesting = true; var startFrameCount = Time.frameCount; var startTime = Time.realtimeSinceStartup; @@ -184,6 +185,7 @@ private void ConnectionApprovalCallback(byte[] connectionData, ulong clientId, N [TearDown] public void TearDown() { + ScenesInBuild.IsTesting = false; if (m_PlayerPrefab != null) { Object.Destroy(m_PlayerPrefab); diff --git a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs index 8bfae869b2..3f7a6930bf 100644 --- a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs +++ b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs @@ -11,7 +11,7 @@ namespace TestProject.RuntimeTests { - public class NetworkSceneManagerTests: BaseMultiInstanceTest + public class NetworkSceneManagerTests : BaseMultiInstanceTest { protected override int NbClients => 9; @@ -139,22 +139,22 @@ public IEnumerator SceneLoadingAndNotifications() /// /// Initializes the m_ShouldWaitList /// - private void InitializeSceneTestInfo() + private void InitializeSceneTestInfo(bool enableSceneVerification = false) { m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = m_ServerNetworkManager.ServerClientId, ShouldWait = false }); - if (!m_ServerNetworkManager.NetworkConfig.RegisteredScenes.Contains(m_CurrentSceneName)) + if (enableSceneVerification) { - m_ServerNetworkManager.NetworkConfig.AllowRuntimeSceneChanges = true; - m_ServerNetworkManager.SceneManager.AddRuntimeSceneName(m_CurrentSceneName, (uint)(m_ServerNetworkManager.NetworkConfig.RegisteredScenes.Count + 1)); + m_ServerNetworkManager.PopulateScenesInBuild(); + m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = ServerVerifySceneBeforeLoading; } foreach (var manager in m_ClientNetworkManagers) { m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = manager.LocalClientId, ShouldWait = false }); - if (!manager.NetworkConfig.RegisteredScenes.Contains(m_CurrentSceneName)) + if (enableSceneVerification) { - manager.NetworkConfig.AllowRuntimeSceneChanges = true; - manager.SceneManager.AddRuntimeSceneName(m_CurrentSceneName, (uint)(manager.NetworkConfig.RegisteredScenes.Count + 1)); + manager.PopulateScenesInBuild(); + manager.SceneManager.VerifySceneBeforeLoading = ClientVerifySceneBeforeLoading; } } } @@ -182,7 +182,15 @@ private void ResetWait() private bool ShouldWait() { m_TimedOut = m_TimeOutMarker < Time.realtimeSinceStartup; - return (m_ShouldWaitList.Select(c => c).Where(c => c.ProcessedEvent != true && c.ShouldWait == true).Count() > 0) && !m_TimedOut; + if (!m_IsTestingVerifyScene) + { + return (m_ShouldWaitList.Select(c => c).Where(c => c.ProcessedEvent != true && c.ShouldWait == true).Count() > 0) && !m_TimedOut; + } + else + { + return (m_ShouldWaitList.Select(c => c).Where(c => c.ProcessedEvent != true && c.ShouldWait == true && + c.ClientId == m_ServerNetworkManager.ServerClientId).Count() > 0) && !m_TimedOut && m_ClientsThatFailedVerification != NbClients; + } } /// @@ -224,15 +232,15 @@ private void SetClientWaitDone(List clients) private bool ContainsAllClients(List clients) { // First, make sure we have the expected client count - if(clients.Count != m_ShouldWaitList.Count) + if (clients.Count != m_ShouldWaitList.Count) { return false; } // Next, make sure we have all client identifiers - foreach(var sceneTestInfo in m_ShouldWaitList) + foreach (var sceneTestInfo in m_ShouldWaitList) { - if(!clients.Contains(sceneTestInfo.ClientId)) + if (!clients.Contains(sceneTestInfo.ClientId)) { return false; } @@ -248,7 +256,7 @@ private bool ContainsAllClients(List clients) /// private void SceneManager_OnSceneEvent(SceneEvent sceneEvent) { - switch(sceneEvent.SceneEventType) + switch (sceneEvent.SceneEventType) { case SceneEventData.SceneEventTypes.S2C_Load: case SceneEventData.SceneEventTypes.S2C_Unload: @@ -300,5 +308,107 @@ private void SceneManager_OnSceneEvent(SceneEvent sceneEvent) } } } + + private bool m_IsTestingVerifyScene; + private bool m_ServerVerifyScene; + private bool m_ClientVerifyScene; + private int m_ExpectedSceneIndex; + private int m_ClientsThatFailedVerification; + private string m_ExpectedSceneName; + private LoadSceneMode m_ExpectedLoadMode; + + private bool ServerVerifySceneBeforeLoading(int sceneIndex, string sceneName, LoadSceneMode loadSceneMode) + { + Assert.IsTrue(m_ExpectedSceneIndex == sceneIndex); + Assert.IsTrue(m_ExpectedSceneName == sceneName); + Assert.IsTrue(m_ExpectedLoadMode == loadSceneMode); + + return m_ServerVerifyScene; + } + + private bool ClientVerifySceneBeforeLoading(int sceneIndex, string sceneName, LoadSceneMode loadSceneMode) + { + Assert.IsTrue(m_ExpectedSceneIndex == sceneIndex); + Assert.IsTrue(m_ExpectedSceneName == sceneName); + Assert.IsTrue(m_ExpectedLoadMode == loadSceneMode); + if(!m_ClientVerifyScene) + { + m_ClientsThatFailedVerification++; + } + return m_ClientVerifyScene; + } + + /// + /// Unit test to verify that user defined scene verification works on both the client and + /// the server side. + /// + /// + [UnityTest] + public IEnumerator SceneVerifyBeforeLoadTest() + { + m_ServerNetworkManager.SceneManager.OnSceneEvent += SceneManager_OnSceneEvent; + m_CurrentSceneName = "AdditiveScene1"; + + // Now prepare for the loading and unloading additive scene testing + InitializeSceneTestInfo(true); + + // Test VerifySceneBeforeLoading with both server and client set to true + ResetWait(); + m_ServerVerifyScene = m_ClientVerifyScene = true; + m_ExpectedSceneIndex = (int)m_ServerNetworkManager.SceneManager.GetBuildIndexFromSceneName(m_CurrentSceneName); + m_ExpectedSceneName = m_CurrentSceneName; + m_ExpectedLoadMode = LoadSceneMode.Additive; + var result = m_ServerNetworkManager.SceneManager.LoadScene(m_CurrentSceneName, LoadSceneMode.Additive); + Assert.True(result == SceneEventProgressStatus.Started); + + // Wait for all clients to load the scene + yield return new WaitWhile(ShouldWait); + Assert.IsFalse(m_TimedOut); + + // Unload the scene + ResetWait(); + result = m_ServerNetworkManager.SceneManager.UnloadScene(m_CurrentScene); + Assert.True(result == SceneEventProgressStatus.Started); + + yield return new WaitWhile(ShouldWait); + Assert.IsFalse(m_TimedOut); + + // Test VerifySceneBeforeLoading with m_ServerVerifyScene set to false + // Server will notify it failed scene verification and no client should load + ResetWait(); + m_ServerVerifyScene = false; + result = m_ServerNetworkManager.SceneManager.LoadScene(m_CurrentSceneName, LoadSceneMode.Additive); + Assert.True(result == SceneEventProgressStatus.SceneFailedVerification); + + // Test VerifySceneBeforeLoading with m_ServerVerifyScene set to true and m_ClientVerifyScene set to false + // Server should load and clients will notify they failed scene verification + ResetWait(); + m_CurrentSceneName = "AdditiveScene2"; + m_ExpectedSceneName = m_CurrentSceneName; + m_ExpectedSceneIndex = (int)m_ServerNetworkManager.SceneManager.GetBuildIndexFromSceneName(m_CurrentSceneName); + m_ServerVerifyScene = true; + m_ClientVerifyScene = false; + m_IsTestingVerifyScene = true; + m_ClientsThatFailedVerification = 0; + result = m_ServerNetworkManager.SceneManager.LoadScene(m_CurrentSceneName, LoadSceneMode.Additive); + Assert.True(result == SceneEventProgressStatus.Started); + + // Now wait for server to complete and all clients to fail + yield return new WaitWhile(ShouldWait); + Assert.IsFalse(m_TimedOut); + + // Now unload the scene the server loaded from last test + ResetWait(); + m_IsTestingVerifyScene = false; + result = m_ServerNetworkManager.SceneManager.UnloadScene(m_CurrentScene); + Assert.True(result == SceneEventProgressStatus.Started); + + // Now wait for server to unload and clients will fake unload + yield return new WaitWhile(ShouldWait); + Assert.IsFalse(m_TimedOut); + + yield break; + } + } } diff --git a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs.meta b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs.meta index 7e4d9c6ae8..31c443308c 100644 --- a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs.meta +++ b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: f7bf3513fa4b1c846af40172cdb7c9af +guid: e536693df1c81e94388cab0f062c2352 MonoImporter: externalObjects: {} serializedVersion: 2 From 3e1c307055645f087f53e5d0ce8e86af14f948a7 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 23 Aug 2021 18:30:28 -0500 Subject: [PATCH 02/20] refactor This is a merge refactoring due to an issue with one of the dependent branches (test/additivesceneloading) that was broken while Fatih was showing me an alternate way to handle daisy chaining branches. Went ahead and followed the same path Fatih took with fixing the additive scene testing. It still has an issue with the unit test, but it is close to being back to the way it was with the additional updates from PR-955. --- .../SceneManagement/NetworkSceneManager.cs | 226 +++++++++++++----- .../SceneManagement/ScenesInBuild.cs.meta | 2 +- .../NetworkObjectSceneSerializationTests.cs | 2 - .../NetworkObjectParentingTests.cs | 2 - .../Assets/Prefabs/RandomMoverObject.prefab | 6 +- 5 files changed, 166 insertions(+), 72 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 5f682adf3a..34e22d5a0e 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -115,9 +115,25 @@ public class NetworkSceneManager /// public event SceneEventDelegate OnSceneEvent; - internal readonly HashSet RegisteredSceneNames = new HashSet(); - internal readonly Dictionary SceneNameToIndex = new Dictionary(); - internal readonly Dictionary SceneIndexToString = new Dictionary(); + /// Delegate declaration for the handler that provides + /// an additional level of scene loading security and/or validation to assure the scene being loaded + /// is valid scene to be loaded in the LoadSceneMode specified. + /// + /// Build Settings Scenes in Build List index of the scene + /// Name of the scene + /// LoadSceneMode the scene is going to be loaded + /// true (valid) or false (not valid) + public delegate bool VerifySceneBeforeLoadingDelegateHandler(int sceneIndex, string sceneName, LoadSceneMode loadSceneMode); + + /// + /// Delegate handler defined by that is invoked before the + /// server or client loads a scene during an active netcode game session. + /// Client Side: In order for clients to be notified of this condition you must subscribe to the event. + /// Server Side: will return . + /// + public VerifySceneBeforeLoadingDelegateHandler VerifySceneBeforeLoading; + + internal readonly Dictionary SceneEventProgressTracking = new Dictionary(); /// @@ -189,6 +205,34 @@ internal NetworkSceneManager(NetworkManager networkManager) ClientSynchEventData = new SceneEventData(networkManager); } + /// + /// If the VerifySceneBeforeLoading delegate handler has been set by the user, this will provides + /// an additional level of security and/or validation that the scene being loaded in the specified + /// loading mode is "a valid scene to be loaded in the LoadSceneMode specified". + /// + /// Build Settings Scenes in Build List index of the scene + /// Name of the scene + /// LoadSceneMode the scene is going to be loaded + /// true (Valid) or false (Invalid) + internal bool ValidateSceneBeforeLoading(uint sceneIndex, string sceneName, LoadSceneMode loadSceneMode) + { + var validated = true; + if (VerifySceneBeforeLoading != null) + { + validated = VerifySceneBeforeLoading.Invoke((int)sceneIndex, sceneName, loadSceneMode); + } + if (!validated) + { + var serverHostorClient = "Client"; + if (m_NetworkManager.IsServer) + { + serverHostorClient = m_NetworkManager.IsHost ? "Host" : "Server"; + } + Debug.LogWarning($"Scene {sceneName} of Scenes in Build Index {SceneEventData.SceneIndex} being loaded in {loadSceneMode.ToString()} mode failed validation on the {serverHostorClient}!"); + } + return validated; + } + /// /// Since SceneManager.GetSceneByName only returns the first scene that matches the name /// we must "find" a newly added scene by looking through all loaded scenes and determining @@ -306,69 +350,64 @@ private void SendSceneEventData(ulong[] targetClientIds) } /// - /// Returns the Netcode scene index from a scene + /// Verifies the scene name is valid relative to the scenes in build list /// - /// - /// Netcode Scene Index - private uint GetNetcodeSceneIndexFromScene(Scene scene) + /// + /// true (Valid) or false (Invalid) + internal bool IsSceneNameValid(string sceneName) { - uint index = 0; - if (!SceneNameToIndex.TryGetValue(scene.name, out index)) + if (m_NetworkManager.ScenesInBuild.Scenes.Contains(sceneName)) { - if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) - { - NetworkLog.LogWarning($"The current scene ({scene.name}) is not registered as a network scene."); - } - //MaxValue denotes an error - return uint.MaxValue; + return true; } - return index; + return false; } /// - /// Returns the scene name from the Netcode scene index - /// Note: This is not the same as the Build Settings Scenes in Build index + /// Used to determine if the index value is within the range of valid + /// build indices. /// - /// Netcode Scene Index - /// scene name - private string GetSceneNameFromNetcodeSceneIndex(uint sceneIndex) + /// index value to check + /// true (Valid) or false (Invalid) + internal bool IsSceneIndexValid(uint index) + { + return (index >= 0 && index < m_NetworkManager.ScenesInBuild.Scenes.Count); + } + + /// + /// Gets the build Index value for the scene name + /// + /// scene name + /// build index + internal uint GetBuildIndexFromSceneName(string sceneName) { - var sceneName = string.Empty; - if (!SceneIndexToString.TryGetValue(sceneIndex, out sceneName)) + if (IsSceneNameValid(sceneName)) { - if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) - { - NetworkLog.LogWarning($"The current scene index ({sceneIndex}) is not registered as a network scene."); - } + return (uint)m_NetworkManager.ScenesInBuild.Scenes.IndexOf(sceneName); } - return sceneName; + return uint.MaxValue; } /// - /// Adds a scene during runtime. - /// The index is REQUIRED to be unique AND the same across all instances. + /// Gets the scene name from the build index /// - /// Scene name. - /// Index. - public void AddRuntimeSceneName(string sceneName, uint index) + /// build index + /// scene name + internal string GetSceneNameFromBuildIndex(uint buildIndex) { - if (!m_NetworkManager.NetworkConfig.AllowRuntimeSceneChanges) + if (IsSceneIndexValid(buildIndex)) { - throw new NetworkConfigurationException($"Cannot change the scene configuration when {nameof(NetworkConfig.AllowRuntimeSceneChanges)} is false"); + return m_NetworkManager.ScenesInBuild.Scenes[(int)buildIndex]; } - - RegisteredSceneNames.Add(sceneName); - SceneIndexToString.Add(index, sceneName); - SceneNameToIndex.Add(sceneName, index); + return string.Empty; } /// - /// Validates the new scene event request by the server-side code. - /// This also initializes some commonly shared values as well as SceneEventProgress + /// Entry method for scene unloading validation /// - /// - /// that should have a of otherwise it failed. - private SceneEventProgress ValidateServerSceneEvent(string sceneName, bool isUnloading = false) + /// the scene to be unloaded + /// + private SceneEventProgress ValidateSceneEventUnLoading(Scene scene) { if (!m_NetworkManager.IsServer) { @@ -383,6 +422,43 @@ private SceneEventProgress ValidateServerSceneEvent(string sceneName, bool isUnl $"{nameof(NetworkSceneManager.LoadScene)} or {nameof(NetworkSceneManager.UnloadScene)}."); } + if (!scene.isLoaded) + { + Debug.LogWarning($"{nameof(UnloadScene)} was called, but the scene {scene.name} is not currently loaded!"); + return new SceneEventProgress(null, SceneEventProgressStatus.SceneNotLoaded); + } + + return ValidateSceneEvent(scene.name, true); + } + + /// + /// Entry method for scene loading validation + /// + /// scene name to load + /// + private SceneEventProgress ValidateSceneEventLoading(string sceneName) + { + if (!m_NetworkManager.IsServer) + { + throw new NotServerException("Only server can start a scene event!"); + } + if (!m_NetworkManager.NetworkConfig.EnableSceneManagement) + { + //Log message about enabling SceneManagement + throw new Exception($"{nameof(NetworkConfig.EnableSceneManagement)} flag is not enabled in the {nameof(NetworkManager)}'s {nameof(NetworkConfig)}. Please set {nameof(NetworkConfig.EnableSceneManagement)} flag to true before calling this method."); + } + + return ValidateSceneEvent(sceneName); + } + + /// + /// Validates the new scene event request by the server-side code. + /// This also initializes some commonly shared values as well as SceneEventProgress + /// + /// + /// that should have a of otherwise it failed. + private SceneEventProgress ValidateSceneEvent(string sceneName, bool isUnloading = false) + { // Return scene event already in progress if one is already in progress... :) if (s_IsSceneEventActive) { @@ -390,7 +466,7 @@ private SceneEventProgress ValidateServerSceneEvent(string sceneName, bool isUnl } // Return invalid scene name status if the scene name is invalid... :) - if (!RegisteredSceneNames.Contains(sceneName)) + if (!IsSceneNameValid(sceneName)) { return new SceneEventProgress(null, SceneEventProgressStatus.InvalidSceneName); } @@ -431,7 +507,7 @@ private bool OnSceneEventProgressCompleted(SceneEventProgress sceneEventProgress using (var nonNullContext = (InternalCommandContext)context) { ClientSynchEventData.SceneEventGuid = sceneEventProgress.Guid; - ClientSynchEventData.SceneIndex = SceneNameToIndex[sceneEventProgress.SceneName]; + ClientSynchEventData.SceneIndex = GetBuildIndexFromSceneName(sceneEventProgress.SceneName); ClientSynchEventData.SceneEventType = sceneEventProgress.SceneEventType; ClientSynchEventData.ClientsCompleted = sceneEventProgress.DoneClients; ClientSynchEventData.ClientsTimedOut = m_NetworkManager.ConnectedClients.Keys.Except(sceneEventProgress.DoneClients).ToList(); @@ -472,7 +548,7 @@ public SceneEventProgressStatus UnloadScene(Scene scene) return SceneEventProgressStatus.SceneNotLoaded; } - var sceneEventProgress = ValidateServerSceneEvent(sceneName, true); + var sceneEventProgress = ValidateSceneEventUnLoading(scene); if (sceneEventProgress.Status != SceneEventProgressStatus.Started) { return sceneEventProgress.Status; @@ -486,7 +562,7 @@ public SceneEventProgressStatus UnloadScene(Scene scene) SceneEventData.SceneEventGuid = sceneEventProgress.Guid; SceneEventData.SceneEventType = SceneEventData.SceneEventTypes.S2C_Unload; - SceneEventData.SceneIndex = SceneNameToIndex[sceneName]; + SceneEventData.SceneIndex = GetBuildIndexFromSceneName(sceneName); SceneEventData.SceneHandle = sceneHandle; // This will be the message we send to everyone when this scene event sceneEventProgress is complete @@ -518,7 +594,7 @@ public SceneEventProgressStatus UnloadScene(Scene scene) /// private void OnClientUnloadScene() { - var sceneName = GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex); + var sceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex); if (sceneName == string.Empty) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) @@ -531,7 +607,7 @@ private void OnClientUnloadScene() if (!ServerSceneHandleToClientSceneHandle.ContainsKey(SceneEventData.SceneHandle)) { - throw new Exception($"Client failed to unload scene {GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex)} " + + throw new Exception($"Client failed to unload scene {GetSceneNameFromBuildIndex(SceneEventData.SceneIndex)} " + $"because we are missing the client scene handle due to the server scene handle {SceneEventData.SceneHandle} not being found!"); } @@ -540,7 +616,7 @@ private void OnClientUnloadScene() if (!ScenesLoaded.ContainsKey(sceneHandle)) { // Error scene handle not found! - throw new Exception($"Client failed to unload scene {GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex)} " + + throw new Exception($"Client failed to unload scene {GetSceneNameFromBuildIndex(SceneEventData.SceneIndex)} " + $"because the client scene handle {sceneHandle} was not found in ScenesLoaded!"); } s_IsSceneEventActive = true; @@ -612,7 +688,7 @@ private void OnSceneUnloaded() { SceneEventType = SceneEventData.SceneEventType, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex), + SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), ClientId = m_NetworkManager.IsServer ? m_NetworkManager.ServerClientId : m_NetworkManager.LocalClientId }); @@ -662,7 +738,7 @@ internal void UnloadAdditivelyLoadedScenes() /// ( means it was successful) public SceneEventProgressStatus LoadScene(string sceneName, LoadSceneMode loadSceneMode) { - var sceneEventProgress = ValidateServerSceneEvent(sceneName); + var sceneEventProgress = ValidateSceneEventLoading(sceneName); if (sceneEventProgress.Status != SceneEventProgressStatus.Started) { return sceneEventProgress.Status; @@ -675,9 +751,16 @@ public SceneEventProgressStatus LoadScene(string sceneName, LoadSceneMode loadSc // Now set up the current scene event SceneEventData.SceneEventGuid = sceneEventProgress.Guid; SceneEventData.SceneEventType = SceneEventData.SceneEventTypes.S2C_Load; - SceneEventData.SceneIndex = SceneNameToIndex[sceneName]; + SceneEventData.SceneIndex = GetBuildIndexFromSceneName(sceneName); SceneEventData.LoadSceneMode = loadSceneMode; + // This both checks to make sure the scene is valid and if not resets the active scene event + s_IsSceneEventActive = ValidateSceneBeforeLoading(SceneEventData.SceneIndex, sceneName, loadSceneMode); + if (!s_IsSceneEventActive) + { + return SceneEventProgressStatus.SceneFailedVerification; + } + if (SceneEventData.LoadSceneMode == LoadSceneMode.Single) { // Destroy current scene objects before switching. @@ -716,13 +799,20 @@ public SceneEventProgressStatus LoadScene(string sceneName, LoadSceneMode loadSc /// Stream data associated with the event private void OnClientSceneLoadingEvent(Stream objectStream) { - if (!SceneIndexToString.TryGetValue(SceneEventData.SceneIndex, out string sceneName) || !RegisteredSceneNames.Contains(sceneName)) + var sceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex); + + if (sceneName == string.Empty) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) { NetworkLog.LogWarning("Server requested a scene switch to a non-registered scene"); } + return; + } + // Run scene validation before loading a scene + if (!ValidateSceneBeforeLoading(SceneEventData.SceneIndex, sceneName, SceneEventData.LoadSceneMode)) + { return; } @@ -746,7 +836,7 @@ private void OnClientSceneLoadingEvent(Stream objectStream) } else { - throw new Exception($"Could not find the scene handle {SceneEventData.SceneHandle} for scene {GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex)} " + + throw new Exception($"Could not find the scene handle {SceneEventData.SceneHandle} for scene {GetSceneNameFromBuildIndex(SceneEventData.SceneIndex)} " + $"during unit test. Did you forget to register this in the unit test?"); } return; @@ -892,7 +982,7 @@ private void OnServerLoadedScene(Scene scene) { SceneEventType = SceneEventData.SceneEventTypes.C2S_LoadComplete, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex), + SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), ClientId = m_NetworkManager.ServerClientId, Scene = scene, }); @@ -921,7 +1011,7 @@ private void OnClientLoadedScene(Scene scene) { SceneEventType = SceneEventData.SceneEventTypes.C2S_LoadComplete, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex), + SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), ClientId = m_NetworkManager.LocalClientId, Scene = scene, }); @@ -951,7 +1041,7 @@ internal void SynchronizeNetworkObjects(ulong clientId) { var scene = SceneManager.GetSceneAt(i); - var sceneIndex = GetNetcodeSceneIndexFromScene(scene); + var sceneIndex = GetBuildIndexFromSceneName(scene.name); if (sceneIndex == uint.MaxValue) { @@ -996,19 +1086,25 @@ private void OnClientBeginSync() { var sceneIndex = SceneEventData.GetNextSceneSynchronizationIndex(); var sceneHandle = SceneEventData.GetNextSceneSynchronizationHandle(); - if (!SceneIndexToString.TryGetValue(sceneIndex, out string sceneName) || !RegisteredSceneNames.Contains(sceneName)) + var sceneName = GetSceneNameFromBuildIndex(sceneIndex); + if (sceneName == string.Empty) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) { NetworkLog.LogWarning("Server requested a scene switch to a non-registered scene"); } - return; } var activeScene = SceneManager.GetActiveScene(); var loadSceneMode = sceneIndex == SceneEventData.SceneIndex ? SceneEventData.LoadSceneMode : LoadSceneMode.Additive; + // Always check to see if the scene needs to be validated + if (!ValidateSceneBeforeLoading(SceneEventData.SceneIndex, sceneName, loadSceneMode)) + { + return; + } + // If this is the beginning of the synchronization event, then send client a notification that synchronization has begun if (sceneIndex == SceneEventData.SceneIndex) { @@ -1073,7 +1169,7 @@ private void OnClientBeginSync() /// Netcode scene index that was loaded private void ClientLoadedSynchronization(uint sceneIndex, int sceneHandle) { - var sceneName = GetSceneNameFromNetcodeSceneIndex(sceneIndex); + var sceneName = GetSceneNameFromBuildIndex(sceneIndex); var nextScene = GetAndAddNewlyLoadedSceneByName(sceneName); if (!nextScene.isLoaded || !nextScene.IsValid()) @@ -1195,7 +1291,7 @@ private void HandleClientSceneEvent(Stream stream) OnSceneEvent?.Invoke(new SceneEvent() { SceneEventType = SceneEventData.SceneEventType, - SceneName = GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex), + SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), ClientId = m_NetworkManager.ServerClientId, LoadSceneMode = SceneEventData.LoadSceneMode, ClientsThatCompleted = SceneEventData.ClientsCompleted, @@ -1228,7 +1324,7 @@ private void HandleServerSceneEvent(ulong clientId, Stream stream) { SceneEventType = SceneEventData.SceneEventType, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex), + SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), ClientId = clientId }); @@ -1250,7 +1346,7 @@ private void HandleServerSceneEvent(ulong clientId, Stream stream) { SceneEventType = SceneEventData.SceneEventType, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromNetcodeSceneIndex(SceneEventData.SceneIndex), + SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), ClientId = clientId }); diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta index 273da91fcf..59d1b2bf9e 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta @@ -1,6 +1,6 @@ fileFormatVersion: 2 <<<<<<< HEAD:testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneToggleHandler.cs.meta -guid: 475de064003ff104fb88b1fbccd0f417 +guid: 66f377a54b543fa43ac0b24e758caeff ======= guid: 6e6dff048b3e7e84b9535cdb6517cf39 >>>>>>> feat/scenesinbuild-mlapi-sceneregistration:com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs index 3b32321098..adaf7890b0 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs @@ -171,7 +171,6 @@ public void NetworkObjectSceneSerializationFailure() [SetUp] public void Setup() { - NetworkSceneManager.IsUnitTesting = true; // Create, instantiate, and host NetworkManagerHelper.StartNetworkManager(out NetworkManager networkManager, NetworkManagerHelper.NetworkManagerOperatingMode.None); networkManager.NetworkConfig.EnableSceneManagement = true; @@ -182,7 +181,6 @@ public void Setup() [TearDown] public void TearDown() { - NetworkSceneManager.IsUnitTesting = false; // Stop, shutdown, and destroy NetworkManagerHelper.ShutdownNetworkManager(); } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index 8d2036e6bb..234a5f9317 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -44,7 +44,6 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode) public IEnumerator Setup() { ScenesInBuild.IsTesting = true; - NetworkSceneManager.IsUnitTesting = true; SceneManager.sceneLoaded += OnSceneLoaded; var execAssembly = Assembly.GetExecutingAssembly(); @@ -199,7 +198,6 @@ public void SetupSet(Transform rootTransform, int setIndex, NetworkManager netwo [UnityTearDown] public IEnumerator Teardown() { - NetworkSceneManager.IsUnitTesting = false; ScenesInBuild.IsTesting = false; SceneManager.sceneLoaded -= OnSceneLoaded; diff --git a/testproject/Assets/Prefabs/RandomMoverObject.prefab b/testproject/Assets/Prefabs/RandomMoverObject.prefab index 852d8d0059..44665854b4 100644 --- a/testproject/Assets/Prefabs/RandomMoverObject.prefab +++ b/testproject/Assets/Prefabs/RandomMoverObject.prefab @@ -146,7 +146,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: e96cb6065543e43c4a752faaa1468eb1, type: 3} m_Name: m_EditorClassIdentifier: - Authority: 2 Channel: 0 InLocalSpace: 0 SyncPositionX: 1 @@ -158,6 +157,9 @@ MonoBehaviour: SyncScaleX: 1 SyncScaleY: 1 SyncScaleZ: 1 + PositionThreshold: 0 + RotAngleThreshold: 0 + ScaleThreshold: 0 FixedSendsPerSecond: 5 --- !u!114 &1932194183178713890 MonoBehaviour: @@ -168,7 +170,7 @@ MonoBehaviour: m_GameObject: {fileID: 771575417923360811} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: c552ef0ccf6ff8148a9c9606e7d3fc15, type: 3} + m_Script: {fileID: 11500000, guid: c4152da5a2f4e7746aecdcd815f6616b, type: 3} m_Name: m_EditorClassIdentifier: --- !u!1 &2058396567867412356 From 473ab82644d78454ca48fce2b8ad727ec6796f04 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 23 Aug 2021 18:36:46 -0500 Subject: [PATCH 03/20] fix missed an exception message update. --- .../Runtime/SceneManagement/NetworkSceneManager.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 34e22d5a0e..c96d14c8ea 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -445,7 +445,9 @@ private SceneEventProgress ValidateSceneEventLoading(string sceneName) if (!m_NetworkManager.NetworkConfig.EnableSceneManagement) { //Log message about enabling SceneManagement - throw new Exception($"{nameof(NetworkConfig.EnableSceneManagement)} flag is not enabled in the {nameof(NetworkManager)}'s {nameof(NetworkConfig)}. Please set {nameof(NetworkConfig.EnableSceneManagement)} flag to true before calling this method."); + throw new Exception($"{nameof(NetworkConfig.EnableSceneManagement)} flag is not enabled in the {nameof(NetworkManager)}'s {nameof(NetworkConfig)}. " + + $"Please set {nameof(NetworkConfig.EnableSceneManagement)} flag to true before calling " + + $"{nameof(NetworkSceneManager.LoadScene)} or {nameof(NetworkSceneManager.UnloadScene)}."); } return ValidateSceneEvent(sceneName); From 38a6092ebd6d5b45f2e6db3b99c66c14e31240a3 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 23 Aug 2021 19:28:49 -0500 Subject: [PATCH 04/20] refactor and fix This includes scene verification in the synchronization process [refactor]. This also includes unit test modifications for the NetworkObjectParentingTests to assure we don't try to reload the unit test temporary scene and moves the client connected and disconnected event handler subscription removal into the OnNetworkDespawn. --- .../SceneManagement/NetworkSceneManager.cs | 8 ++++++++ .../NetworkObjectParentingTests.cs | 18 +++++++++++++++++- .../HybridScripts/RpcQueueManualTests.cs | 5 +++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index c96d14c8ea..2f49800a35 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -1053,9 +1053,17 @@ internal void SynchronizeNetworkObjects(ulong clientId) // If we are the base scene, then we set the root scene index; if (activeScene == scene) { + if(!ValidateSceneBeforeLoading(sceneIndex, scene.name, LoadSceneMode.Single)) + { + continue; + } ClientSynchEventData.SceneIndex = sceneIndex; ClientSynchEventData.SceneHandle = scene.handle; } + else if (!ValidateSceneBeforeLoading(sceneIndex, scene.name, LoadSceneMode.Additive)) + { + continue; + } ClientSynchEventData.AddSceneToSynchronize(sceneIndex, scene.handle); } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index 234a5f9317..fb044661d7 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -40,6 +40,15 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode) } } + private bool VerifySceneBeforeLoading(int sceneIndex, string sceneName, LoadSceneMode loadSceneMode) + { + if(sceneName.StartsWith("InitTestScene")) + { + return false; + } + return true; + } + [UnitySetUp] public IEnumerator Setup() { @@ -62,7 +71,7 @@ public IEnumerator Setup() Assert.That(m_ClientNetworkManagers, Is.Not.Null); Assert.That(m_ClientNetworkManagers.Length, Is.EqualTo(k_ClientInstanceCount)); m_ServerNetworkManager.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); - foreach(var entry in m_ClientNetworkManagers) + foreach (var entry in m_ClientNetworkManagers) { if(!m_ServerNetworkManager.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) { @@ -96,6 +105,13 @@ public IEnumerator Setup() // Start server and client NetworkManager instances Assert.That(MultiInstanceHelpers.Start(true, m_ServerNetworkManager, m_ClientNetworkManagers)); + // Register our scene verification delegate handler so we don't load the unit test scene + m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = VerifySceneBeforeLoading; + for (int setIndex = 0; setIndex < k_ClientInstanceCount; setIndex++) + { + m_ClientNetworkManagers[setIndex].SceneManager.VerifySceneBeforeLoading = VerifySceneBeforeLoading; + } + // Wait for connection on client side yield return MultiInstanceHelpers.Run(MultiInstanceHelpers.WaitForClientsConnected(m_ClientNetworkManagers)); diff --git a/testproject/Assets/Tests/Manual/HybridScripts/RpcQueueManualTests.cs b/testproject/Assets/Tests/Manual/HybridScripts/RpcQueueManualTests.cs index a2491102d0..e599b080bb 100644 --- a/testproject/Assets/Tests/Manual/HybridScripts/RpcQueueManualTests.cs +++ b/testproject/Assets/Tests/Manual/HybridScripts/RpcQueueManualTests.cs @@ -333,15 +333,16 @@ public override void OnNetworkSpawn() } /// - /// Unregister for the client connected and disconnected events upon being destroyed + /// Unregister for the client connected and disconnected events upon being despawned /// - private void OnDestroy() + public override void OnNetworkDespawn() { if (IsServer) { NetworkManager.OnClientConnectedCallback -= OnClientConnectedCallback; NetworkManager.OnClientDisconnectCallback -= OnClientDisconnectCallback; } + base.OnNetworkDespawn(); } /// From 9bba5e25b9a56db9b54bfda15cab01d450a7aeb6 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue, 24 Aug 2021 10:35:16 -0500 Subject: [PATCH 05/20] style fixing some standards related issues. --- .../Runtime/Configuration/NetworkConfig.cs | 3 --- testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs index 336a67f150..600073a5ce 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; using UnityEngine; -#if UNITY_EDITOR -using UnityEditor; -#endif using System.Linq; namespace Unity.Netcode diff --git a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs index 3f7a6930bf..18dac102fe 100644 --- a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs +++ b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs @@ -261,7 +261,7 @@ private void SceneManager_OnSceneEvent(SceneEvent sceneEvent) case SceneEventData.SceneEventTypes.S2C_Load: case SceneEventData.SceneEventTypes.S2C_Unload: { - Assert.AreEqual(sceneEvent.SceneName,m_CurrentSceneName); + Assert.AreEqual(sceneEvent.SceneName, m_CurrentSceneName); Assert.IsTrue(ContainsClient(sceneEvent.ClientId)); Assert.IsNotNull(sceneEvent.AsyncOperation); break; @@ -331,7 +331,7 @@ private bool ClientVerifySceneBeforeLoading(int sceneIndex, string sceneName, Lo Assert.IsTrue(m_ExpectedSceneIndex == sceneIndex); Assert.IsTrue(m_ExpectedSceneName == sceneName); Assert.IsTrue(m_ExpectedLoadMode == loadSceneMode); - if(!m_ClientVerifyScene) + if (!m_ClientVerifyScene) { m_ClientsThatFailedVerification++; } From 0948ff6cb1d4d923edd6fd428bd43d6534d71af1 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue, 24 Aug 2021 15:32:30 -0500 Subject: [PATCH 06/20] refactor Refactoring scenes in build and unit testing. --- .../Runtime/SceneManagement/ScenesInBuild.cs | 36 ++++++++++++++----- .../NetworkManagerMessageHandlerTests.cs | 3 -- .../NetworkPrefabGlobalObjectIdHashTests.cs | 2 -- .../Runtime/Helpers/NetworkManagerHelper.cs | 2 -- .../Tests/Runtime/MultiInstanceHelpers.cs | 1 - .../NetworkObjectParentingTests.cs | 7 ++-- .../Runtime/MultiClientConnectionApproval.cs | 2 -- 7 files changed, 32 insertions(+), 21 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs index 9e5c3c3f8a..4033458cd2 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs @@ -18,13 +18,28 @@ namespace Unity.Netcode /// public class ScenesInBuild : ScriptableObject { - static internal bool IsTesting; + [HideInInspector] [SerializeField] internal List Scenes; + + private bool IsRunningUnitTest() + { +#if UNITY_EDITOR + if (!EditorApplication.isPlaying) + { + return false; + } +#endif + // For scenes in build, we have to check whether we are running a unit test or not each time + return SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); + } + + #if UNITY_EDITOR + /// /// This will create a new ScenesInBuildList asset if one does not exist and will adjust the path to the ScenesInBuildList /// asset if the asset is moved. This will also notify the user if more than one ScenesInBuildList asset exists. @@ -50,7 +65,7 @@ internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkMana networkManager.DefaultScenesInBuildAssetNameAndPath = AssetDatabase.GUIDToAssetPath(foundScenesInBuildList[0]); } var scenesInBuild = (ScenesInBuild)AssetDatabase.LoadAssetAtPath(networkManager.DefaultScenesInBuildAssetNameAndPath, typeof(ScenesInBuild)); - if(scenesInBuild == null) + if (scenesInBuild == null) { scenesInBuild = CreateInstance(); AssetDatabase.CreateAsset(scenesInBuild, networkManager.DefaultScenesInBuildAssetNameAndPath); @@ -64,30 +79,35 @@ internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkMana /// internal void PopulateScenesInBuild() { - if(Scenes != null && Scenes.Count > 0 && IsTesting) + var isRunningUnitTest = IsRunningUnitTest(); + if (Scenes != null && Scenes.Count > 0 && isRunningUnitTest) { return; } Scenes = new List(); for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) { - if(IsTesting && i >= EditorBuildSettings.scenes.Length) + + if (isRunningUnitTest && i >= EditorBuildSettings.scenes.Length) { - continue; + break; } var scene = EditorBuildSettings.scenes[i]; var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); Scenes.Add(sceneAsset.name); } - AssetDatabase.SaveAssets(); + if (!isRunningUnitTest) + { + AssetDatabase.SaveAssets(); + } } /// - /// Depending upon the current editor state, this will refresh the Scenes in Build list + /// Depending upon the current editor state or if we are running a unit test or not, this will refresh the Scenes in Build list /// private void OnValidate() { - if (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating || IsTesting) + if (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating || IsRunningUnitTest()) { PopulateScenesInBuild(); } diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs index 7eca8311c4..8226a20cb8 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs @@ -13,7 +13,6 @@ public class NetworkManagerMessageHandlerTests [Test] public void MessageHandlerReceivedMessageServerClient() { - ScenesInBuild.IsTesting = true; // Init var gameObject = new GameObject(nameof(MessageHandlerReceivedMessageServerClient)); var networkManager = gameObject.AddComponent(); @@ -246,8 +245,6 @@ public void MessageHandlerReceivedMessageServerClient() // Full cleanup networkManager.StopClient(); - - ScenesInBuild.IsTesting = false; } // Ensure no missmatches with expectations diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs index 2cfedb249e..556be87c37 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/GlobalObjectIdHash/NetworkPrefabGlobalObjectIdHashTests.cs @@ -25,7 +25,6 @@ private void OnSceneLoaded(Scene scene, LoadSceneMode mode) [UnitySetUp] public IEnumerator Setup() { - ScenesInBuild.IsTesting = true; SceneManager.sceneLoaded += OnSceneLoaded; var execAssembly = Assembly.GetExecutingAssembly(); @@ -38,7 +37,6 @@ public IEnumerator Setup() [UnityTearDown] public IEnumerator Teardown() { - ScenesInBuild.IsTesting = false; SceneManager.sceneLoaded -= OnSceneLoaded; if (m_TestScene.isLoaded) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs index 8bb53dd583..07214a021b 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs @@ -51,7 +51,6 @@ public enum NetworkManagerOperatingMode /// true if it was instantiated or is already instantiate otherwise false means it failed to instantiate public static bool StartNetworkManager(out NetworkManager networkManager, NetworkManagerOperatingMode managerMode = NetworkManagerOperatingMode.Host, NetworkConfig networkConfig = null) { - ScenesInBuild.IsTesting = true; // If we are changing the current manager mode and the current manager mode is not "None", then stop the NetworkManager mode if (CurrentNetworkManagerMode != managerMode && CurrentNetworkManagerMode != NetworkManagerOperatingMode.None) { @@ -232,7 +231,6 @@ private static void StopNetworkManagerMode() // This is called, even if we assert and exit early from a test public static void ShutdownNetworkManager() { - ScenesInBuild.IsTesting = false; // clean up any game objects created with custom unit testing components foreach (var entry in InstantiatedGameObjects) { diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs index 2687d30421..81f3c24982 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs @@ -31,7 +31,6 @@ public static class MultiInstanceHelpers public static bool Create(int clientCount, out NetworkManager server, out NetworkManager[] clients, int targetFrameRate = 60) { s_NetworkManagerInstances = new List(); - ScenesInBuild.IsTesting = true; CreateNewClients(clientCount, out clients); // Create gameObject diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index fb044661d7..2b7c60b923 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -52,9 +52,12 @@ private bool VerifySceneBeforeLoading(int sceneIndex, string sceneName, LoadScen [UnitySetUp] public IEnumerator Setup() { - ScenesInBuild.IsTesting = true; SceneManager.sceneLoaded += OnSceneLoaded; + // We need NetworkManager to be instantiated first before you load scenes externally in order to be able to determine if + // we are running a unit test or not. (it is this or manually setting a property) + Assert.That(MultiInstanceHelpers.Create(k_ClientInstanceCount, out m_ServerNetworkManager, out m_ClientNetworkManagers)); + var execAssembly = Assembly.GetExecutingAssembly(); var packagePath = PackageInfo.FindForAssembly(execAssembly).assetPath; var scenePath = Path.Combine(packagePath, $"Tests/Runtime/ObjectParenting/{nameof(NetworkObjectParentingTests)}.unity"); @@ -66,7 +69,6 @@ public IEnumerator Setup() const int setCount = k_ClientInstanceCount + 1; - Assert.That(MultiInstanceHelpers.Create(k_ClientInstanceCount, out m_ServerNetworkManager, out m_ClientNetworkManagers)); Assert.That(m_ServerNetworkManager, Is.Not.Null); Assert.That(m_ClientNetworkManagers, Is.Not.Null); Assert.That(m_ClientNetworkManagers.Length, Is.EqualTo(k_ClientInstanceCount)); @@ -214,7 +216,6 @@ public void SetupSet(Transform rootTransform, int setIndex, NetworkManager netwo [UnityTearDown] public IEnumerator Teardown() { - ScenesInBuild.IsTesting = false; SceneManager.sceneLoaded -= OnSceneLoaded; MultiInstanceHelpers.Destroy(); diff --git a/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs b/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs index f002e4d745..da85f8b9ab 100644 --- a/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs +++ b/testproject/Assets/Tests/Runtime/MultiClientConnectionApproval.cs @@ -52,7 +52,6 @@ public IEnumerator ConnectionApprovalPrefabOverride() /// private IEnumerator ConnectionApprovalHandler(int numClients, int failureTestCount = 1, bool prefabOverride = false) { - ScenesInBuild.IsTesting = true; var startFrameCount = Time.frameCount; var startTime = Time.realtimeSinceStartup; @@ -185,7 +184,6 @@ private void ConnectionApprovalCallback(byte[] connectionData, ulong clientId, N [TearDown] public void TearDown() { - ScenesInBuild.IsTesting = false; if (m_PlayerPrefab != null) { Object.Destroy(m_PlayerPrefab); From 908b5472ea4276da977eb828066155cf12d1a741 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue, 24 Aug 2021 15:34:42 -0500 Subject: [PATCH 07/20] refactor moving the unit test check --- .../Runtime/SceneManagement/ScenesInBuild.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs index 4033458cd2..5eda9691a6 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs @@ -18,28 +18,21 @@ namespace Unity.Netcode /// public class ScenesInBuild : ScriptableObject { - - [HideInInspector] [SerializeField] internal List Scenes; - +#if UNITY_EDITOR private bool IsRunningUnitTest() { -#if UNITY_EDITOR if (!EditorApplication.isPlaying) { return false; } -#endif // For scenes in build, we have to check whether we are running a unit test or not each time return SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); } - -#if UNITY_EDITOR - /// /// This will create a new ScenesInBuildList asset if one does not exist and will adjust the path to the ScenesInBuildList /// asset if the asset is moved. This will also notify the user if more than one ScenesInBuildList asset exists. From d766225ce965834c1def0cd6042e2c8e5d2dbca8 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue, 24 Aug 2021 17:02:21 -0500 Subject: [PATCH 08/20] refactor This crept back into this branch. Removing this check as it isn't needed any longer. --- com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs index 1d27bdc1cb..9b60dc3862 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs @@ -539,11 +539,7 @@ public void SpawnAsPlayerObject(ulong clientId, bool destroyWithScene = false) /// (true) the will be destroyed (false) the will persist after being despawned public void Despawn(bool destroy = false) { - // An edge case scenario can occur that will throw an exception due to the fact that SpawnManager is null. - if (NetworkManager.SpawnManager != null) - { - NetworkManager.SpawnManager.DespawnObject(this, destroy); - } + NetworkManager.SpawnManager.DespawnObject(this, destroy); } /// From 302806acee817ad7c5394df43642b68cd052f2c3 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Tue, 24 Aug 2021 17:08:59 -0500 Subject: [PATCH 09/20] style removing minor LF changes which removes these 3 files from the PR. --- .../Tests/Runtime/ConnectionApproval.cs | 1 - .../NetworkObject/NetworkObjectSceneSerializationTests.cs | 1 + testproject/Assets/Tests/Runtime/MessageOrdering.cs | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs index 189f20b4b4..3b48766df3 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ConnectionApproval.cs @@ -59,7 +59,6 @@ private void NetworkManagerObject_ConnectionApprovalCallback(byte[] connectionDa [TearDown] public void TearDown() { - // Stop, shutdown, and destroy NetworkManagerHelper.ShutdownNetworkManager(); } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs index adaf7890b0..6984baf2cc 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSceneSerializationTests.cs @@ -132,6 +132,7 @@ public void NetworkObjectSceneSerializationFailure() invalidNetworkObjectCount++; } + NetworkManagerHelper.NetworkManagerObject.SceneManager.SetTheSceneBeingSynchronized(reader.ReadInt32Packed()); var deserializedNetworkObject = NetworkObject.DeserializeSceneObject(pooledBuffer, reader, NetworkManagerHelper.NetworkManagerObject); diff --git a/testproject/Assets/Tests/Runtime/MessageOrdering.cs b/testproject/Assets/Tests/Runtime/MessageOrdering.cs index d9adab8575..70506cdd08 100644 --- a/testproject/Assets/Tests/Runtime/MessageOrdering.cs +++ b/testproject/Assets/Tests/Runtime/MessageOrdering.cs @@ -167,6 +167,7 @@ public IEnumerator SpawnRpcDespawn([Values] NetworkUpdateStage testStage) var nextFrameNumber = Time.frameCount + 1; yield return new WaitUntil(() => Time.frameCount >= nextFrameNumber); } + Assert.AreEqual(testStage, Support.SpawnRpcDespawn.StageExecutedByReceiver); Assert.AreEqual(Support.SpawnRpcDespawn.ServerUpdateCount, Support.SpawnRpcDespawn.ClientUpdateCount); Assert.True(handler.WasSpawned); From 7825b5577e20c58035941606712d84368a8cc0c6 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 27 Aug 2021 12:12:43 -0500 Subject: [PATCH 10/20] fix missed a parenthesis removal. --- .../Runtime/SceneManagement/NetworkSceneManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 7a21e6048b..6e3600a4db 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -504,7 +504,7 @@ private bool OnSceneEventProgressCompleted(SceneEventProgress sceneEventProgress var context = m_NetworkManager.MessageQueueContainer.EnterInternalCommandContext(k_MessageType, k_ChannelType, m_NetworkManager.ConnectedClientsIds, k_NetworkUpdateStage); if (context != null) { - using var nonNullContext = (InternalCommandContext)context); + using var nonNullContext = (InternalCommandContext)context; ClientSynchEventData.SceneEventGuid = sceneEventProgress.Guid; ClientSynchEventData.SceneIndex = GetBuildIndexFromSceneName(sceneEventProgress.SceneName); ClientSynchEventData.SceneEventType = sceneEventProgress.SceneEventType; From 734d3622c0b941327a07d6abcf6e4607d09e8cc6 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 27 Aug 2021 17:14:42 -0500 Subject: [PATCH 11/20] refactor Removed ScenesInBuild populate from NetworkManager. Refactored how we initialize the ScenesInBuild list during unit tests for editor and stand alone. Adjusted all unit and integration tests to the above modifications. --- .../Runtime/Core/NetworkManager.cs | 28 +-- .../Runtime/SceneManagement/ScenesInBuild.cs | 177 ++++++++++++++++-- ...NetworkManagerCustomMessageManagerTests.cs | 4 +- .../NetworkManagerMessageHandlerTests.cs | 4 +- .../Editor/NetworkManagerSceneManagerTests.cs | 4 +- .../Runtime/Helpers/NetworkManagerHelper.cs | 5 +- .../Tests/Runtime/MultiInstanceHelpers.cs | 10 +- .../Runtime/NetworkPrefabHandlerTests.cs | 8 +- .../NetworkObjectParentingTests.cs | 24 ++- .../SceneEventNotificationQueue.cs | 24 ++- .../Manual/Scripts/PlayerMovementManager.cs | 23 ++- ...dUpdateMessagesAreOnlyProcessedOnceTest.cs | 4 +- .../Tests/Runtime/NetworkSceneManagerTests.cs | 4 +- 13 files changed, 228 insertions(+), 91 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index a608be85d2..094d56f0a5 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -263,31 +263,6 @@ internal void InvokeConnectionApproval(byte[] payload, ulong clientId, Connectio #if UNITY_EDITOR - /// - /// Assures the ScenesInBuild asset exists and that it is always up to date - /// - /// - internal void PopulateScenesInBuild(bool isTesting = false) - { - // If we are testing or we are playing (in editor) and ScenesInBuild is null then we want to initialize and populate the ScenesInBuild asset. - // Otherwise, there are special edge case scenarios where we might want to repopulate this list - // The scenario with EditorApplication.isPlaying and ScenesInBuild being null is where we loaded a scene that did not have a NetworkManager but - // we transition to a scene with a NetworkManager while playing in the editor. Under this condition we have to assign and populate. - if ( (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating) || isTesting - || ( (ScenesInBuild == null || ScenesInBuild != null && ScenesInBuild.Scenes.Count == 0) && EditorApplication.isPlaying)) - { - if (ScenesInBuild == null) - { - ScenesInBuild = ScenesInBuild.InitializeScenesInBuild(this); - ScenesInBuild.PopulateScenesInBuild(); - } - else - { - ScenesInBuild.PopulateScenesInBuild(); - } - } - } - private void OnValidate() { if (NetworkConfig == null) @@ -295,7 +270,7 @@ private void OnValidate() return; // May occur when the component is added } - PopulateScenesInBuild(); + ScenesInBuild.SynchronizeOrCreate(this); if (GetComponentInChildren() != null) { @@ -487,7 +462,6 @@ private void Initialize(bool server) // Always clear our prefab override links before building NetworkConfig.NetworkPrefabOverrideLinks.Clear(); - // Build the NetworkPrefabOverrideLinks dictionary // Build the NetworkPrefabOverrideLinks dictionary for (int i = 0; i < NetworkConfig.NetworkPrefabs.Count; i++) { diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs index 5eda9691a6..5a42dd417e 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs @@ -18,19 +18,105 @@ namespace Unity.Netcode /// public class ScenesInBuild : ScriptableObject { - [HideInInspector] + //[HideInInspector] [SerializeField] internal List Scenes; -#if UNITY_EDITOR - private bool IsRunningUnitTest() +#if UNITY_EDITOR || DEVELOPMENT_BUILD + + /// + /// Determines if we are running a unit test + /// In DEVELOPMENT_BUILD we only check for the InitTestScene + /// + private static bool IsRunningUnitTest() { +#if UNITY_EDITOR if (!EditorApplication.isPlaying) { return false; } +#endif + + var isTesting = SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); + + // For scenes in build, we have to check whether we are running a unit test or not each time - return SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); + return isTesting; + } + + /// + /// Assures the ScenesInBuild asset exists and if in the editor that it is always up to date + /// + internal static void SynchronizeOrCreate(NetworkManager networkManager) + { + var isUnitTestRunning = IsRunningUnitTest(); + +#if UNITY_EDITOR + // If we are testing or we are playing (in editor) and ScenesInBuild is null then we want to initialize and populate the ScenesInBuild asset. + // Otherwise, there are special edge case scenarios where we might want to repopulate this list + // The scenario with EditorApplication.isPlaying and ScenesInBuild being null is where we loaded a scene that did not have a NetworkManager but + // we transition to a scene with a NetworkManager while playing in the editor. Under this condition we have to assign and populate. + if ( (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating) || isUnitTestRunning || + ( (networkManager.ScenesInBuild == null || networkManager.ScenesInBuild != null && networkManager.ScenesInBuild.Scenes.Count == 0) && EditorApplication.isPlaying) ) + { + if (networkManager.ScenesInBuild == null) + { + networkManager.ScenesInBuild = InitializeScenesInBuild(networkManager); + } + + networkManager.ScenesInBuild.PopulateScenesInBuild(); + } +#else + + // Only if we are running a stand alone build as for unit or integration testing + if (isUnitTestRunning) + { + if (networkManager.ScenesInBuild == null) + { + networkManager.ScenesInBuild = CreateInstance(); + } + var currentlyActiveSceneName = SceneManager.GetActiveScene().name; + + // If the unit test scene is not already added to the ScenesInBuild + if(!networkManager.ScenesInBuild.Scenes.Contains(currentlyActiveSceneName)) + { + // Then add it into the valid scenes that it can be loaded + networkManager.ScenesInBuild.Scenes.Add(currentlyActiveSceneName); + } + } +#endif + } + + +#if UNITY_EDITOR + + private bool m_CheckHasBeenApplied; + + /// + /// This will add a play mode state change watch to determine when we are done with a unit test + /// in order to re-synchronize our ScenesInBuild asset. + /// + private void CheckForEndOfUnitTest() + { + if (!m_CheckHasBeenApplied) + { + EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; + m_CheckHasBeenApplied = true; + } + } + + /// + /// Check for when we enter into editor mode so we can remove any scenes that might have been added to the + /// scenes list. + /// + private void EditorApplication_playModeStateChanged(PlayModeStateChange obj) + { + if (obj == PlayModeStateChange.EnteredEditMode) + { + EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged; + m_CheckHasBeenApplied = false; + PopulateScenesInBuild(); + } } /// @@ -72,24 +158,80 @@ internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkMana /// internal void PopulateScenesInBuild() { - var isRunningUnitTest = IsRunningUnitTest(); - if (Scenes != null && Scenes.Count > 0 && isRunningUnitTest) + var shouldRebuild = false; + var isTesting = IsRunningUnitTest(); + + // if we have no scenes registered or we have changed the scenes in the build we should rebuild + if (Scenes == null) { - return; + shouldRebuild = true; } - Scenes = new List(); - for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) + else if (!isTesting) { + if (EditorBuildSettings.scenes.Length != Scenes.Count) + { + shouldRebuild = true; + } + else + { + // Verify our order hasn't changed and if it has then we should rebuild + for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) + { + var scene = EditorBuildSettings.scenes[i]; + var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); + // We could either have changed the order or we could have rename something or we could have removed and added + // either case we rebuild if they don't align properly + if (Scenes[i] != sceneAsset.name) + { + shouldRebuild = true; + break; + } + } + } + } + else + if ( Scenes.Count != SceneManager.sceneCountInBuildSettings) + { + shouldRebuild = true; + } - if (isRunningUnitTest && i >= EditorBuildSettings.scenes.Length) + if (shouldRebuild) + { + Scenes = new List(); + if (!isTesting) { - break; + // Normal scenes in build list generation + for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) + { + var scene = EditorBuildSettings.scenes[i]; + var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); + Scenes.Add(sceneAsset.name); + } + } + else + { + CheckForEndOfUnitTest(); + + // This is only for unit or integration testing + for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) + { + // First we make sure we order everything exactly as it is in the build settings + if (EditorBuildSettings.scenes.Length > i) + { + var scene = EditorBuildSettings.scenes[i]; + var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); + Scenes.Add(sceneAsset.name); + } + else // If we are testing then we will just add the remaining scenes into our registered scenes list + if (!Scenes.Contains(SceneManager.GetSceneByBuildIndex(i).name)) + { + Scenes.Add(SceneManager.GetSceneByBuildIndex(i).name); + } + } } - var scene = EditorBuildSettings.scenes[i]; - var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); - Scenes.Add(sceneAsset.name); } - if (!isRunningUnitTest) + + if (!isTesting) { AssetDatabase.SaveAssets(); } @@ -105,6 +247,9 @@ private void OnValidate() PopulateScenesInBuild(); } } -#endif + +#endif // UNITY_EDITOR +#endif // UNITY_EDITOR || DEVELOPMENT_BUILD + } } diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs index 4300faff33..48131038a7 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs @@ -1,6 +1,5 @@ using NUnit.Framework; using UnityEngine; -using UnityEngine.SceneManagement; namespace Unity.Netcode.EditorTests { @@ -13,8 +12,7 @@ public void CustomMessageManagerAssigned() var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - networkManager.PopulateScenesInBuild(true); - networkManager.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + ScenesInBuild.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs index 3adecb5b7b..702d65d24f 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs @@ -2,7 +2,6 @@ using NUnit.Framework; using Unity.Netcode.Editor; using UnityEngine; -using UnityEngine.SceneManagement; using UnityEngine.TestTools; using Object = UnityEngine.Object; @@ -18,8 +17,7 @@ public void MessageHandlerReceivedMessageServerClient() var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - networkManager.PopulateScenesInBuild(true); - networkManager.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + ScenesInBuild.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs index f0a096b029..3143c98ad6 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs @@ -1,6 +1,5 @@ using NUnit.Framework; using UnityEngine; -using UnityEngine.SceneManagement; namespace Unity.Netcode.EditorTests { @@ -12,8 +11,7 @@ public void SceneManagerAssigned() var gameObject = new GameObject(nameof(SceneManagerAssigned)); var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - networkManager.PopulateScenesInBuild(true); - networkManager.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + ScenesInBuild.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs index 07214a021b..f4ad5b13a4 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using UnityEngine; -using UnityEngine.SceneManagement; using NUnit.Framework; using Unity.Netcode.Transports.UNET; @@ -78,9 +77,7 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ EnableSceneManagement = false, }; } - - NetworkManagerObject.PopulateScenesInBuild(true); - NetworkManagerObject.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + ScenesInBuild.SynchronizeOrCreate(NetworkManagerObject); NetworkManagerObject.NetworkConfig = networkConfig; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs index 95cc9fba23..a7c6217364 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs @@ -46,8 +46,7 @@ public static bool Create(int clientCount, out NetworkManager server, out Networ // Set transport NetworkTransport = go.AddComponent() }; - server.PopulateScenesInBuild(true); - server.ScenesInBuild.Scenes.Add(SceneManager.GetActiveScene().name); + ScenesInBuild.SynchronizeOrCreate(server); s_OriginalTargetFrameRate = Application.targetFrameRate; Application.targetFrameRate = targetFrameRate; @@ -79,12 +78,7 @@ public static bool CreateNewClients(int clientCount, out NetworkManager[] client NetworkTransport = go.AddComponent() }; - clients[i].PopulateScenesInBuild(true); - - if (!clients[i].ScenesInBuild.Scenes.Contains(activeSceneName)) - { - clients[i].ScenesInBuild.Scenes.Add(activeSceneName); - } + ScenesInBuild.SynchronizeOrCreate(clients[i]); } NetworkManagerInstances.AddRange(clients); diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkPrefabHandlerTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkPrefabHandlerTests.cs index c4fdcac29f..da1b712051 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkPrefabHandlerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkPrefabHandlerTests.cs @@ -17,13 +17,13 @@ public class NetworkPrefabHandlerTests { private const string k_TestPrefabObjectName = "NetworkPrefabTestObject"; - private uint m_GlobalObjectIdHashBase = 123456; + private uint m_ObjectId = 1; private GameObject MakeValidNetworkPrefab() { - Guid baseObjectID = NetworkManagerHelper.AddGameNetworkObject(k_TestPrefabObjectName + m_GlobalObjectIdHashBase.ToString()); + Guid baseObjectID = NetworkManagerHelper.AddGameNetworkObject(k_TestPrefabObjectName + m_ObjectId.ToString()); NetworkObject validPrefab = NetworkManagerHelper.InstantiatedNetworkObjects[baseObjectID]; - MultiInstanceHelpers.MakeNetworkObjectTestPrefab(validPrefab, m_GlobalObjectIdHashBase); - m_GlobalObjectIdHashBase++; + MultiInstanceHelpers.MakeNetworkObjectTestPrefab(validPrefab); + m_ObjectId++; return validPrefab.gameObject; } diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index 2b7c60b923..89b6722bb0 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -58,6 +58,13 @@ public IEnumerator Setup() // we are running a unit test or not. (it is this or manually setting a property) Assert.That(MultiInstanceHelpers.Create(k_ClientInstanceCount, out m_ServerNetworkManager, out m_ClientNetworkManagers)); + ScenesInBuild.SynchronizeOrCreate(m_ServerNetworkManager); + foreach (var entry in m_ClientNetworkManagers) + { + ScenesInBuild.SynchronizeOrCreate(entry); + } + + var execAssembly = Assembly.GetExecutingAssembly(); var packagePath = PackageInfo.FindForAssembly(execAssembly).assetPath; var scenePath = Path.Combine(packagePath, $"Tests/Runtime/ObjectParenting/{nameof(NetworkObjectParentingTests)}.unity"); @@ -72,12 +79,13 @@ public IEnumerator Setup() Assert.That(m_ServerNetworkManager, Is.Not.Null); Assert.That(m_ClientNetworkManagers, Is.Not.Null); Assert.That(m_ClientNetworkManagers.Length, Is.EqualTo(k_ClientInstanceCount)); + m_ServerNetworkManager.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); foreach (var entry in m_ClientNetworkManagers) { - if(!m_ServerNetworkManager.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) + if(!entry.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) { - m_ServerNetworkManager.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); + entry.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); } } @@ -218,6 +226,18 @@ public IEnumerator Teardown() { SceneManager.sceneLoaded -= OnSceneLoaded; + if (m_ServerNetworkManager.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) + { + m_ServerNetworkManager.ScenesInBuild.Scenes.Remove(nameof(NetworkObjectParentingTests)); + } + foreach (var entry in m_ClientNetworkManagers) + { + if (entry.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) + { + entry.ScenesInBuild.Scenes.Remove(nameof(NetworkObjectParentingTests)); + } + } + MultiInstanceHelpers.Destroy(); if (m_TestScene.isLoaded) diff --git a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneEventNotificationQueue.cs b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneEventNotificationQueue.cs index 6e36aa912f..f4e9838a04 100644 --- a/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneEventNotificationQueue.cs +++ b/testproject/Assets/Tests/Manual/SceneTransitioningAdditive/SceneEventNotificationQueue.cs @@ -38,6 +38,25 @@ private void Start() m_NetworkManager = gameObject.GetComponent(); } + private void DeregisterFromOnSceneEvent() + { + if (m_IsInitialized && m_NetworkManager != null && m_NetworkManager.SceneManager != null) + { + m_IsInitialized = false; + m_NetworkManager.SceneManager.OnSceneEvent -= OnSceneEvent; + } + } + + private void OnApplicationQuit() + { + DeregisterFromOnSceneEvent(); + } + + private void OnDisable() + { + DeregisterFromOnSceneEvent(); + } + /// /// Invoked on all local scene event notifications /// @@ -97,11 +116,6 @@ private void Update() m_SceneEvents.Dequeue(); } } - else if (m_IsInitialized) - { - m_IsInitialized = false; - m_NetworkManager.SceneManager.OnSceneEvent -= OnSceneEvent; - } } } } diff --git a/testproject/Assets/Tests/Manual/Scripts/PlayerMovementManager.cs b/testproject/Assets/Tests/Manual/Scripts/PlayerMovementManager.cs index e90c7a61a7..73a887c657 100644 --- a/testproject/Assets/Tests/Manual/Scripts/PlayerMovementManager.cs +++ b/testproject/Assets/Tests/Manual/Scripts/PlayerMovementManager.cs @@ -10,8 +10,6 @@ public class PlayerMovementManager : NetworkBehaviour { public int MoveSpeed = 10; - private NetworkObject m_NetworkObject; - private RandomMovement m_RandomMovement; private Rigidbody m_Rigidbody; @@ -20,9 +18,7 @@ public class PlayerMovementManager : NetworkBehaviour // Start is called before the first frame update private void Start() { - m_NetworkObject = GetComponent(); m_RandomMovement = GetComponent(); - } public override void OnNetworkSpawn() @@ -36,19 +32,22 @@ public override void OnNetworkSpawn() private void Update() { - if (m_NetworkObject.IsOwner && Input.GetKeyDown(KeyCode.Space)) + if (NetworkObject != null) { - if (m_RandomMovement) + if (IsOwner && Input.GetKeyDown(KeyCode.Space)) { - m_RandomMovement.enabled = !m_RandomMovement.enabled; + if (m_RandomMovement) + { + m_RandomMovement.enabled = !m_RandomMovement.enabled; + } } - } - if (m_NetworkObject && m_NetworkObject.NetworkManager && m_NetworkObject.NetworkManager.IsListening) - { - if (m_RandomMovement.enabled) + if (NetworkObject != null && NetworkObject.NetworkManager != null && NetworkObject.NetworkManager.IsListening) { - m_RandomMovement.Move(MoveSpeed); + if (m_RandomMovement.enabled) + { + m_RandomMovement.Move(MoveSpeed); + } } } } diff --git a/testproject/Assets/Tests/Runtime/FixedUpdateMessagesAreOnlyProcessedOnceTest.cs b/testproject/Assets/Tests/Runtime/FixedUpdateMessagesAreOnlyProcessedOnceTest.cs index a543cfb3c0..edab517e84 100644 --- a/testproject/Assets/Tests/Runtime/FixedUpdateMessagesAreOnlyProcessedOnceTest.cs +++ b/testproject/Assets/Tests/Runtime/FixedUpdateMessagesAreOnlyProcessedOnceTest.cs @@ -51,8 +51,8 @@ public IEnumerator TestFixedUpdateMessagesAreOnlyProcessedOnce() var networkObject = m_Prefab.AddComponent(); // Make it a prefab - MultiInstanceHelpers.MakeNetworkObjectTestPrefab(networkObject, 1); - var handler = new SpawnRpcDespawnInstanceHandler(1); + MultiInstanceHelpers.MakeNetworkObjectTestPrefab(networkObject); + var handler = new SpawnRpcDespawnInstanceHandler(networkObject.GlobalObjectIdHash); foreach (var client in clients) { client.PrefabHandler.AddHandler(networkObject, handler); diff --git a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs index 18dac102fe..81bbd16dd9 100644 --- a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs +++ b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs @@ -144,7 +144,7 @@ private void InitializeSceneTestInfo(bool enableSceneVerification = false) m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = m_ServerNetworkManager.ServerClientId, ShouldWait = false }); if (enableSceneVerification) { - m_ServerNetworkManager.PopulateScenesInBuild(); + ScenesInBuild.SynchronizeOrCreate(m_ServerNetworkManager); m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = ServerVerifySceneBeforeLoading; } @@ -153,7 +153,7 @@ private void InitializeSceneTestInfo(bool enableSceneVerification = false) m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = manager.LocalClientId, ShouldWait = false }); if (enableSceneVerification) { - manager.PopulateScenesInBuild(); + ScenesInBuild.SynchronizeOrCreate(manager); manager.SceneManager.VerifySceneBeforeLoading = ClientVerifySceneBeforeLoading; } } From 556a42af9739d110c0a53de0961e61d2223a00ec Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 27 Aug 2021 18:29:49 -0500 Subject: [PATCH 12/20] refactor Using UNITY_INCLUDE_TESTS as opposed to UNIT_EDITOR || DEVELOPMENT_BUILD --- .../Runtime/SceneManagement/NetworkSceneManager.cs | 10 +++++----- .../Runtime/SceneManagement/ScenesInBuild.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 6e3600a4db..ae69d6e30f 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -98,7 +98,7 @@ public class NetworkSceneManager // TODO: Remove `m_IsRunningUnitTest` entirely after we switch to multi-process testing // In MultiInstance tests, we cannot allow clients to load additional scenes as they're sharing the same scene space / Unity instance. -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_INCLUDE_TESTS private readonly bool m_IsRunningUnitTest = SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); #endif @@ -619,7 +619,7 @@ private void OnClientUnloadScene() } s_IsSceneEventActive = true; var sceneUnload = (AsyncOperation)null; -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_INCLUDE_TESTS if (m_IsRunningUnitTest) { sceneUnload = new AsyncOperation(); @@ -649,7 +649,7 @@ private void OnClientUnloadScene() }); -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_INCLUDE_TESTS if (m_IsRunningUnitTest) { OnSceneUnloaded(); @@ -814,7 +814,7 @@ private void OnClientSceneLoadingEvent(Stream objectStream) return; } -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_INCLUDE_TESTS if (m_IsRunningUnitTest) { // Send the loading message @@ -1131,7 +1131,7 @@ private void OnClientBeginSync() shouldPassThrough = true; } -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_INCLUDE_TESTS if (m_IsRunningUnitTest) { // In unit tests, we don't allow clients to load additional scenes since diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs index 5a42dd417e..81877d4d3f 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs @@ -22,7 +22,7 @@ public class ScenesInBuild : ScriptableObject [SerializeField] internal List Scenes; -#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_INCLUDE_TESTS /// /// Determines if we are running a unit test From b3ae1634438e8f9000b1c486c85a178b2c8d8e42 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Fri, 27 Aug 2021 20:03:46 -0500 Subject: [PATCH 13/20] refactor Reverting and condensing Got rid of DefaultScenesInBuildAssetNameAndPath --- .../Runtime/Core/NetworkManager.cs | 5 ----- .../SceneManagement/NetworkSceneManager.cs | 10 +++++----- .../Runtime/SceneManagement/ScenesInBuild.cs | 19 ++++++++----------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index b83f4feef3..835a53fc52 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -248,9 +248,6 @@ internal void InvokeConnectionApproval(byte[] payload, ulong clientId, Connectio [SerializeField] internal ScenesInBuild ScenesInBuild; - [HideInInspector] - [SerializeField] - internal string DefaultScenesInBuildAssetNameAndPath = "Assets/ScenesInBuildList.asset"; /// /// The current host name we are connected to, used to validate certificate /// @@ -260,8 +257,6 @@ internal void InvokeConnectionApproval(byte[] payload, ulong clientId, Connectio internal static event Action OnSingletonReady; - - #if UNITY_EDITOR private void OnValidate() { diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index ae69d6e30f..6e3600a4db 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -98,7 +98,7 @@ public class NetworkSceneManager // TODO: Remove `m_IsRunningUnitTest` entirely after we switch to multi-process testing // In MultiInstance tests, we cannot allow clients to load additional scenes as they're sharing the same scene space / Unity instance. -#if UNITY_INCLUDE_TESTS +#if UNITY_EDITOR || DEVELOPMENT_BUILD private readonly bool m_IsRunningUnitTest = SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); #endif @@ -619,7 +619,7 @@ private void OnClientUnloadScene() } s_IsSceneEventActive = true; var sceneUnload = (AsyncOperation)null; -#if UNITY_INCLUDE_TESTS +#if UNITY_EDITOR || DEVELOPMENT_BUILD if (m_IsRunningUnitTest) { sceneUnload = new AsyncOperation(); @@ -649,7 +649,7 @@ private void OnClientUnloadScene() }); -#if UNITY_INCLUDE_TESTS +#if UNITY_EDITOR || DEVELOPMENT_BUILD if (m_IsRunningUnitTest) { OnSceneUnloaded(); @@ -814,7 +814,7 @@ private void OnClientSceneLoadingEvent(Stream objectStream) return; } -#if UNITY_INCLUDE_TESTS +#if UNITY_EDITOR || DEVELOPMENT_BUILD if (m_IsRunningUnitTest) { // Send the loading message @@ -1131,7 +1131,7 @@ private void OnClientBeginSync() shouldPassThrough = true; } -#if UNITY_INCLUDE_TESTS +#if UNITY_EDITOR || DEVELOPMENT_BUILD if (m_IsRunningUnitTest) { // In unit tests, we don't allow clients to load additional scenes since diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs index 81877d4d3f..587b9477d5 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs @@ -18,11 +18,11 @@ namespace Unity.Netcode /// public class ScenesInBuild : ScriptableObject { - //[HideInInspector] + [HideInInspector] [SerializeField] internal List Scenes; -#if UNITY_INCLUDE_TESTS +#if UNITY_EDITOR || DEVELOPMENT_BUILD /// /// Determines if we are running a unit test @@ -36,12 +36,8 @@ private static bool IsRunningUnitTest() return false; } #endif - - var isTesting = SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); - - // For scenes in build, we have to check whether we are running a unit test or not each time - return isTesting; + return SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); } /// @@ -89,7 +85,7 @@ internal static void SynchronizeOrCreate(NetworkManager networkManager) #if UNITY_EDITOR - + private const string k_ScenesInBuildDefaultPath = "Assets/ScenesInBuildList.asset"; private bool m_CheckHasBeenApplied; /// @@ -128,6 +124,7 @@ private void EditorApplication_playModeStateChanged(PlayModeStateChange obj) internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkManager) { var foundScenesInBuildList = AssetDatabase.FindAssets("ScenesInBuildList"); + var currentAssetPath = k_ScenesInBuildDefaultPath; if (foundScenesInBuildList.Length > 0) { if (foundScenesInBuildList.Length > 1) @@ -141,13 +138,13 @@ internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkMana message += "Using first entry. Please remove one of the instances if that is not the right asset path!"; Debug.LogError(message); } - networkManager.DefaultScenesInBuildAssetNameAndPath = AssetDatabase.GUIDToAssetPath(foundScenesInBuildList[0]); + currentAssetPath = AssetDatabase.GUIDToAssetPath(foundScenesInBuildList[0]); } - var scenesInBuild = (ScenesInBuild)AssetDatabase.LoadAssetAtPath(networkManager.DefaultScenesInBuildAssetNameAndPath, typeof(ScenesInBuild)); + var scenesInBuild = (ScenesInBuild)AssetDatabase.LoadAssetAtPath(currentAssetPath, typeof(ScenesInBuild)); if (scenesInBuild == null) { scenesInBuild = CreateInstance(); - AssetDatabase.CreateAsset(scenesInBuild, networkManager.DefaultScenesInBuildAssetNameAndPath); + AssetDatabase.CreateAsset(scenesInBuild, currentAssetPath); } return scenesInBuild; } From acfab6e16e3145b9cf761c92469983ad171febd0 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 30 Aug 2021 11:19:18 -0500 Subject: [PATCH 14/20] refactor Removes the circular reference by creating a 3rd helper class to handle the initial creation and synchronization process. --- .../Runtime/Core/NetworkManager.cs | 2 +- .../Runtime/SceneManagement/ScenesInBuild.cs | 124 ++++++++++-------- ...NetworkManagerCustomMessageManagerTests.cs | 2 +- .../NetworkManagerMessageHandlerTests.cs | 2 +- .../Editor/NetworkManagerSceneManagerTests.cs | 2 +- .../Runtime/Helpers/NetworkManagerHelper.cs | 2 +- .../Tests/Runtime/MultiInstanceHelpers.cs | 4 +- .../NetworkObjectParentingTests.cs | 4 +- .../Tests/Runtime/NetworkSceneManagerTests.cs | 4 +- 9 files changed, 80 insertions(+), 66 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 835a53fc52..2ca6044a09 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -265,7 +265,7 @@ private void OnValidate() return; // May occur when the component is added } - ScenesInBuild.SynchronizeOrCreate(this); + ScenesInBuildHelper.SynchronizeOrCreate(this); if (GetComponentInChildren() != null) { diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs index 587b9477d5..63ac8e58c1 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs @@ -8,27 +8,15 @@ namespace Unity.Netcode { - /// - /// This replaces the need to register scenes and contains the Scenes in Build list (as strings) - /// Scenes are ordered identically to the Scenes in Build list indices values - /// For refined control over which scenes can be loaded or unloaded during a netcode game session, - /// use the event to add additional - /// constraints over which scenes are considered valid. - /// In order for clients to get this notification you must subscribe to the event. - /// - public class ScenesInBuild : ScriptableObject - { - [HideInInspector] - [SerializeField] - internal List Scenes; - #if UNITY_EDITOR || DEVELOPMENT_BUILD - + public static class ScenesInBuildHelper + { + private const string k_ScenesInBuildDefaultPath = "Assets/ScenesInBuildList.asset"; /// /// Determines if we are running a unit test /// In DEVELOPMENT_BUILD we only check for the InitTestScene /// - private static bool IsRunningUnitTest() + internal static bool IsRunningUnitTest() { #if UNITY_EDITOR if (!EditorApplication.isPlaying) @@ -52,8 +40,8 @@ internal static void SynchronizeOrCreate(NetworkManager networkManager) // Otherwise, there are special edge case scenarios where we might want to repopulate this list // The scenario with EditorApplication.isPlaying and ScenesInBuild being null is where we loaded a scene that did not have a NetworkManager but // we transition to a scene with a NetworkManager while playing in the editor. Under this condition we have to assign and populate. - if ( (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating) || isUnitTestRunning || - ( (networkManager.ScenesInBuild == null || networkManager.ScenesInBuild != null && networkManager.ScenesInBuild.Scenes.Count == 0) && EditorApplication.isPlaying) ) + if ((!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating) || isUnitTestRunning || + ((networkManager.ScenesInBuild == null || networkManager.ScenesInBuild != null && networkManager.ScenesInBuild.Scenes.Count == 0) && EditorApplication.isPlaying)) { if (networkManager.ScenesInBuild == null) { @@ -83,45 +71,13 @@ internal static void SynchronizeOrCreate(NetworkManager networkManager) #endif } - -#if UNITY_EDITOR - private const string k_ScenesInBuildDefaultPath = "Assets/ScenesInBuildList.asset"; - private bool m_CheckHasBeenApplied; - - /// - /// This will add a play mode state change watch to determine when we are done with a unit test - /// in order to re-synchronize our ScenesInBuild asset. - /// - private void CheckForEndOfUnitTest() - { - if (!m_CheckHasBeenApplied) - { - EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; - m_CheckHasBeenApplied = true; - } - } - - /// - /// Check for when we enter into editor mode so we can remove any scenes that might have been added to the - /// scenes list. - /// - private void EditorApplication_playModeStateChanged(PlayModeStateChange obj) - { - if (obj == PlayModeStateChange.EnteredEditMode) - { - EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged; - m_CheckHasBeenApplied = false; - PopulateScenesInBuild(); - } - } - /// /// This will create a new ScenesInBuildList asset if one does not exist and will adjust the path to the ScenesInBuildList /// asset if the asset is moved. This will also notify the user if more than one ScenesInBuildList asset exists. /// /// The relative network manager instance /// - internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkManager) + private static ScenesInBuild InitializeScenesInBuild(NetworkManager networkManager) { var foundScenesInBuildList = AssetDatabase.FindAssets("ScenesInBuildList"); var currentAssetPath = k_ScenesInBuildDefaultPath; @@ -143,11 +99,69 @@ internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkMana var scenesInBuild = (ScenesInBuild)AssetDatabase.LoadAssetAtPath(currentAssetPath, typeof(ScenesInBuild)); if (scenesInBuild == null) { - scenesInBuild = CreateInstance(); - AssetDatabase.CreateAsset(scenesInBuild, currentAssetPath); + scenesInBuild = ScenesInBuild.Create(currentAssetPath); } return scenesInBuild; } + } +#endif + + /// + /// This replaces the need to register scenes and contains the Scenes in Build list (as strings) + /// Scenes are ordered identically to the Scenes in Build list indices values + /// For refined control over which scenes can be loaded or unloaded during a netcode game session, + /// use the event to add additional + /// constraints over which scenes are considered valid. + /// In order for clients to get this notification you must subscribe to the event. + /// + public class ScenesInBuild : ScriptableObject + { + [HideInInspector] + [SerializeField] + internal List Scenes; + +#if UNITY_EDITOR || DEVELOPMENT_BUILD +#if UNITY_EDITOR + private bool m_CheckHasBeenApplied; + + /// + /// Creates a ScenesInBuild asset + /// + /// path where the asset is created + /// + internal static ScenesInBuild Create(string path) + { + var scenesInBuild = CreateInstance(); + AssetDatabase.CreateAsset(scenesInBuild, path); + return scenesInBuild; + } + + /// + /// This will add a play mode state change watch to determine when we are done with a unit test + /// in order to re-synchronize our ScenesInBuild asset. + /// + private void CheckForEndOfUnitTest() + { + if (!m_CheckHasBeenApplied) + { + EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; + m_CheckHasBeenApplied = true; + } + } + + /// + /// Check for when we enter into editor mode so we can remove any scenes that might have been added to the + /// scenes list. + /// + private void EditorApplication_playModeStateChanged(PlayModeStateChange obj) + { + if (obj == PlayModeStateChange.EnteredEditMode) + { + EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged; + m_CheckHasBeenApplied = false; + PopulateScenesInBuild(); + } + } /// /// Populates the scenes from the Scenes in Build list. @@ -156,7 +170,7 @@ internal static ScenesInBuild InitializeScenesInBuild(NetworkManager networkMana internal void PopulateScenesInBuild() { var shouldRebuild = false; - var isTesting = IsRunningUnitTest(); + var isTesting = ScenesInBuildHelper.IsRunningUnitTest(); // if we have no scenes registered or we have changed the scenes in the build we should rebuild if (Scenes == null) @@ -239,7 +253,7 @@ internal void PopulateScenesInBuild() /// private void OnValidate() { - if (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating || IsRunningUnitTest()) + if (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating || ScenesInBuildHelper.IsRunningUnitTest()) { PopulateScenesInBuild(); } diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs index 48131038a7..616b708f5b 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs @@ -12,7 +12,7 @@ public void CustomMessageManagerAssigned() var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - ScenesInBuild.SynchronizeOrCreate(networkManager); + ScenesInBuildHelper.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs index 702d65d24f..0f0540df8d 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs @@ -17,7 +17,7 @@ public void MessageHandlerReceivedMessageServerClient() var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - ScenesInBuild.SynchronizeOrCreate(networkManager); + ScenesInBuildHelper.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs index 3143c98ad6..373a9920e8 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs @@ -11,7 +11,7 @@ public void SceneManagerAssigned() var gameObject = new GameObject(nameof(SceneManagerAssigned)); var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - ScenesInBuild.SynchronizeOrCreate(networkManager); + ScenesInBuildHelper.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs index f4ad5b13a4..a4ee978cdd 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs @@ -77,7 +77,7 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ EnableSceneManagement = false, }; } - ScenesInBuild.SynchronizeOrCreate(NetworkManagerObject); + ScenesInBuildHelper.SynchronizeOrCreate(NetworkManagerObject); NetworkManagerObject.NetworkConfig = networkConfig; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs index 40d8f622bf..069bd31347 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs @@ -46,7 +46,7 @@ public static bool Create(int clientCount, out NetworkManager server, out Networ // Set transport NetworkTransport = go.AddComponent() }; - ScenesInBuild.SynchronizeOrCreate(server); + ScenesInBuildHelper.SynchronizeOrCreate(server); s_OriginalTargetFrameRate = Application.targetFrameRate; Application.targetFrameRate = targetFrameRate; @@ -78,7 +78,7 @@ public static bool CreateNewClients(int clientCount, out NetworkManager[] client NetworkTransport = go.AddComponent() }; - ScenesInBuild.SynchronizeOrCreate(clients[i]); + ScenesInBuildHelper.SynchronizeOrCreate(clients[i]); } NetworkManagerInstances.AddRange(clients); diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index 89b6722bb0..e34fe02f98 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -58,10 +58,10 @@ public IEnumerator Setup() // we are running a unit test or not. (it is this or manually setting a property) Assert.That(MultiInstanceHelpers.Create(k_ClientInstanceCount, out m_ServerNetworkManager, out m_ClientNetworkManagers)); - ScenesInBuild.SynchronizeOrCreate(m_ServerNetworkManager); + ScenesInBuildHelper.SynchronizeOrCreate(m_ServerNetworkManager); foreach (var entry in m_ClientNetworkManagers) { - ScenesInBuild.SynchronizeOrCreate(entry); + ScenesInBuildHelper.SynchronizeOrCreate(entry); } diff --git a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs index 81bbd16dd9..e6d4ce267c 100644 --- a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs +++ b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs @@ -144,7 +144,7 @@ private void InitializeSceneTestInfo(bool enableSceneVerification = false) m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = m_ServerNetworkManager.ServerClientId, ShouldWait = false }); if (enableSceneVerification) { - ScenesInBuild.SynchronizeOrCreate(m_ServerNetworkManager); + ScenesInBuildHelper.SynchronizeOrCreate(m_ServerNetworkManager); m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = ServerVerifySceneBeforeLoading; } @@ -153,7 +153,7 @@ private void InitializeSceneTestInfo(bool enableSceneVerification = false) m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = manager.LocalClientId, ShouldWait = false }); if (enableSceneVerification) { - ScenesInBuild.SynchronizeOrCreate(manager); + ScenesInBuildHelper.SynchronizeOrCreate(manager); manager.SceneManager.VerifySceneBeforeLoading = ClientVerifySceneBeforeLoading; } } From 82cf53872c69585589af7a5a8b8456e3c12db7d1 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 30 Aug 2021 12:40:28 -0500 Subject: [PATCH 15/20] refactor Found a much better way to generate the scenes in build list while running in the editor or as a stand alone development or release build. This completely removes the ScenesInBuild asset and all dependencies. --- .../Runtime/Core/NetworkManager.cs | 9 - .../SceneManagement/NetworkSceneManager.cs | 38 ++- .../Runtime/SceneManagement/ScenesInBuild.cs | 266 ------------------ .../SceneManagement/ScenesInBuild.cs.meta | 15 - ...NetworkManagerCustomMessageManagerTests.cs | 1 - .../NetworkManagerMessageHandlerTests.cs | 1 - .../Editor/NetworkManagerSceneManagerTests.cs | 1 - .../Runtime/Helpers/NetworkManagerHelper.cs | 1 - .../Tests/Runtime/MultiInstanceHelpers.cs | 3 - .../NetworkObjectParentingTests.cs | 36 +-- .../Tests/Runtime/NetworkSceneManagerTests.cs | 2 - 11 files changed, 42 insertions(+), 331 deletions(-) delete mode 100644 com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs delete mode 100644 com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 2ca6044a09..4348809bb4 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -241,13 +241,6 @@ internal void InvokeConnectionApproval(byte[] payload, ulong clientId, Connectio /// [HideInInspector] public NetworkConfig NetworkConfig; - /// - /// Reference to the ScenesInBuild asset that contains a list of the scenes in the build list - /// - [HideInInspector] - [SerializeField] - internal ScenesInBuild ScenesInBuild; - /// /// The current host name we are connected to, used to validate certificate /// @@ -265,8 +258,6 @@ private void OnValidate() return; // May occur when the component is added } - ScenesInBuildHelper.SynchronizeOrCreate(this); - if (GetComponentInChildren() != null) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 45152338cb..07f5ec18cf 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -167,6 +167,11 @@ public class NetworkSceneManager /// internal Dictionary ServerSceneHandleToClientSceneHandle = new Dictionary(); + /// + /// The scenes in the build without their path + /// + internal List ScenesInBuild = new List(); + /// /// The Condition: While a scene is asynchronously loaded in single loading scene mode, if any new NetworkObjects are spawned /// they need to be moved into the do not destroy temporary scene @@ -197,6 +202,29 @@ public class NetworkSceneManager internal Scene DontDestroyOnLoadScene; + /// + /// Gets the scene name from full path to the scene + /// + /// + internal string GetSceneNameFromPath(string scenePath) + { + var begin = scenePath.LastIndexOf("/", StringComparison.Ordinal) + 1; + var end = scenePath.LastIndexOf(".", StringComparison.Ordinal); + return scenePath.Substring(begin, end - begin); + } + + /// + /// Generates the scenes in build list + /// + internal void GenerateScenesInBuild() + { + ScenesInBuild.Clear(); + for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) + { + ScenesInBuild.Add(GetSceneNameFromPath(SceneUtility.GetScenePathByBuildIndex(i))); + } + } + /// /// Constructor /// @@ -207,6 +235,8 @@ internal NetworkSceneManager(NetworkManager networkManager) SceneEventData = new SceneEventData(networkManager); ClientSynchEventData = new SceneEventData(networkManager); + GenerateScenesInBuild(); + // If NetworkManager has this set to true, then we can get the DDOL (DontDestroyOnLoad) from its GaemObject if (networkManager.DontDestroy) { @@ -404,7 +434,7 @@ private void SendSceneEventData(ulong[] targetClientIds) /// true (Valid) or false (Invalid) internal bool IsSceneNameValid(string sceneName) { - if (m_NetworkManager.ScenesInBuild.Scenes.Contains(sceneName)) + if (ScenesInBuild.Contains(sceneName)) { return true; } @@ -419,7 +449,7 @@ internal bool IsSceneNameValid(string sceneName) /// true (Valid) or false (Invalid) internal bool IsSceneIndexValid(uint index) { - return (index >= 0 && index < m_NetworkManager.ScenesInBuild.Scenes.Count); + return (index >= 0 && index < ScenesInBuild.Count); } /// @@ -431,7 +461,7 @@ internal uint GetBuildIndexFromSceneName(string sceneName) { if (IsSceneNameValid(sceneName)) { - return (uint)m_NetworkManager.ScenesInBuild.Scenes.IndexOf(sceneName); + return (uint)ScenesInBuild.IndexOf(sceneName); } return uint.MaxValue; } @@ -445,7 +475,7 @@ internal string GetSceneNameFromBuildIndex(uint buildIndex) { if (IsSceneIndexValid(buildIndex)) { - return m_NetworkManager.ScenesInBuild.Scenes[(int)buildIndex]; + return ScenesInBuild[(int)buildIndex]; } return string.Empty; } diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs deleted file mode 100644 index 63ac8e58c1..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs +++ /dev/null @@ -1,266 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.SceneManagement; -#if UNITY_EDITOR -using UnityEditor; -#endif - - -namespace Unity.Netcode -{ -#if UNITY_EDITOR || DEVELOPMENT_BUILD - public static class ScenesInBuildHelper - { - private const string k_ScenesInBuildDefaultPath = "Assets/ScenesInBuildList.asset"; - /// - /// Determines if we are running a unit test - /// In DEVELOPMENT_BUILD we only check for the InitTestScene - /// - internal static bool IsRunningUnitTest() - { -#if UNITY_EDITOR - if (!EditorApplication.isPlaying) - { - return false; - } -#endif - // For scenes in build, we have to check whether we are running a unit test or not each time - return SceneManager.GetActiveScene().name.StartsWith("InitTestScene"); - } - - /// - /// Assures the ScenesInBuild asset exists and if in the editor that it is always up to date - /// - internal static void SynchronizeOrCreate(NetworkManager networkManager) - { - var isUnitTestRunning = IsRunningUnitTest(); - -#if UNITY_EDITOR - // If we are testing or we are playing (in editor) and ScenesInBuild is null then we want to initialize and populate the ScenesInBuild asset. - // Otherwise, there are special edge case scenarios where we might want to repopulate this list - // The scenario with EditorApplication.isPlaying and ScenesInBuild being null is where we loaded a scene that did not have a NetworkManager but - // we transition to a scene with a NetworkManager while playing in the editor. Under this condition we have to assign and populate. - if ((!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating) || isUnitTestRunning || - ((networkManager.ScenesInBuild == null || networkManager.ScenesInBuild != null && networkManager.ScenesInBuild.Scenes.Count == 0) && EditorApplication.isPlaying)) - { - if (networkManager.ScenesInBuild == null) - { - networkManager.ScenesInBuild = InitializeScenesInBuild(networkManager); - } - - networkManager.ScenesInBuild.PopulateScenesInBuild(); - } -#else - - // Only if we are running a stand alone build as for unit or integration testing - if (isUnitTestRunning) - { - if (networkManager.ScenesInBuild == null) - { - networkManager.ScenesInBuild = CreateInstance(); - } - var currentlyActiveSceneName = SceneManager.GetActiveScene().name; - - // If the unit test scene is not already added to the ScenesInBuild - if(!networkManager.ScenesInBuild.Scenes.Contains(currentlyActiveSceneName)) - { - // Then add it into the valid scenes that it can be loaded - networkManager.ScenesInBuild.Scenes.Add(currentlyActiveSceneName); - } - } -#endif - } - - /// - /// This will create a new ScenesInBuildList asset if one does not exist and will adjust the path to the ScenesInBuildList - /// asset if the asset is moved. This will also notify the user if more than one ScenesInBuildList asset exists. - /// - /// The relative network manager instance - /// - private static ScenesInBuild InitializeScenesInBuild(NetworkManager networkManager) - { - var foundScenesInBuildList = AssetDatabase.FindAssets("ScenesInBuildList"); - var currentAssetPath = k_ScenesInBuildDefaultPath; - if (foundScenesInBuildList.Length > 0) - { - if (foundScenesInBuildList.Length > 1) - { - var message = "There are multiple instances of your ScenesInBuildList:\n"; - - foreach (var entry in foundScenesInBuildList) - { - message += $"{AssetDatabase.GUIDToAssetPath(entry)}\n"; - } - message += "Using first entry. Please remove one of the instances if that is not the right asset path!"; - Debug.LogError(message); - } - currentAssetPath = AssetDatabase.GUIDToAssetPath(foundScenesInBuildList[0]); - } - var scenesInBuild = (ScenesInBuild)AssetDatabase.LoadAssetAtPath(currentAssetPath, typeof(ScenesInBuild)); - if (scenesInBuild == null) - { - scenesInBuild = ScenesInBuild.Create(currentAssetPath); - } - return scenesInBuild; - } - } -#endif - - /// - /// This replaces the need to register scenes and contains the Scenes in Build list (as strings) - /// Scenes are ordered identically to the Scenes in Build list indices values - /// For refined control over which scenes can be loaded or unloaded during a netcode game session, - /// use the event to add additional - /// constraints over which scenes are considered valid. - /// In order for clients to get this notification you must subscribe to the event. - /// - public class ScenesInBuild : ScriptableObject - { - [HideInInspector] - [SerializeField] - internal List Scenes; - -#if UNITY_EDITOR || DEVELOPMENT_BUILD -#if UNITY_EDITOR - private bool m_CheckHasBeenApplied; - - /// - /// Creates a ScenesInBuild asset - /// - /// path where the asset is created - /// - internal static ScenesInBuild Create(string path) - { - var scenesInBuild = CreateInstance(); - AssetDatabase.CreateAsset(scenesInBuild, path); - return scenesInBuild; - } - - /// - /// This will add a play mode state change watch to determine when we are done with a unit test - /// in order to re-synchronize our ScenesInBuild asset. - /// - private void CheckForEndOfUnitTest() - { - if (!m_CheckHasBeenApplied) - { - EditorApplication.playModeStateChanged += EditorApplication_playModeStateChanged; - m_CheckHasBeenApplied = true; - } - } - - /// - /// Check for when we enter into editor mode so we can remove any scenes that might have been added to the - /// scenes list. - /// - private void EditorApplication_playModeStateChanged(PlayModeStateChange obj) - { - if (obj == PlayModeStateChange.EnteredEditMode) - { - EditorApplication.playModeStateChanged -= EditorApplication_playModeStateChanged; - m_CheckHasBeenApplied = false; - PopulateScenesInBuild(); - } - } - - /// - /// Populates the scenes from the Scenes in Build list. - /// If testing, then this is ignored (i.e. some tests require loading of scenes not in the Scenes in Build list) - /// - internal void PopulateScenesInBuild() - { - var shouldRebuild = false; - var isTesting = ScenesInBuildHelper.IsRunningUnitTest(); - - // if we have no scenes registered or we have changed the scenes in the build we should rebuild - if (Scenes == null) - { - shouldRebuild = true; - } - else if (!isTesting) - { - if (EditorBuildSettings.scenes.Length != Scenes.Count) - { - shouldRebuild = true; - } - else - { - // Verify our order hasn't changed and if it has then we should rebuild - for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) - { - var scene = EditorBuildSettings.scenes[i]; - var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); - // We could either have changed the order or we could have rename something or we could have removed and added - // either case we rebuild if they don't align properly - if (Scenes[i] != sceneAsset.name) - { - shouldRebuild = true; - break; - } - } - } - } - else - if ( Scenes.Count != SceneManager.sceneCountInBuildSettings) - { - shouldRebuild = true; - } - - if (shouldRebuild) - { - Scenes = new List(); - if (!isTesting) - { - // Normal scenes in build list generation - for (int i = 0; i < EditorBuildSettings.scenes.Length; i++) - { - var scene = EditorBuildSettings.scenes[i]; - var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); - Scenes.Add(sceneAsset.name); - } - } - else - { - CheckForEndOfUnitTest(); - - // This is only for unit or integration testing - for (int i = 0; i < SceneManager.sceneCountInBuildSettings; i++) - { - // First we make sure we order everything exactly as it is in the build settings - if (EditorBuildSettings.scenes.Length > i) - { - var scene = EditorBuildSettings.scenes[i]; - var sceneAsset = AssetDatabase.LoadAssetAtPath(scene.path); - Scenes.Add(sceneAsset.name); - } - else // If we are testing then we will just add the remaining scenes into our registered scenes list - if (!Scenes.Contains(SceneManager.GetSceneByBuildIndex(i).name)) - { - Scenes.Add(SceneManager.GetSceneByBuildIndex(i).name); - } - } - } - } - - if (!isTesting) - { - AssetDatabase.SaveAssets(); - } - } - - /// - /// Depending upon the current editor state or if we are running a unit test or not, this will refresh the Scenes in Build list - /// - private void OnValidate() - { - if (!EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying && !EditorApplication.isUpdating || ScenesInBuildHelper.IsRunningUnitTest()) - { - PopulateScenesInBuild(); - } - } - -#endif // UNITY_EDITOR -#endif // UNITY_EDITOR || DEVELOPMENT_BUILD - - } -} diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta b/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta deleted file mode 100644 index 59d1b2bf9e..0000000000 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta +++ /dev/null @@ -1,15 +0,0 @@ -fileFormatVersion: 2 -<<<<<<< HEAD:testproject/Assets/Tests/Manual/SceneTransitioningAdditive/AdditiveSceneToggleHandler.cs.meta -guid: 66f377a54b543fa43ac0b24e758caeff -======= -guid: 6e6dff048b3e7e84b9535cdb6517cf39 ->>>>>>> feat/scenesinbuild-mlapi-sceneregistration:com.unity.netcode.gameobjects/Runtime/SceneManagement/ScenesInBuild.cs.meta -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs index 616b708f5b..2094b1efd3 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerCustomMessageManagerTests.cs @@ -12,7 +12,6 @@ public void CustomMessageManagerAssigned() var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - ScenesInBuildHelper.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs index 0f0540df8d..2b01929ccc 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerMessageHandlerTests.cs @@ -17,7 +17,6 @@ public void MessageHandlerReceivedMessageServerClient() var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - ScenesInBuildHelper.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs index 373a9920e8..c1f5b30d14 100644 --- a/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Editor/NetworkManagerSceneManagerTests.cs @@ -11,7 +11,6 @@ public void SceneManagerAssigned() var gameObject = new GameObject(nameof(SceneManagerAssigned)); var networkManager = gameObject.AddComponent(); var transport = gameObject.AddComponent(); - ScenesInBuildHelper.SynchronizeOrCreate(networkManager); networkManager.NetworkConfig = new NetworkConfig(); // Set dummy transport that does nothing networkManager.NetworkConfig.NetworkTransport = transport; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs index a4ee978cdd..57129aef1b 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Helpers/NetworkManagerHelper.cs @@ -77,7 +77,6 @@ public static bool StartNetworkManager(out NetworkManager networkManager, Networ EnableSceneManagement = false, }; } - ScenesInBuildHelper.SynchronizeOrCreate(NetworkManagerObject); NetworkManagerObject.NetworkConfig = networkConfig; diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs index 069bd31347..a59d3300dd 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/MultiInstanceHelpers.cs @@ -46,7 +46,6 @@ public static bool Create(int clientCount, out NetworkManager server, out Networ // Set transport NetworkTransport = go.AddComponent() }; - ScenesInBuildHelper.SynchronizeOrCreate(server); s_OriginalTargetFrameRate = Application.targetFrameRate; Application.targetFrameRate = targetFrameRate; @@ -77,8 +76,6 @@ public static bool CreateNewClients(int clientCount, out NetworkManager[] client // Set transport NetworkTransport = go.AddComponent() }; - - ScenesInBuildHelper.SynchronizeOrCreate(clients[i]); } NetworkManagerInstances.AddRange(clients); diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index e34fe02f98..cf969089f4 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -58,13 +58,6 @@ public IEnumerator Setup() // we are running a unit test or not. (it is this or manually setting a property) Assert.That(MultiInstanceHelpers.Create(k_ClientInstanceCount, out m_ServerNetworkManager, out m_ClientNetworkManagers)); - ScenesInBuildHelper.SynchronizeOrCreate(m_ServerNetworkManager); - foreach (var entry in m_ClientNetworkManagers) - { - ScenesInBuildHelper.SynchronizeOrCreate(entry); - } - - var execAssembly = Assembly.GetExecutingAssembly(); var packagePath = PackageInfo.FindForAssembly(execAssembly).assetPath; var scenePath = Path.Combine(packagePath, $"Tests/Runtime/ObjectParenting/{nameof(NetworkObjectParentingTests)}.unity"); @@ -80,15 +73,6 @@ public IEnumerator Setup() Assert.That(m_ClientNetworkManagers, Is.Not.Null); Assert.That(m_ClientNetworkManagers.Length, Is.EqualTo(k_ClientInstanceCount)); - m_ServerNetworkManager.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); - foreach (var entry in m_ClientNetworkManagers) - { - if(!entry.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) - { - entry.ScenesInBuild.Scenes.Add(nameof(NetworkObjectParentingTests)); - } - } - m_Dude_NetObjs = new Transform[setCount]; m_Dude_LeftArm_NetObjs = new Transform[setCount]; m_Dude_RightArm_NetObjs = new Transform[setCount]; @@ -114,6 +98,14 @@ public IEnumerator Setup() // Start server and client NetworkManager instances Assert.That(MultiInstanceHelpers.Start(true, m_ServerNetworkManager, m_ClientNetworkManagers)); + m_ServerNetworkManager.SceneManager.ScenesInBuild.Add(nameof(NetworkObjectParentingTests)); + foreach (var entry in m_ClientNetworkManagers) + { + if (!entry.SceneManager.ScenesInBuild.Contains(nameof(NetworkObjectParentingTests))) + { + entry.SceneManager.ScenesInBuild.Add(nameof(NetworkObjectParentingTests)); + } + } // Register our scene verification delegate handler so we don't load the unit test scene m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = VerifySceneBeforeLoading; @@ -226,18 +218,6 @@ public IEnumerator Teardown() { SceneManager.sceneLoaded -= OnSceneLoaded; - if (m_ServerNetworkManager.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) - { - m_ServerNetworkManager.ScenesInBuild.Scenes.Remove(nameof(NetworkObjectParentingTests)); - } - foreach (var entry in m_ClientNetworkManagers) - { - if (entry.ScenesInBuild.Scenes.Contains(nameof(NetworkObjectParentingTests))) - { - entry.ScenesInBuild.Scenes.Remove(nameof(NetworkObjectParentingTests)); - } - } - MultiInstanceHelpers.Destroy(); if (m_TestScene.isLoaded) diff --git a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs index e6d4ce267c..495d6b29ab 100644 --- a/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs +++ b/testproject/Assets/Tests/Runtime/NetworkSceneManagerTests.cs @@ -144,7 +144,6 @@ private void InitializeSceneTestInfo(bool enableSceneVerification = false) m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = m_ServerNetworkManager.ServerClientId, ShouldWait = false }); if (enableSceneVerification) { - ScenesInBuildHelper.SynchronizeOrCreate(m_ServerNetworkManager); m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = ServerVerifySceneBeforeLoading; } @@ -153,7 +152,6 @@ private void InitializeSceneTestInfo(bool enableSceneVerification = false) m_ShouldWaitList.Add(new SceneTestInfo() { ClientId = manager.LocalClientId, ShouldWait = false }); if (enableSceneVerification) { - ScenesInBuildHelper.SynchronizeOrCreate(manager); manager.SceneManager.VerifySceneBeforeLoading = ClientVerifySceneBeforeLoading; } } From a974752c1624809250fd63b4521ed7c88cf2b812 Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 30 Aug 2021 12:50:07 -0500 Subject: [PATCH 16/20] refactor minor adjustment to a unit test where server and client NetworkManagers are being initialized in one pass as opposed to two. --- .../ObjectParenting/NetworkObjectParentingTests.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs index cf969089f4..90f7317216 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/ObjectParenting/NetworkObjectParentingTests.cs @@ -99,19 +99,16 @@ public IEnumerator Setup() // Start server and client NetworkManager instances Assert.That(MultiInstanceHelpers.Start(true, m_ServerNetworkManager, m_ClientNetworkManagers)); m_ServerNetworkManager.SceneManager.ScenesInBuild.Add(nameof(NetworkObjectParentingTests)); + // Register our scene verification delegate handler so we don't load the unit test scene + m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = VerifySceneBeforeLoading; foreach (var entry in m_ClientNetworkManagers) { if (!entry.SceneManager.ScenesInBuild.Contains(nameof(NetworkObjectParentingTests))) { entry.SceneManager.ScenesInBuild.Add(nameof(NetworkObjectParentingTests)); } - } - - // Register our scene verification delegate handler so we don't load the unit test scene - m_ServerNetworkManager.SceneManager.VerifySceneBeforeLoading = VerifySceneBeforeLoading; - for (int setIndex = 0; setIndex < k_ClientInstanceCount; setIndex++) - { - m_ClientNetworkManagers[setIndex].SceneManager.VerifySceneBeforeLoading = VerifySceneBeforeLoading; + // Register our scene verification delegate handler so we don't load the unit test scene + entry.SceneManager.VerifySceneBeforeLoading = VerifySceneBeforeLoading; } // Wait for connection on client side From 0b203fd56dcfcefda2a82e321350f0abfb1850f7 Mon Sep 17 00:00:00 2001 From: Noel Stephens Date: Mon, 30 Aug 2021 14:28:57 -0500 Subject: [PATCH 17/20] Update com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs Co-authored-by: Matt Walsh <69258106+mattwalsh-unity@users.noreply.github.com> --- .../Runtime/SceneManagement/NetworkSceneManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 07f5ec18cf..8864ac65d4 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -269,7 +269,7 @@ internal NetworkSceneManager(NetworkManager networkManager) } /// - /// If the VerifySceneBeforeLoading delegate handler has been set by the user, this will provides + /// If the VerifySceneBeforeLoading delegate handler has been set by the user, this will provide /// an additional level of security and/or validation that the scene being loaded in the specified /// loading mode is "a valid scene to be loaded in the LoadSceneMode specified". /// From c81d05d685e469c8e7d3d9d82e560a6faa63f5f0 Mon Sep 17 00:00:00 2001 From: Noel Stephens Date: Mon, 30 Aug 2021 14:29:03 -0500 Subject: [PATCH 18/20] Update com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs Co-authored-by: Matt Walsh <69258106+mattwalsh-unity@users.noreply.github.com> --- .../Runtime/SceneManagement/NetworkSceneManager.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 8864ac65d4..5055f4c536 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -273,7 +273,7 @@ internal NetworkSceneManager(NetworkManager networkManager) /// an additional level of security and/or validation that the scene being loaded in the specified /// loading mode is "a valid scene to be loaded in the LoadSceneMode specified". /// - /// Build Settings Scenes in Build List index of the scene + /// index into ScenesInBuild /// Name of the scene /// LoadSceneMode the scene is going to be loaded /// true (Valid) or false (Invalid) From f24c16e903861d0edae3416901eeed091060ae8d Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 30 Aug 2021 15:04:43 -0500 Subject: [PATCH 19/20] refactor Refactoring based on a few of Matt's suggestions: Completely removed the GetSceneNameFromBuildIndex as it really wasn't needed. Removed passing the scene name into the ValidateSceneBeforeLoading method as that really didn't need to be passed in as a parameter either. --- .../SceneManagement/NetworkSceneManager.cs | 64 ++++++++----------- 1 file changed, 25 insertions(+), 39 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 07f5ec18cf..292cfd843f 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -277,9 +277,10 @@ internal NetworkSceneManager(NetworkManager networkManager) /// Name of the scene /// LoadSceneMode the scene is going to be loaded /// true (Valid) or false (Invalid) - internal bool ValidateSceneBeforeLoading(uint sceneIndex, string sceneName, LoadSceneMode loadSceneMode) + internal bool ValidateSceneBeforeLoading(uint sceneIndex, LoadSceneMode loadSceneMode) { var validated = true; + var sceneName = ScenesInBuild[(int)sceneIndex]; if (VerifySceneBeforeLoading != null) { validated = VerifySceneBeforeLoading.Invoke((int)sceneIndex, sceneName, loadSceneMode); @@ -466,20 +467,6 @@ internal uint GetBuildIndexFromSceneName(string sceneName) return uint.MaxValue; } - /// - /// Gets the scene name from the build index - /// - /// build index - /// scene name - internal string GetSceneNameFromBuildIndex(uint buildIndex) - { - if (IsSceneIndexValid(buildIndex)) - { - return ScenesInBuild[(int)buildIndex]; - } - return string.Empty; - } - /// /// Entry method for scene unloading validation /// @@ -672,8 +659,7 @@ public SceneEventProgressStatus UnloadScene(Scene scene) /// private void OnClientUnloadScene() { - var sceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex); - if (sceneName == string.Empty) + if (!IsSceneIndexValid(SceneEventData.SceneIndex)) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) { @@ -683,9 +669,11 @@ private void OnClientUnloadScene() return; } + var sceneName = ScenesInBuild[(int)SceneEventData.SceneIndex]; + if (!ServerSceneHandleToClientSceneHandle.ContainsKey(SceneEventData.SceneHandle)) { - throw new Exception($"Client failed to unload scene {GetSceneNameFromBuildIndex(SceneEventData.SceneIndex)} " + + throw new Exception($"Client failed to unload scene {sceneName} " + $"because we are missing the client scene handle due to the server scene handle {SceneEventData.SceneHandle} not being found!"); } @@ -694,7 +682,7 @@ private void OnClientUnloadScene() if (!ScenesLoaded.ContainsKey(sceneHandle)) { // Error scene handle not found! - throw new Exception($"Client failed to unload scene {GetSceneNameFromBuildIndex(SceneEventData.SceneIndex)} " + + throw new Exception($"Client failed to unload scene {sceneName} " + $"because the client scene handle {sceneHandle} was not found in ScenesLoaded!"); } s_IsSceneEventActive = true; @@ -766,7 +754,7 @@ private void OnSceneUnloaded() { SceneEventType = SceneEventData.SceneEventType, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), + SceneName = ScenesInBuild[(int)SceneEventData.SceneIndex], ClientId = m_NetworkManager.IsServer ? m_NetworkManager.ServerClientId : m_NetworkManager.LocalClientId }); @@ -833,7 +821,7 @@ public SceneEventProgressStatus LoadScene(string sceneName, LoadSceneMode loadSc SceneEventData.LoadSceneMode = loadSceneMode; // This both checks to make sure the scene is valid and if not resets the active scene event - s_IsSceneEventActive = ValidateSceneBeforeLoading(SceneEventData.SceneIndex, sceneName, loadSceneMode); + s_IsSceneEventActive = ValidateSceneBeforeLoading(SceneEventData.SceneIndex, loadSceneMode); if (!s_IsSceneEventActive) { return SceneEventProgressStatus.SceneFailedVerification; @@ -877,9 +865,7 @@ public SceneEventProgressStatus LoadScene(string sceneName, LoadSceneMode loadSc /// Stream data associated with the event private void OnClientSceneLoadingEvent(Stream objectStream) { - var sceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex); - - if (sceneName == string.Empty) + if (!IsSceneIndexValid(SceneEventData.SceneIndex)) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) { @@ -888,8 +874,10 @@ private void OnClientSceneLoadingEvent(Stream objectStream) return; } + var sceneName = ScenesInBuild[(int)SceneEventData.SceneIndex]; + // Run scene validation before loading a scene - if (!ValidateSceneBeforeLoading(SceneEventData.SceneIndex, sceneName, SceneEventData.LoadSceneMode)) + if (!ValidateSceneBeforeLoading(SceneEventData.SceneIndex, SceneEventData.LoadSceneMode)) { return; } @@ -914,7 +902,7 @@ private void OnClientSceneLoadingEvent(Stream objectStream) } else { - throw new Exception($"Could not find the scene handle {SceneEventData.SceneHandle} for scene {GetSceneNameFromBuildIndex(SceneEventData.SceneIndex)} " + + throw new Exception($"Could not find the scene handle {SceneEventData.SceneHandle} for scene {sceneName} " + $"during unit test. Did you forget to register this in the unit test?"); } return; @@ -1052,13 +1040,12 @@ private void OnServerLoadedScene(Scene scene) } s_IsSceneEventActive = false; - //First, notify local server that the scene was loaded OnSceneEvent?.Invoke(new SceneEvent() { SceneEventType = SceneEventData.SceneEventTypes.C2S_LoadComplete, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), + SceneName = ScenesInBuild[(int)SceneEventData.SceneIndex], ClientId = m_NetworkManager.ServerClientId, Scene = scene, }); @@ -1087,7 +1074,7 @@ private void OnClientLoadedScene(Scene scene) { SceneEventType = SceneEventData.SceneEventTypes.C2S_LoadComplete, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), + SceneName = ScenesInBuild[(int)SceneEventData.SceneIndex], ClientId = m_NetworkManager.LocalClientId, Scene = scene, }); @@ -1127,14 +1114,14 @@ internal void SynchronizeNetworkObjects(ulong clientId) // If we are the base scene, then we set the root scene index; if (activeScene == scene) { - if(!ValidateSceneBeforeLoading(sceneIndex, scene.name, LoadSceneMode.Single)) + if(!ValidateSceneBeforeLoading(sceneIndex, LoadSceneMode.Single)) { continue; } ClientSynchEventData.SceneIndex = sceneIndex; ClientSynchEventData.SceneHandle = scene.handle; } - else if (!ValidateSceneBeforeLoading(sceneIndex, scene.name, LoadSceneMode.Additive)) + else if (!ValidateSceneBeforeLoading(sceneIndex, LoadSceneMode.Additive)) { continue; } @@ -1168,8 +1155,7 @@ private void OnClientBeginSync() { var sceneIndex = SceneEventData.GetNextSceneSynchronizationIndex(); var sceneHandle = SceneEventData.GetNextSceneSynchronizationHandle(); - var sceneName = GetSceneNameFromBuildIndex(sceneIndex); - if (sceneName == string.Empty) + if (!IsSceneIndexValid(sceneIndex)) { if (NetworkLog.CurrentLogLevel <= LogLevel.Normal) { @@ -1177,12 +1163,12 @@ private void OnClientBeginSync() } return; } - + var sceneName = ScenesInBuild[(int)sceneIndex]; var activeScene = SceneManager.GetActiveScene(); var loadSceneMode = sceneIndex == SceneEventData.SceneIndex ? SceneEventData.LoadSceneMode : LoadSceneMode.Additive; // Always check to see if the scene needs to be validated - if (!ValidateSceneBeforeLoading(SceneEventData.SceneIndex, sceneName, loadSceneMode)) + if (!ValidateSceneBeforeLoading(SceneEventData.SceneIndex, loadSceneMode)) { return; } @@ -1251,7 +1237,7 @@ private void OnClientBeginSync() /// Netcode scene index that was loaded private void ClientLoadedSynchronization(uint sceneIndex, int sceneHandle) { - var sceneName = GetSceneNameFromBuildIndex(sceneIndex); + var sceneName = ScenesInBuild[(int)sceneIndex]; var nextScene = GetAndAddNewlyLoadedSceneByName(sceneName); if (!nextScene.isLoaded || !nextScene.IsValid()) @@ -1373,7 +1359,7 @@ private void HandleClientSceneEvent(Stream stream) OnSceneEvent?.Invoke(new SceneEvent() { SceneEventType = SceneEventData.SceneEventType, - SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), + SceneName = ScenesInBuild[(int)SceneEventData.SceneIndex], ClientId = m_NetworkManager.ServerClientId, LoadSceneMode = SceneEventData.LoadSceneMode, ClientsThatCompleted = SceneEventData.ClientsCompleted, @@ -1406,7 +1392,7 @@ private void HandleServerSceneEvent(ulong clientId, Stream stream) { SceneEventType = SceneEventData.SceneEventType, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), + SceneName = ScenesInBuild[(int)SceneEventData.SceneIndex], ClientId = clientId }); @@ -1428,7 +1414,7 @@ private void HandleServerSceneEvent(ulong clientId, Stream stream) { SceneEventType = SceneEventData.SceneEventType, LoadSceneMode = SceneEventData.LoadSceneMode, - SceneName = GetSceneNameFromBuildIndex(SceneEventData.SceneIndex), + SceneName = ScenesInBuild[(int)SceneEventData.SceneIndex], ClientId = clientId }); From 8c18e4b91b8d42a5b6aed0adbf10a89e19a4a7ea Mon Sep 17 00:00:00 2001 From: NoelStephensUnity <73188597+NoelStephensUnity@users.noreply.github.com> Date: Mon, 30 Aug 2021 16:09:24 -0500 Subject: [PATCH 20/20] refactor Minor adjustment for SceneEventProgress. Set the SceneIndex as opposed to name. --- .../Runtime/SceneManagement/NetworkSceneManager.cs | 6 +++--- .../Runtime/SceneManagement/SceneEventProgress.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs index 4f88786329..5e99d222a6 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs @@ -539,7 +539,7 @@ private SceneEventProgress ValidateSceneEvent(string sceneName, bool isUnloading } var sceneEventProgress = new SceneEventProgress(m_NetworkManager); - sceneEventProgress.SceneName = sceneName; + sceneEventProgress.SceneIndex = GetBuildIndexFromSceneName(sceneName); SceneEventProgressTracking.Add(sceneEventProgress.Guid, sceneEventProgress); if (!isUnloading) @@ -573,7 +573,7 @@ private bool OnSceneEventProgressCompleted(SceneEventProgress sceneEventProgress { using var nonNullContext = (InternalCommandContext)context; ClientSynchEventData.SceneEventGuid = sceneEventProgress.Guid; - ClientSynchEventData.SceneIndex = GetBuildIndexFromSceneName(sceneEventProgress.SceneName); + ClientSynchEventData.SceneIndex = sceneEventProgress.SceneIndex; ClientSynchEventData.SceneEventType = sceneEventProgress.SceneEventType; ClientSynchEventData.ClientsCompleted = sceneEventProgress.DoneClients; ClientSynchEventData.ClientsTimedOut = m_NetworkManager.ConnectedClients.Keys.Except(sceneEventProgress.DoneClients).ToList(); @@ -584,7 +584,7 @@ private bool OnSceneEventProgressCompleted(SceneEventProgress sceneEventProgress OnSceneEvent?.Invoke(new SceneEvent() { SceneEventType = sceneEventProgress.SceneEventType, - SceneName = sceneEventProgress.SceneName, + SceneName = ScenesInBuild[(int)sceneEventProgress.SceneIndex], ClientId = m_NetworkManager.ServerClientId, LoadSceneMode = sceneEventProgress.LoadSceneMode, ClientsThatCompleted = sceneEventProgress.DoneClients, diff --git a/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs b/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs index 63d8033c5b..d38df4ddfb 100644 --- a/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs +++ b/com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventProgress.cs @@ -88,7 +88,7 @@ internal class SceneEventProgress /// internal bool AreAllClientsDoneLoading { get; private set; } - internal string SceneName { get; set; } + internal uint SceneIndex { get; set; } internal Guid Guid { get; } = Guid.NewGuid();