Skip to content

Commit

Permalink
refactor(NetworkIdentity): removing NetworkIdentity.GetSceneIdentity
Browse files Browse the repository at this point in the history
Removing static field left over from mirror. only used at access internal collection sceneIds. sceneIds only exist to check if there are any duplicate scene ids

BREAKING CHANGE: `NetworkIdentity.GetSceneIdentity` has been removed
  • Loading branch information
James-Frowen committed Oct 21, 2021
1 parent a72d777 commit 34699ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
17 changes: 6 additions & 11 deletions Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,7 @@ internal set
}
}

/// <summary>
/// Keep track of all sceneIds to detect scene duplicates
/// </summary>
static readonly Dictionary<ulong, NetworkIdentity> sceneIds = new Dictionary<ulong, NetworkIdentity>();


[Header("Events")]
[SerializeField] AddLateEvent _onStartServer = new AddLateEvent();
Expand Down Expand Up @@ -367,13 +364,6 @@ internal set
/// <remarks>Can be used as hook to save player information</remarks>
public IAddLateEvent OnStopServer => _onStopServer;

/// <summary>
/// Gets the NetworkIdentity from the sceneIds dictionary with the corresponding id
/// </summary>
/// <param name="id"></param>
/// <returns>NetworkIdentity from the sceneIds dictionary</returns>
public static NetworkIdentity GetSceneIdentity(ulong id) => sceneIds[id];

/// <summary>
/// used when adding players
/// </summary>
Expand Down Expand Up @@ -445,6 +435,11 @@ void OnValidate()
}

#if UNITY_EDITOR
/// <summary>
/// Keep track of all sceneIds to detect scene duplicates
/// </summary>
internal static readonly Dictionary<ulong, NetworkIdentity> sceneIds = new Dictionary<ulong, NetworkIdentity>();

void AssignAssetID(GameObject prefab) => AssignAssetID(AssetDatabase.GetAssetPath(prefab));

void AssignAssetID(string path) => m_AssetId = AssetDatabase.AssetPathToGUID(path);
Expand Down
8 changes: 4 additions & 4 deletions Assets/Tests/Editor/NetworkIdentityCallbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,14 +285,14 @@ public void RemoveObserverInternal()
[Test]
public void AssignSceneID()
{
// Awake will have assigned a random sceneId of format 0x00000000FFFFFFFF
// OnValidate will have assigned a random sceneId of format 0x00000000FFFFFFFF
// -> make sure that one was assigned, and that the left part was
// left empty for scene hash
Assert.That(identity.sceneId, !Is.Zero);
Assert.That(identity.sceneId, Is.Not.Zero);
Assert.That(identity.sceneId & 0xFFFFFFFF00000000, Is.EqualTo(0x0000000000000000));

// make sure that Awake added it to sceneIds dict
Assert.That(NetworkIdentity.GetSceneIdentity(identity.sceneId), !Is.Null);
// make sure that OnValidate added it to sceneIds dict
Assert.That(NetworkIdentity.sceneIds[identity.sceneId], Is.Not.Null);
}

[Test]
Expand Down

0 comments on commit 34699ae

Please sign in to comment.