-
Notifications
You must be signed in to change notification settings - Fork 450
fix: PopulateScenePlacedObjects only checks IsSceneObject for null [MTT-3041] #1850
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NoelStephensUnity
merged 10 commits into
develop
from
fix/mtt-3041-populatesceneplacedobjects-sceneobject-check-logic
Mar 31, 2022
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d5810ac
fix
NoelStephensUnity 5e01bbb
style
NoelStephensUnity 1884bab
Update CHANGELOG.md
NoelStephensUnity 30462bd
Merge branch 'develop' into fix/mtt-3041-populatesceneplacedobjects-s…
NoelStephensUnity 79dfcb4
update
NoelStephensUnity a6bb5d0
test
NoelStephensUnity 2c50ced
style
NoelStephensUnity 8d9a91d
Merge branch 'develop' into fix/mtt-3041-populatesceneplacedobjects-s…
NoelStephensUnity fbb1a0e
test
NoelStephensUnity ec8b811
Merge branch 'fix/mtt-3041-populatesceneplacedobjects-sceneobject-che…
NoelStephensUnity File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...oject/Assets/Tests/Runtime/NetworkSceneManager/NetworkSceneManagerPopulateInSceneTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Collections; | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using UnityEngine.SceneManagement; | ||
using UnityEngine.TestTools; | ||
using NUnit.Framework; | ||
using Unity.Netcode; | ||
using Unity.Netcode.TestHelpers.Runtime; | ||
using Object = UnityEngine.Object; | ||
|
||
namespace TestProject.RuntimeTests | ||
{ | ||
public class NetworkSceneManagerPopulateInSceneTests : NetcodeIntegrationTest | ||
{ | ||
protected override int NumberOfClients => 0; | ||
|
||
|
||
protected Dictionary<uint, GameObject> m_InSceneObjectList = new Dictionary<uint, GameObject>(); | ||
|
||
protected override IEnumerator OnSetup() | ||
{ | ||
m_InSceneObjectList.Clear(); | ||
return base.OnSetup(); | ||
} | ||
|
||
protected override void OnServerAndClientsCreated() | ||
{ | ||
// Create one that simulates when an in-scene placed NetworkObject is first instantiated when | ||
// the scene is loaded (i.e. IsSceneObject is null) | ||
var inScenePrefab = CreateNetworkObjectPrefab("NewSceneObject"); | ||
var networkObject = inScenePrefab.GetComponent<NetworkObject>(); | ||
networkObject.IsSceneObject = null; | ||
networkObject.NetworkManagerOwner = m_ServerNetworkManager; | ||
m_InSceneObjectList.Add(networkObject.GlobalObjectIdHash, inScenePrefab); | ||
|
||
// Create one that simulates when an in-scene placed NetworkObject has already been instantiated | ||
// (i.e. IsSceneObject is true) which can happen if a client disconnects and then reconnects without | ||
// unloading/reloading any scenes. | ||
inScenePrefab = CreateNetworkObjectPrefab("SetInSceneObject"); | ||
networkObject = inScenePrefab.GetComponent<NetworkObject>(); | ||
networkObject.IsSceneObject = true; | ||
networkObject.NetworkManagerOwner = m_ServerNetworkManager; | ||
m_InSceneObjectList.Add(networkObject.GlobalObjectIdHash, inScenePrefab); | ||
} | ||
|
||
[UnityTest] | ||
public IEnumerator PopulateScenePlacedObjectsTest() | ||
{ | ||
var activeScene = SceneManager.GetActiveScene(); | ||
|
||
m_ServerNetworkManager.SceneManager.PopulateScenePlacedObjects(activeScene, true); | ||
var scenePlacedNetworkObjects = m_ServerNetworkManager.SceneManager.ScenePlacedObjects; | ||
foreach (var entry in m_InSceneObjectList) | ||
{ | ||
// Verify the GlobalObjectIdHash for this object has an entry | ||
Assert.IsTrue(scenePlacedNetworkObjects.ContainsKey(entry.Key), $"Failed to find {nameof(NetworkObject.GlobalObjectIdHash)}({entry.Key}) for {entry.Value.name} in the {nameof(NetworkSceneManager.ScenePlacedObjects)}!"); | ||
|
||
// Verify the active scene for this object has an entry | ||
Assert.IsTrue(scenePlacedNetworkObjects[entry.Key].ContainsKey(activeScene.handle), $"Failed to find the scene handle {activeScene.handle} ({activeScene.name}) entry for {entry.Value.name} in the {nameof(NetworkSceneManager.ScenePlacedObjects)}!"); | ||
|
||
// Verify the GameObject is the same one | ||
var inSceneGameObject = scenePlacedNetworkObjects[entry.Key][activeScene.handle].gameObject; | ||
Assert.IsTrue(inSceneGameObject == entry.Value, $"{nameof(GameObject)} {entry.Value.name} is not the same as {inSceneGameObject.name}!"); | ||
} | ||
|
||
yield break; | ||
} | ||
|
||
protected override IEnumerator OnTearDown() | ||
{ | ||
foreach (var spawnedInstance in m_InSceneObjectList) | ||
{ | ||
Object.Destroy(spawnedInstance.Value); | ||
} | ||
return base.OnTearDown(); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
.../Assets/Tests/Runtime/NetworkSceneManager/NetworkSceneManagerPopulateInSceneTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.