-
Notifications
You must be signed in to change notification settings - Fork 450
feat: Instantiation payload support for INetworkPrefabInstanceHandler #3430
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
Closed
Closed
Changes from all commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
3ff9326
feat: Network Object Instantiation Payload
Extrys 7f395ba
Merge branch 'Unity-Technologies:develop-2.0.0' into develop-2.0.0
Extrys f0d49aa
insight on INetworkInstantiationPayloadSynchronizer in the INetworkPr…
Extrys 3f34e83
cleaning diff
Extrys 47680f5
Some fixes for object instantiated in the server without handler
Extrys b8765a2
Merge branch 'Unity-Technologies:develop-2.0.0' into develop-2.0.0
Extrys de9fc05
Simplified approach that reuses createObjectMesage bufferSerializer
Extrys 6419ad0
commented non generic serialization methods
Extrys 1d746fe
Merge branch 'feat/InstantiationPayload' into develop-2.0.0
Extrys 4005c50
Cleaning diff
Extrys a103e49
Cleaning diff
Extrys 43e8ff4
Review Changes
Extrys 0fab0a6
Some more renamigs for making it more closer to unity's naming
Extrys 36a041c
Merge branch 'develop-2.0.0' into develop-2.0.0
Extrys fd787e8
Merge branch 'develop-2.0.0' into develop-2.0.0
Extrys 96b7af6
Added buffer safety and Tests
Extrys e49cb63
Merge remote-tracking branch 'origin/develop-2.0.0' into develop-2.0.0
Extrys 89eb5c4
Log text change for more clarity
Extrys adead9d
Renamed HasInstantiationPayload to HasInstantiationData to mantain na…
Extrys e4481b2
CHANGELOG.md entry added
Extrys 3522fc0
Merge branch 'Unity-Technologies:develop-2.0.0' into develop-2.0.0
Extrys 6757e63
Solved late-join problems
Extrys a5670e3
cleaning diff
Extrys 426d82c
Updated comment
Extrys 6899764
Added more Buffer/Synchronization safety changes
Extrys c1d6503
Improves handler lookup performance
Extrys 096c85c
New stateless approach working flawless
Extrys 7f6c9c7
Test updated
Extrys 89dd4c0
Test refactor and included late joining test
Extrys b992b7c
clean diff
Extrys 1f27a68
Changelog updated
Extrys 5b68637
Adds comment for data handling workaround
Extrys d42bf95
Cleaning diff, fixed comment accidentally using a chinese version of …
Extrys 4c7f63d
New requirements fullfilled
Extrys 2b6befd
removed yet unused method
Extrys 3dea6aa
extending the interface to directly allow different injection patterns
Extrys 015e384
Merge branch 'develop-2.0.0' into develop-2.0.0
Extrys 536642b
Pure stateless, non generic approach for sending data through fastBuf…
Extrys fa774e7
Merge branch 'develop-2.0.0' into develop-2.0.0
Extrys 0d62ea4
renamings from Inject to Set
Extrys 3fad66c
Inlined functions and removed terniary call
Extrys 81d574a
Changed instantiation data throw by an error log
Extrys 36ec35f
Abstract class approach, removed wrapper
Extrys 7326a83
Removed the BufferSerializer From the GetInstantiationDataReader method
Extrys e8a661c
Using Approach A (unsafe block) to avoid allocations for FastBufferRe…
Extrys f47f3d4
Most review comments addressed
Extrys 6b3963f
Renamed Interface in the Changelog
Extrys fc43642
Update formatting and use NetcodeIntegrationTest for test class
EmandM 729f4d6
fixed late join bug
Extrys fea9d7d
Merge branch 'develop-2.0.0' into develop-2.0.0
Extrys 900c7ee
Using BytePacker utilities to optimize the size of the serialized int…
Extrys 886697e
Updated comment to match new interface name
Extrys 4586a6e
Merge branch 'develop-2.0.0' into develop-2.0.0
Extrys 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
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
41 changes: 41 additions & 0 deletions
41
com.unity.netcode.gameobjects/Runtime/Spawning/NetworkPrefabInstanceHandlerWithData.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,41 @@ | ||
using UnityEngine; | ||
|
||
namespace Unity.Netcode | ||
{ | ||
/// <summary> | ||
/// Specialized version of <see cref="INetworkPrefabInstanceHandler"/> that receives | ||
/// custom instantiation data injected by the server before spawning. | ||
/// </summary> | ||
public abstract class NetworkPrefabInstanceHandlerWithData<T> : INetworkPrefabInstanceHandlerWithData where T : struct, INetworkSerializable | ||
{ | ||
public abstract NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, T instantiationData); | ||
|
||
public abstract void Destroy(NetworkObject networkObject); | ||
|
||
bool INetworkPrefabInstanceHandlerWithData.HandlesDataType<TK>() => typeof(T) == typeof(TK); | ||
|
||
NetworkObject INetworkPrefabInstanceHandlerWithData.Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, FastBufferReader reader) | ||
{ | ||
var startPosition = reader.Position; | ||
reader.ReadValueSafe(out T payload); | ||
var length = reader.Position - startPosition; | ||
|
||
NetworkObject networkObject = Instantiate(ownerClientId, position, rotation, payload); | ||
reader.Seek(startPosition); | ||
if (networkObject.InstantiationData == null || networkObject.InstantiationData.Length != length) | ||
{ | ||
networkObject.InstantiationData = new byte[length]; | ||
} | ||
reader.ReadBytesSafe(ref networkObject.InstantiationData, length); | ||
return networkObject; | ||
} | ||
|
||
NetworkObject INetworkPrefabInstanceHandler.Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation) => Instantiate(ownerClientId, position, rotation, default); | ||
} | ||
|
||
internal interface INetworkPrefabInstanceHandlerWithData : INetworkPrefabInstanceHandler | ||
{ | ||
bool HandlesDataType<T>(); | ||
NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation, FastBufferReader reader); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
com.unity.netcode.gameobjects/Runtime/Spawning/NetworkPrefabInstanceHandlerWithData.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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.