diff --git a/Netick/Editor/Netick.CodeGen.dll b/Netick/Editor/Netick.CodeGen.dll
index 8411134..ef56173 100644
Binary files a/Netick/Editor/Netick.CodeGen.dll and b/Netick/Editor/Netick.CodeGen.dll differ
diff --git a/Netick/Editor/Netick.Unity.Editor.dll b/Netick/Editor/Netick.Unity.Editor.dll
index 372e1ea..28488d2 100644
Binary files a/Netick/Editor/Netick.Unity.Editor.dll and b/Netick/Editor/Netick.Unity.Editor.dll differ
diff --git a/Netick/Editor/Netick.Unity.Pro.Editor.dll b/Netick/Editor/Netick.Unity.Pro.Editor.dll
index 694d898..1f00a5a 100644
Binary files a/Netick/Editor/Netick.Unity.Pro.Editor.dll and b/Netick/Editor/Netick.Unity.Pro.Editor.dll differ
diff --git a/Netick/Editor/Unity.Netick.CodeGen.dll b/Netick/Editor/Unity.Netick.CodeGen.dll
index 0c8a6a5..8668265 100644
Binary files a/Netick/Editor/Unity.Netick.CodeGen.dll and b/Netick/Editor/Unity.Netick.CodeGen.dll differ
diff --git a/Netick/Runtime/Netick.Pro.dll b/Netick/Runtime/Netick.Pro.dll
index 59c6392..248511b 100644
Binary files a/Netick/Runtime/Netick.Pro.dll and b/Netick/Runtime/Netick.Pro.dll differ
diff --git a/Netick/Runtime/Netick.Pro.xml b/Netick/Runtime/Netick.Pro.xml
index e9d7d55..24a1c56 100644
--- a/Netick/Runtime/Netick.Pro.xml
+++ b/Netick/Runtime/Netick.Pro.xml
@@ -15,7 +15,6 @@
The input source to compensate for.
The max distance the ray should check for collisions.
A that is used to selectively ignore Colliders when casting a ray.
- Choose whether you want to include normal unity colliders, or only Netick HitShapes.
Returns true if the ray intersects with a Collider/HitShape, otherwise false.
@@ -38,7 +37,6 @@
The input source to compensate for.
A defines which layers of colliders to include in the query.
- Choose whether you want to include normal unity colliders, or only Netick HitShapes.
Choose whether you want to include only one HitShape per HitShapeContainer
diff --git a/Netick/Runtime/Netick.Unity.Pro.dll b/Netick/Runtime/Netick.Unity.Pro.dll
index 6db9788..dffb5a5 100644
Binary files a/Netick/Runtime/Netick.Unity.Pro.dll and b/Netick/Runtime/Netick.Unity.Pro.dll differ
diff --git a/Netick/Runtime/Netick.Unity.dll b/Netick/Runtime/Netick.Unity.dll
index f7df504..c1c196a 100644
Binary files a/Netick/Runtime/Netick.Unity.dll and b/Netick/Runtime/Netick.Unity.dll differ
diff --git a/Netick/Runtime/Netick.Unity.xml b/Netick/Runtime/Netick.Unity.xml
index e6ca0d8..dec8570 100644
--- a/Netick/Runtime/Netick.Unity.xml
+++ b/Netick/Runtime/Netick.Unity.xml
@@ -4,674 +4,16 @@
Netick.Unity
-
-
- This component is used to replicate the position and rotation of an object. Therefore, it’s the same as the Network Transform, the difference is that Network Rigidbody must be used if you want to have client-side prediction over PhysX objects since it replicates several other properties necessary for correct prediction.
-
-
-
-
- Use this to enable/disable Physics Prediction in the client at runtime.
-
-
-
-
- Returns true if this is the server.
-
-
-
-
- Returns true if this is a client.
-
-
-
-
- Returns true if this is a host.
-
-
-
-
- Returns true if this is a player, which is the case when running as a Client, Host, or in Single-Player mode.
-
-
-
-
- Configuration data for Netick.
-
-
-
-
- Use this to associate an object with this sandbox.
-
-
-
-
- The associated with this . Always use this to perform physics queries inside the sandbox instead of .
-
-
-
-
- The associated with this . Always use this to perform physics queries inside the sandbox instead of .
-
-
-
-
- The associated with this .
-
-
-
-
- Returns true if this has been started.
-
-
-
-
- [Client Only] The of the server you are connected to. Returns null if you are not connected to any server, or if you are the server.
-
-
-
-
- [Client Only] Returns true if this client is currently connected to a server.
-
-
-
-
- The underlying transport used for low-level networking.
-
-
-
-
- A list containing all connected clients currently.
- Note: if you want the clients + the server, use .
-
-
-
-
- A list containing all connected clients currently, in addition to the server (when started as a host).
- Note: if you only want the clients, use .
-
-
-
-
- The server the client is connected to.
-
-
-
-
- A dictionary containing all simulated/registered network objects [] currently.
-
-
-
-
- This player.
-
-
-
-
- Time period between network simulation steps. Same as
-
-
-
-
- Current simulation tick.
- On the server, it's always going forward/increasing.
- On the client, during resimulations it returns the current resimulated tick. To check for resimulations, use .
-
-
-
-
- Last received tick on the client. On the server, it returns the same value as
-
-
-
-
- Last predicted tick.
- On the client, it always returns the predicted tick of the client, regardless of whether it's a resimulation or not.
- On the server, it returns the same value as Sandbox.Tick
-
-
-
-
- Returns true if we are currently resimulating a previous input/tick of the past. On the server, it always returns false since only the clients resimulate.
-
-
-
-
- Incoming data in kilobytes per second (KBps).
-
-
-
-
- Outgoing data in kilobytes per second (KBps).
-
-
-
-
- [Client Only] Estimation of incoming packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
-
-
-
-
- [Client Only] Estimation of outgoing packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
-
-
-
-
- [Client Only] Interpolation delay in seconds.
-
-
-
-
- [Client Only] The round-trip time (RTT) of the client in seconds.
-
-
-
-
- Always always returns null except when called inside the body of an RPC method, it returns the we are executing RPCs from.
-
-
-
-
-
- Called after all NetworkFixedUpdate methods have been executed.
- Note: it's called with every resimulation on the client.
-
-
-
-
- Called before any NetworkFixedUpdate method have been executed.
- Note: it's called with every resimulation on the client.
-
-
-
-
- Gets a specific input for the next tick.
-
-
-
-
-
-
-
- Sets a specific input for the next tick.
-
-
-
-
-
-
-
- Gets the with the specified id. Returns null in case no object with that id exists.
-
- The id of the
-
-
-
-
- Tries to get the with the specified id.
-
- The id of the
-
-
-
-
- Tries to get the of a with the specified id.
-
- The id of the network object
-
-
-
-
- Converts ticks to time in seconds.
-
-
-
-
-
-
- Converts ticks to time in seconds.
-
-
-
-
-
-
- Converts time (in seconds) to ticks.
-
-
-
-
-
- Attachs a to the simulation.
-
-
-
-
-
- Deattachs a from the simulation.
-
-
-
-
-
- [Client Only] Connects to a remote server.
- Note: if you are already connected to a server, and you want to connect to a different one, you have to disconnect before calling this. Otherwise this method does nothing.
- Note: connectionData array length should not be more than 300 if you are using Netick Transport.
-
- IP address of the server.
- Port of the server.
- RawValue sent with the connection request. Could be used to decide whether or not to allow the connection.
-
-
-
- [Server Only] Disconnects a client from the server.
-
- The client to be disconnected.
-
-
-
- [Client Only] Disconnects this client from the server.
-
-
-
-
- [Server Only] Creates a match. Only functional if the low-level transport has support for matchmaking.
-
- Name of the match.
-
-
-
- Requests an update to the match list. Only functional if the low-level transport has support for matchmaking.
-
-
-
-
- [Server Only] Switches to a different scene. This must be called instead of or its variations.
-
- SceneBuildIndex of the desired scene.
-
-
-
- [Server Only] Switches to a different scene. This must be called instead of or its variations.
-
- SceneBuildIndex of the desired scene.
-
-
-
- [Server Only] Loads a scene asynchronously.
-
-
-
-
-
- [Server Only] Unloads a scene asynchronously.
-
-
-
-
- Initializes the pool for the specified prefab. After this method has been called for a certain prefab, all instances of that prefab will be recycled and reset when created/destroyed.
- Note: this method should only be called on , in other words, just after Netick has been started.
-
- Prefab to enable pooling for.
- How many instances to be preloaded.
- Pass true to hide inactive pool members.
-
-
-
- Gets a Network Prefab by name.
- Note: this causes GC.
-
-
- The Network Prefab
-
-
-
- Instantiates a prefab. This must be called instead of or its variations.
- Note: this must be called only for non-networked prefabs. If you want to instantiate a network prefab, use instead.
-
- The prefab to be instantiated.
- Position of the instantiated object.
- Rotation of the instantiated object.
-
-
-
-
- [Server Only] Instantiates a network prefab.
- This must only be called on the server, since only the server can instantiate network prefabs.
- Note: make sure the prefab has been registered.
- Note: the specified input source will be given to every child of this prefab.
-
- The prefab to be instantiated.
- Position of the instantiated object.
- Rotation of the instantiated object.
- Input source of the instantiated object.
-
-
-
-
- [Server Only] Destroys a network object.
- Note: never call this on a child of the original prefab, only the root of the prefab.
-
- The object to destroy.
-
-
A networked array.
-
-
- This component is used to replicate the position and rotation of an object. Therefore, it’s the same as the Network Transform, the difference is that Network Rigidbody 2D must be used if you want to have client-side prediction over Box2D objects since it replicates several other properties necessary for correct prediction.
-
-
-
-
- Any GameObject which needs to be synced/replicated must have a Network Object component. It’s the component that tells Netick a GameObject is networked. Although not every child GameObject needs it, only the root has to have a Network Object.
-
-
-
-
- The parent of this object.
-
-
-
-
- Returns true if this is a client.
-
-
-
-
- Returns true if this is the server.
-
-
-
-
- Returns true if this is the owner of this Object. In this version of Netick: Server=Owner.
-
-
-
-
- Returns true if this is providing inputs for this .
-
-
-
-
- Returns true if we neither provide inputs nor own this .
-
-
-
-
- Returns the source (/) of inputs for this . If the source of inputs is remote (from a client) it returns that , while on the
- input source itself it returns the local .
-
-
-
-
- The interest group of this object. This can only be changed if BroadPhaseFilter is set to Custom.
-
-
-
-
- Returns true if we are currently resimulating a previous input of the past. On the server, it always returns false since only the clients resimulate.
-
-
-
-
- Returns true if this has been added to the simulation by Netick, and thus has a valid id.
-
-
-
-
- Returns the networked state size of this object in bytes.
-
-
-
-
- Sets the state of this object. Ignores [OnChanged] callbacks when setting the data.
-
-
-
-
-
- [Owner/InputSource Only] Changes the parent of this object.
-
- The object which will become the parent of this object.
-
-
-
- This component is used to replicate the position and rotation of an object.
-
-
-
-
- Instantly moves the object. By calling this method, the object won't be interpolated for one tick.
-
-
-
-
-
- Instantly moves the object. By calling this method, the object won't be interpolated for one tick.
-
-
-
-
-
- Instantly moves the object. By calling this method, the object won't be interpolated for one tick.
-
-
-
- Add this component to a GameObject to ensure only a single instance of it will exist at the same time, across all sandboxes.
+ AddEntity this component to a GameObject to ensure only a single instance of it will exist at the same time, across all sandboxes.
-
-
- Config class for Netick.
-
-
-
-
- The containing this .
-
-
-
-
- The this behaviour is attached to.
-
-
-
-
- Called when this behaviour has been added to the simulation.
-
-
-
-
- Called when this behaviour has been removed from the simulation.
-
-
-
-
- Called every frame. Executed before NetworkFixedUpdate.
-
-
-
-
- Called every fixed-time network step. Any changes to the networked state should happen here.
- On the client, if you are the Input Source or if this Object.PredictionMode is set to Everyone, it will be called several times in one update/tick during resimulations. To check for resimulations, use [].
-
-
-
-
- Called every frame. Executed after NetworkUpdate and NetworkFixedUpdate.
-
- IMPORTANT NOTE: properties (which can be interpolated) marked with [] attribute will return interpolated values when accessed in this method.
-
-
-
- The network id of this .
-
-
-
-
- The network id of this .
-
-
-
-
- Returns true if this is a client.
-
-
-
-
- Returns true if this is the server.
-
-
-
-
- Returns true if this is the owner of this Object. In this version of Netick: Server=Owner.
-
-
-
-
- Returns true if this is providing inputs to this Object.
-
-
-
-
- Returns true if we neither provide inputs nor own this .
-
-
-
-
- Returns true if we are currently resimulating a previous input of the past. On the server, it always returns false since only the clients resimulate.
-
-
-
-
- On the client, it returns true only if the client is predicting this object. On the server, it always returns true.
-
-
-
-
- Returns the source (/) of inputs for this . If the source of inputs is remote (from a client) it returns that , while on the
- input source itself it returns the local .
-
-
-
-
- Returns the networked state size of this behavior in bytes.
-
-
-
-
- Sets the state of this behavior. Ignores [OnChanged] callbacks when setting the data.
-
-
-
-
-
- Fetches a network input for this tick. Returns false if no input source is currently providing inputs to this Object, or when input loss occurs (in case of a remote input source).
-
-
-
-
- Fetches a network input for this tick. Returns false if no input source is currently providing inputs to this Object, or when input loss occurs (in case of a remote input source).
-
-
-
-
- Called on the server when the input source of this Object has disconnected.
-
-
-
-
- Called on the client when the server confirms that this object has been successfully spawn-predicted and therefore has a valid SceneLoadId.
-
-
-
-
- This component is used to replicate Unity's Animator parameters and states.
-
-
-
-
- Manages Netick and its sandboxes, and is used to start and shut down Netick.
-
-
-
-
- Initializes Netick. This is automatically called when you start Netick.
- If you don't provide a , Netick will use the default config, which can be modified/found in (Netick -> Settings).
-
-
-
-
- Shuts down Netick and destroys all sandboxes. The shutdown will occur in the next frame. For immediate shutdown, use:
-
-
-
-
- Shuts down Netick and destroys all sandboxes immediately.
-
-
-
-
- Shuts down a specific sandbox.
-
- The sandbox to shut down.
-
-
-
- Focus on a specific sandbox.
-
- The sandbox to focus on.
-
-
-
- Starts both a client (or clients) and a server.
-
- Network port.
- Number of client sandboxes to create.
-
-
-
-
- Starts multiple peers together.
-
- Network port.
- Number of clients to create.
- Should we start a server too.
-
-
-
-
-
- Starts Netick as a client.
-
- The sandbox representing the client
-
-
-
- Starts Netick in single player mode.
-
- The sandbox representing the server
-
-
-
- Starts Netick as a host.
-
- Network port.
- The sandbox representing the server
-
-
-
- Starts Netick as a server.
-
- Network port.
- The sandbox representing the server
-
Called on the server when a client tries to connect. Use to decide whether or not to allow this client to connect.
@@ -748,6 +90,16 @@
+
+
+ Called on when a specific player has joined the game. This is synced to all clients, including late-joiners..
+
+
+
+
+ Called on when a specific player has left the game. This is synced to all clients, including late-joiners..
+
+
Called on the server when a specific client has connected.
@@ -788,5 +140,871 @@
+
+
+ Any GameObject which needs to be synced/replicated must have a Network Object component. It’s the component that tells Netick a GameObject is networked. Although not every child GameObject needs it, only the root has to have a Network Object.
+
+
+
+
+ Returns true if this has been added to the simulation by Netick, and thus has a valid id.
+
+
+
+
+ The parent of this object.
+
+
+
+
+ Returns true if this is a client.
+
+
+
+
+ Returns true if this is the server.
+
+
+
+
+ Returns true if this is the owner of this Object. In this version of Netick: Server=Owner.
+
+
+
+
+ Returns true if this is providing inputs for this .
+
+
+
+
+ Returns true if we neither provide inputs nor own this .
+
+
+
+
+ Returns true if we are currently resimulating a previous input of the past. On the server, it always returns false since only the clients resimulate.
+
+
+
+
+ Returns the source (/) of inputs for this . If the source of inputs is remote (from a client) it returns that , while on the
+ input source itself it returns the local .
+
+
+
+
+ Returns the NetworkPlayerId of the input source of this object. This is synced for every client.
+
+
+
+
+ The interest group of this object. This can only be changed if BroadPhaseFilter is set to Custom.
+
+
+
+
+ Returns the networked state size of this object in bytes.
+
+
+
+
+ Zeros out the networked state memory of this object. Ignores InputSource Relevancy.
+
+
+
+
+ Copies the state of this object into target.
+
+
+
+
+ Copies the state of this object into target.
+
+
+
+
+ Sets the state of this object. Ignores InputSource Relevancy.
+
+
+
+
+ Sets the state of this object. Ignores InputSource Relevancy.
+
+
+
+
+ [Owner/InputSource Only] Changes the parent of this object.
+
+ The object which will become the parent of this object.
+
+
+
+ This component is used to replicate the position and rotation of an object. Therefore, it’s the same as the Network Transform, the difference is that Network Rigidbody 2D must be used if you want to have client-side prediction over Box2D objects since it replicates several other properties necessary for correct prediction.
+
+
+
+
+ This component is used to replicate the position and rotation of an object. Therefore, it’s the same as the Network Transform, the difference is that Network Rigidbody must be used if you want to have client-side prediction over PhysX objects since it replicates several other properties necessary for correct prediction.
+
+
+
+
+ The containing this .
+
+
+
+
+ The this behaviour is attached to.
+
+
+
+
+ Called when this behaviour has been added to the simulation.
+
+
+
+
+ Called when this behaviour has been removed from the simulation.
+
+
+
+
+ Called every frame. Executed before NetworkFixedUpdate.
+
+
+
+
+ Called every fixed-time network step. Any changes to the networked state should happen here.
+ On the client, if you are the Input Source or if this Object.PredictionMode is set to Everyone, it will be called several times in one update/tick during resimulations. To check for resimulations, use [].
+
+
+
+
+ Called every frame. Executed after NetworkUpdate and NetworkFixedUpdate.
+
+ IMPORTANT NOTE: properties (which can be interpolated) marked with [] attribute will return interpolated values when accessed in this method.
+
+
+
+ The network id of this .
+
+
+
+
+ The network id of this .
+
+
+
+
+ Returns true if this is a client.
+
+
+
+
+ Returns true if this is the server.
+
+
+
+
+ Returns true if this is the owner of this Object. In this version of Netick: Server=Owner.
+
+
+
+
+ Returns true if this is providing inputs to this Object.
+
+
+
+
+ Returns true if we neither provide inputs nor own this .
+
+
+
+
+ Returns true if we are currently resimulating a previous input of the past. On the server, it always returns false since only the clients resimulate.
+
+
+
+
+ On the client, it returns true only if the client is predicting this object. On the server, it always returns true.
+
+
+
+
+ Returns the source (/) of inputs for this . If the source of inputs is remote (from a client) it returns that , while on the
+ input source itself it returns the local .
+
+
+
+
+ Returns the NetworkPlayerId of the input source of this object. This is synced for every client.
+
+
+
+
+ Returns the networked state size of this behavior in bytes.
+
+
+
+
+ Copies the state of this behavior into target.
+
+
+
+
+ Copies the state of this behavior into target.
+
+
+
+
+ Sets the state of this behavior. Ignores InputSource Relevancy.
+
+
+
+
+
+ Sets the state of this behavior. Ignores InputSource Relevancy.
+
+
+
+
+ Zeros out the networked state memory of this behavior. Ignores InputSource Relevancy.
+
+
+
+
+ Fetches a network input for this tick. Returns false if no input source is currently providing inputs to this Object, or when input loss occurs (in case of a remote input source).
+
+
+
+
+ Fetches a network input for this tick. Returns false if no input source is currently providing inputs to this Object, or when input loss occurs (in case of a remote input source).
+
+
+
+
+ Called on the server when the input source of this Object has disconnected.
+
+
+
+
+ This component is used to replicate Unity's Animator parameters and states.
+
+
+
+
+ This component is used to replicate the position and rotation of an object.
+
+
+
+
+ Instantly moves the object. By calling this method, the object won't be interpolated for one tick.
+
+
+
+
+
+ Instantly moves the object. By calling this method, the object won't be interpolated for one tick.
+
+
+
+
+
+ Instantly moves the object. By calling this method, the object won't be interpolated for one tick.
+
+
+
+
+
+ NetworkSandbox represents a networked game instance in Netick. It encapsulates the entire simulation state for that instance.
+
+
+
+
+ Initializes the pool for the specified prefab. After this method has been called for a certain prefab, all instances of that prefab will be recycled and reset when created/destroyed.
+ Note: this method should only be called on , in other words, just after Netick has been started.
+
+ Prefab to enable pooling for.
+ How many instances to be preloaded.
+ Pass true to hide inactive pool members.
+
+
+
+ Gets a Network Prefab by name.
+ Note: this causes GC.
+
+
+ The Network Prefab
+
+
+
+ [Server Only] Instantiates a network prefab.
+ This must only be called on the server, since only the server can instantiate network prefabs.
+ Note: make sure the prefab has been registered.
+ Note: the specified input source will be given to every child of this prefab.
+
+
+
+
+ [Server Only] Instantiates a network prefab.
+ This must only be called on the server, since only the server can instantiate network prefabs.
+ Note: make sure the prefab has been registered.
+ Note: the specified input source will be given to every child of this prefab.
+
+
+
+
+ [Server Only] Instantiates a network prefab.
+ This must only be called on the server, since only the server can instantiate network prefabs.
+ Note: make sure the prefab has been registered.
+ Note: the specified input source will be given to every child of this prefab.
+
+
+
+
+ [Server Only] Instantiates a network prefab.
+ This must only be called on the server, since only the server can instantiate network prefabs.
+ Note: make sure the prefab has been registered.
+ Note: the specified input source will be given to every child of this prefab.
+
+
+
+
+ [Server Only] Destroys a network object.
+ Note: never call this on a child of the original prefab, only the root of the prefab.
+
+ The object to destroy.
+
+
+
+
+ Instantiates a prefab. This must be called instead of or its variations.
+ Note: this must be called only for non-networked prefabs. If you want to instantiate a network prefab, use instead.
+
+
+
+
+ Gets the the associated NetworkObject (player object) with this player.
+
+
+
+
+
+ Gets the the associated script (player object) of type with this player.
+
+
+
+
+
+ Tries to get the the associated NetworkObject (player object) with this player.
+
+
+
+
+
+ Tries to get the the associated script (player object) of type with this player.
+
+
+
+
+
+ Gets the the associated NetworkObject (player object) with this player.
+
+
+
+
+
+ Gets the the associated script (player object) of type with this player.
+
+
+
+
+
+ Tries to get the the associated NetworkObject (player object) with this player.
+
+
+
+
+
+ Tries to get the the associated script (player object) of type with this player.
+
+
+
+
+
+ [Server Only] Sets the the associated NetworkObject (player object) with this player.
+
+
+
+
+
+ Gets the the associated (player object) with the local player.
+
+
+
+
+
+ Gets the the associated script (player object) of type with the local player.
+
+
+
+
+
+ Tries to get the the associated (player object) with the local player.
+
+
+
+
+
+ Tries to get the the associated script (player object) of type with the local player.
+
+
+
+
+
+ Retrieves the associated with the given .
+
+ On the server, this method can return any player by their ID. On the client, it only returns the local player or the server player.
+
+
+
+
+
+ Checks if a player with the specified exists in the simulation.
+
+
+
+
+ Gets the with the specified id. Returns null in case no object with that id exists.
+
+ The id of the
+
+
+
+
+ Tries to get the with the specified id.
+
+ The id of the
+
+
+
+
+ Tries to get the of a with the specified id.
+
+ The id of the network object
+
+
+
+
+ Converts ticks to time in seconds.
+
+
+
+
+
+
+ Converts ticks to time in seconds.
+
+
+
+
+
+
+ Converts time (in seconds) to ticks.
+
+
+
+
+
+ Attaches a to the simulation.
+
+
+
+
+
+ Detaches a from the simulation.
+
+
+
+
+
+ Use this to associate an object with this sandbox.
+
+
+
+
+ Name of this sandbox.
+
+
+
+
+ The NetickEngine instance attached to this sandbox.
+
+
+
+
+ The mode this sandbox was started in.
+
+
+
+
+ Returns true if this has been started.
+
+
+
+
+ Returns true if this is the server.
+
+
+
+
+ Returns true if this is a client.
+
+
+
+
+ Returns true if this is a host.
+
+
+
+
+ Returns true if this is a player, which is the case when running as a Client, Host, or in Single-Player mode.
+
+
+
+
+ Configuration data for Netick.
+
+
+
+
+ The associated with this . Always use this to perform physics queries inside the sandbox instead of .
+
+
+
+
+ The associated with this . Always use this to perform physics queries inside the sandbox instead of .
+
+
+
+
+ The associated with this .
+
+
+
+
+ Use this to enable/disable Physics Prediction in the client at runtime.
+
+
+
+
+ [Client Only] The of the server you are connected to. Returns null if you are not connected to any server, or if you are the server.
+
+
+
+
+ [Client Only] Returns true if this client is currently connected to a server.
+
+
+
+
+ The underlying transport used for low-level networking.
+
+
+
+
+ A list containing the ids of all connected players currently. This list is networked and synced to all clients.
+
+
+
+
+ A list containing all connected clients currently.
+ Note: if you want the clients + the server, use .
+
+
+
+
+ A list containing all connected clients currently, in addition to the server (when started as a host).
+ Note: if you only want the clients, use .
+
+
+
+
+ The server the client is connected to.
+
+
+
+
+ A dictionary containing all simulated/registered network objects [] currently.
+
+
+
+
+ This player.
+
+
+
+
+ Time period between network simulation steps. Same as
+
+
+
+
+ Current simulation tick.
+ On the server, it's always going forward/increasing.
+ On the client, during resimulations it returns the current resimulated tick. To check for resimulations, use .
+
+
+
+
+ Last received tick on the client. On the server, it returns the same value as
+
+
+
+
+ Last predicted tick.
+ On the client, it always returns the predicted tick of the client, regardless of whether it's a resimulation or not.
+ On the server, it returns the same value as Sandbox.Tick
+
+
+
+
+ Returns true if we are currently resimulating a previous input/tick of the past. On the server, it always returns false since only the clients resimulate.
+
+
+
+
+ Returns true if this NetworkFixedUpdate call is the first one executed in this frame. This excludes resimulations, and it only refers to new/forward ticks.
+
+
+
+
+ Returns true if this NetworkFixedUpdate call is the last one executed in this frame. This excludes resimulations, and it only refers to new/forward ticks.
+
+
+
+
+ Incoming data in kilobytes per second (KBps).
+
+
+
+
+ Outgoing data in kilobytes per second (KBps).
+
+
+
+
+ [Client Only] Estimation of incoming packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
+
+
+
+
+ [Client Only] Estimation of outgoing packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
+
+
+
+
+ [Client Only] Interpolation delay in seconds.
+
+
+
+
+ [Client Only] The round-trip time (RTT) of the client in seconds.
+
+
+
+
+ Always always returns null except when called inside the body of an RPC method, it returns the we are executing RPCs from.
+
+
+
+
+ Always always returns null except when called inside the body of an RPC method, it returns the we are executing RPCs from. Works the same as , except when the RPC is called by the local player, it returns .
+
+
+
+
+ Called after all NetworkFixedUpdate methods have been executed.
+ Note: it's called with every resimulation on the client.
+
+
+
+
+ Called before any NetworkFixedUpdate method have been executed.
+ Note: it's called with every resimulation on the client.
+
+
+
+
+ Called after all NetworkUpdate methods have been executed.
+
+
+
+
+ Called before any NetworkUpdate method have been executed.
+
+
+
+
+ Called after all NetworkRender methods have been executed.
+
+
+
+
+ Called before any NetworkRender method have been executed.
+
+
+
+
+ Gets a specific input for the next tick.
+
+
+
+
+
+
+
+ Sets a specific input for the next tick.
+
+
+
+
+
+
+
+ [Client Only] Connects to a remote server.
+ Note: if you are already connected to a server, and you want to connect to a different one, you have to disconnect before calling this. Otherwise this method does nothing.
+ Note: connectionData array length should not be more than 300 if you are using Netick Transport.
+
+ IP address of the server.
+ Port of the server.
+ RawValue sent with the connection request. Could be used to decide whether or not to allow the connection.
+
+
+
+ [Server Only] Disconnects a client from the server.
+
+ The client to be disconnected.
+
+
+
+ [Client Only] Disconnects this client from the server.
+
+
+
+
+ [Server Only] Creates a match. Only functional if the low-level transport has support for matchmaking.
+
+ Name of the match.
+
+
+
+ Requests an update to the match list. Only functional if the low-level transport has support for matchmaking.
+
+
+
+
+ [Server Only] Switches to a different scene. This must be called instead of or its variations. This should only be called for scenes included in the build of the game.
+
+ SceneBuildIndex of the desired scene.
+
+
+
+ [Server Only] Switches to a different scene. This must be called instead of or its variations. This should only be called for scenes included in the build of the game.
+
+ SceneBuildIndex of the desired scene.
+
+
+
+ [Server Only] Loads a scene asynchronously. This should only be called for scenes included in the build of the game.
+
+
+
+
+
+ [Server Only] Unloads a scene asynchronously.
+
+
+
+
+ Manages Netick and its sandboxes, and is used to start and shut down Netick.
+
+
+
+
+ Initializes Netick. This is automatically called when you start Netick.
+ If you don't provide a , Netick will use the default config, which can be modified/found in (Netick -> Settings).
+
+
+
+
+ Shuts down Netick and destroys all sandboxes. The shutdown will occur in the next frame. For immediate shutdown, use:
+
+
+
+
+ Shuts down Netick and destroys all sandboxes immediately.
+
+
+
+
+ Shuts down a specific sandbox.
+
+ The sandbox to shut down.
+
+
+
+ Focus on a specific sandbox.
+
+ The sandbox to focus on.
+
+
+
+ Starts both a client (or clients) and a server.
+
+ Network port.
+ Number of client sandboxes to create.
+
+
+
+
+ Starts multiple peers together.
+
+ Network port.
+ Number of clients to create.
+ Should we start a server too.
+
+
+
+
+ Starts Netick as a client.
+
+ The sandbox representing the client
+
+
+
+ Starts Netick in single player mode.
+
+ The sandbox representing the server
+
+
+
+ Starts Netick as a host.
+
+ Network port.
+ The sandbox representing the server
+
+
+
+ Starts Netick as a server.
+
+ Network port.
+ The sandbox representing the server
+
+
+
+ Config class for Netick.
+
+
diff --git a/Netick/Runtime/Netick.dll b/Netick/Runtime/Netick.dll
index f9c4db3..f7880e8 100644
Binary files a/Netick/Runtime/Netick.dll and b/Netick/Runtime/Netick.dll differ
diff --git a/Netick/Runtime/Netick.xml b/Netick/Runtime/Netick.xml
index 2d28b89..f1f4ccb 100644
--- a/Netick/Runtime/Netick.xml
+++ b/Netick/Runtime/Netick.xml
@@ -4,9 +4,69 @@
Netick
+
+ --------------------------------------------------------------------------------------------------------------
+ --------------------------------------------------------------------------------------------------------------
+ --------------------------------------------------------------------------------------------------------------
+ --------------------------------------------------------------------------------------------------------------
+
-------------------------------
+
+
+ A rolling sequence counter for ordering values. Repeats indefinitely
+ with 1022 possible unique values (0 is treated as invalid internally).
+
+ Consumes 10 bits when encoded for transmission.
+
+
+
+
+ Constructs a NotServerException
+
+
+
+
+ Constructs a NotServerException with a message
+
+ The exception message
+
+
+
+ Constructs a NotServerException with a message and a inner exception
+
+ The exception message
+ The inner exception
+
+
+
+ Constructs a NotClientException
+
+
+
+
+ Constructs a NotClientException with a message
+
+ The exception message
+
+
+
+ Constructs a NotClientException with a message and a inner exception
+
+ The exception message
+ The inner exception
+
+
+
+ Constructs a BadPacketException
+
+
+
+
+ Represents an networked struct identifier for a .
+
+
A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
@@ -17,6 +77,325 @@
A networked collection.
+
+
+ Interpolation time in seconds.
+
+
+
+
+ Time in seconds.
+
+
+
+
+ A struct that is used to obtain interpolation data for a network variable.
+
+
+
+
+ Tries to obtain interpolation data for this frame.
+
+
+
+
+
+ Returns true if there was interpolation data for this frame.
+
+
+
+ Tries to obtain interpolation data for this frame. This is the array version.
+
+
+
+
+
+ Returns true if there was interpolation data for this frame.
+
+
+
+ A class representing an abstract interpolation interface, which is implemented by and
+
+
+
+
+ A class representing the local interpolation of this instance . This should be used whenever you want to use Predicted Timeline on the client.
+
+
+
+
+ Time in seconds.
+
+
+
+
+ A class representing the remote interpolation of this instance . This should be used whenever you want to use Remote Timeline on the client.
+
+
+
+
+ Interpolation time in seconds.
+
+
+
+
+ Time in seconds.
+
+
+
+
+ Returns true if this OnChanged callback is due to a mismatch between the state of this variable before rollback, and the state after rollback and resimulation.
+
+
+
+
+ Gets a snapshot of the previous state of a NetworkDictionary collection.
+
+
+
+
+
+ Gets a snapshot of the previous state of a NetworkHashSet collection.
+
+
+
+
+
+ Gets a snapshot of the previous state of a NetworkLinkedList collection.
+
+
+
+
+
+ Gets a snapshot of the previous state of a NetworkUnorderedList collection.
+
+
+
+
+
+ Gets a snapshot of the previous state of a NetworkQueue collection.
+
+
+
+
+
+ Gets a snapshot of the previous state of a NetworkStack collection.
+
+
+
+
+
+ Gets previous value for the changed network property.
+ Note: this must only be used with non-array network properties. For arrays, use instead.
+
+
+
+
+
+
+ Gets a pointer to the previous value
+
+
+
+
+
+ Gets the index of the changed element of the array.
+
+
+
+
+
+ Gets the value of the changed element of the array. This is an unsafe method, use it carefully and make sure to never go outside range to avoid a crash.
+
+
+
+
+
+ Gets the index of the changed element of the array.
+
+
+
+
+
+
+ A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
+
+
+
+
+ A networked collection.
+
+
+
+
+ Use this attribute on a method you want to call when a specific property value changes. Example: [OnChanged(nameof(PropertyName)]
+
+
+
+
+ Use this attribute on any method you want to make an RPC. Should have the return type of void.
+ * Use the parameter "source" to specify who is allowed to send this RPC.
+ * Use the parameter "target" to specify who is allowed to receive and execute this RPC.
+ * Use the parameter "isReliable" to specify if this Rpc should be reliable or not, meaning it won't be lost (due to packet loss).
+ * Use the parameter "localInvoke" to specify if this Rpc should be executed on the machine it was called from.
+
+
+
+
+ A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
+
+
+
+
+ A networked collection.
+
+
+
+
+ A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
+
+
+
+
+ A networked collection.
+
+
+
+
+ A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
+
+
+
+
+ Index of this node within the collection.
+
+
+
+
+ Index of the next node.
+
+
+
+
+ Index of the previous node.
+
+
+
+
+ A networked linked list collection. This is an ordered list meaning that the elements insertion order is maintained when iterating through the collection.
+
+
+
+
+ Represents a network player, which can be either a local player (representing this player) or a remote connection (representing a connected client)).
+
+
+
+
+ The networked index of this player.
+ Note: it returns -1 on the client for the local player when not connected to a server.
+ Note: the server player always has Id 0.
+
+
+
+
+ Use this to associate an object with this player. This is a local variable that is not synced.
+
+
+
+
+ A list containing all connected clients currently.
+ Note: if you want the clients + the server, use .
+
+
+
+
+ A list containing all connected clients currently, in addition to the server.
+ Note: if you only want the clients, use .
+
+
+
+
+ [Client Only] The of the server you are connected to. Returns null if you are not connected to any server, or if you are the server.
+
+
+
+
+ [Client Only] Returns true if this client is currently connected to a server.
+
+
+
+
+ Time period between simulation ticks.
+
+
+
+
+
+ Returns true if we are currently resimulating a previous input/tick of the past. On the server, it always returns false since only the clients resimulate.
+
+
+
+
+ Incoming data in kilobytes per second (KBps).
+
+
+
+
+ Outgoing data in kilobytes per second (KBps).
+
+
+
+
+ [Client Only] Estimation of incoming packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
+
+
+
+
+ [Client Only] Estimation of outgoing packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
+
+
+
+
+ [Client Only] Interpolation delay in seconds.
+
+
+
+
+ [Client Only] The round-trip time (RTT) of the client in seconds.
+
+
+
+
+ [Client Only] Disconnects this client from the server.
+
+
+
+
+ Attaches a to the simulation.
+
+
+
+
+ Detaches a from the simulation.
+
+
+
+
+ Returns the size of the entirety of the game's networked state snapshot size, in bytes. This includes the sizes of all allocated blocks.
+
+
+
+
+
+ Updates Netick logic.
+
+
+
+
+ Call this to invoke NetworkRender on simulated entities. This might not be needed if you are running a headless build.
+
+
Implements this to inform Netick about the size (in 32 bit words) of your connection meta data.
@@ -102,7 +481,7 @@
Called every fixed-time network update/tick. Any changes/updates to the network state must happen here.
- On the client, if you are the Input Source or if this Entity.PredictionMode is set to None, it will be called several times in one update/tick during resimulations. To check for resimulations, use [].
+ On the client, if you are the Input Source or if this Entity.PredictionMode is set to Global, it will be called several times in one update/tick during resimulations. To check for resimulations, use [].
@@ -112,157 +491,29 @@
- A network scripts which can have networked properties and rpcs.
+ A script which can have networked properties and rpcs.
- Used to initialize the user entity and assign Engine and Entity
+ Used to initialize the user entity and assign Engine and Entity.
-
+
- Returns true if this OnChanged callback is due to a mismatch between the state of this variable before rollback, and the state after rollback and resimulation.
+ A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
-
+
- Gets a snapshot of the previous state of a NetworkDictionary collection.
-
-
-
-
-
- Gets a snapshot of the previous state of a NetworkHashSet collection.
-
-
-
-
-
- Gets a snapshot of the previous state of a NetworkLinkedList collection.
-
-
-
-
-
- Gets a snapshot of the previous state of a NetworkQueue collection.
-
-
-
-
-
- Gets a snapshot of the previous state of a NetworkStack collection.
-
-
-
-
-
- Gets previous value for the changed network property.
- Note: this must only be used with non-array network properties. For arrays, use instead.
-
-
-
-
-
-
- Gets a pointer to the previous value
-
-
-
-
-
- Gets the index of the changed element of the array.
-
-
-
-
-
- Gets the value of the changed element of the array. This is an unsafe method, use it carefully and make sure to never go outside range to avoid a crash.
-
-
-
-
-
- Gets the index of the changed element of the array.
-
-
-
-
-
-
- A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
+ A networked list collection. This is an unordered list meaning that the order of the elements during iteration is undefined.
-
+
- A networked collection.
-
-
-
-
- A struct that is used to obtain interpolation data for a network property.
-
-
-
-
- Tries to obtain interpolation data for this frame.
-
-
-
-
-
- Returns true if there was interpolation data for this frame.
-
-
-
- Tries to obtain interpolation data for this frame. This is the array version.
-
-
-
-
-
- Returns true if there was interpolation data for this frame.
-
-
-
- A class representing an abstract interpolation interface, which is implemented by and
-
-
-
-
- A class representing the local interpolation of this instance . This should be used whenever you want to use Predicted Timeline on the client.
-
-
-
-
- Time in seconds.
-
-
-
-
- A class representing the remote interpolation of this instance . This should be used whenever you want to use Remote Timeline on the client.
-
-
-
-
- Interpolation time in seconds.
-
-
-
-
- Time in seconds.
-
-
-
-
- Interpolation time in seconds.
-
-
-
-
- Time in seconds.
+ Always use NetworkBool instead of bool, for networked properties and RPC parameters.
@@ -285,229 +536,29 @@
Internal method. Never call this.
-
-
- A rolling sequence counter for ordering values. Repeats indefinitely
- with 1022 possible unique values (0 is treated as invalid internally).
-
- Consumes 10 bits when encoded for transmission.
-
-
-
-
- A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
-
-
-
-
- A networked collection.
-
-
-
-
- A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
-
-
-
-
- A networked collection.
-
-
-
-
- Constructs a NotServerException
-
-
-
-
- Constructs a NotServerException with a message
-
- The exception message
-
-
-
- Constructs a NotServerException with a message and a inner exception
-
- The exception message
- The inner exception
-
-
-
- Constructs a NotClientException
-
-
-
-
- Constructs a NotClientException with a message
-
- The exception message
-
-
-
- Constructs a NotClientException with a message and a inner exception
-
- The exception message
- The inner exception
-
-
-
- Constructs a BadPacketException
-
-
-
-
- A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
-
-
-
-
- A networked linked list collection. This is an ordered list meaning that the elements insertion order is maintained when iterating through the collection.
-
-
----------------------------------------------------
-
+
- Represents a network player, which can be either a local player (representing this sandbox) or a remote connection (representing a connected client)).
+ The longest inward packet loss burst (more than 2 packets lost in a row) in the last 10 seconds.
-
+
- The networked index of this player.
- Note: it returns -1 on the client for the local player when not connected to a server.
- Note: the server player always has Id 0.
+ Estimation of incoming packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
-
+
- Use this to associate an object with this player.
+ Estimation of outgoing packets that are being lost. Value ranges between 0.0 and 1.0, with 1.0 meaning all packets are being lost.
-
-
- A list containing all connected clients currently.
- Note: if you want the clients + the server, use .
-
-
-
-
- A list containing all connected clients currently, in addition to the server.
- Note: if you only want the clients, use .
-
-
-
-
- [Client Only] The of the server you are connected to. Returns null if you are not connected to any server, or if you are the server.
-
-
-
-
- [Client Only] Returns true if this client is currently connected to a server.
-
-
-
-
- Time period between simulation ticks.
-
-
-
-
-
- Returns true if we are currently resimulating a previous input/tick of the past. On the server, it always returns false since only the clients resimulate.
-
-
-
-
- Incoming data in kilobytes per second (KBps).
-
-
-
-
- Outgoing data in kilobytes per second (KBps).
-
-
-
-
- [Client Only] Interpolation delay in seconds.
-
-
-
-
- [Client Only] The round-trip time (RTT) of the client in seconds.
-
-
-
-
- [Client Only] Disconnects this client from the server.
-
-
-
-
- Update Netick's logic.
-
-
-
-
- Call this to invoke NetworkRender on simulated entities. This might not be needed if you are running a headless build.
-
-
-
-
- Attachs a to the simulation.
-
-
-
-
-
- Deattachs a from the simulation.
-
-
-
Sends data to this connection.
Note: the low-level transport must implement for this method to have an effect.
-
-
-
-
-
- --------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------
-
-
- -------------------------------- -------------------------------- -------------------------------- --------------------------------
-
-
- -------------------------------- -------------------------------- -------------------------------- --------------------------------
-
-
-
- A snapshot of the state of a collection. Note this must not be used outside the scope of an OnChanged call or a NetworkRender call.
-
-
-
-
- A networked list collection. This is an unordered list meaning that the order of the elements during iteration is undefined.
-
-
-
-
- Use this attribute on a method you want to call when a specific property value changes. Example: [OnChanged(nameof(PropertyName)]
-
-
-
-
- Use this attribute on any method you want to make an RPC. Should have the return type of void, and not be static.
- * Use the parameter "source" to specify who is allowed to send this RPC.
- * Use the parameter "target" to specify who is allowed to receive and execute this RPC.
- * Use the parameter "isReliable" to specify if this Rpc should be reliable or not, meaning it won't be lost (due to packet loss).
- * Use the parameter "localInvoke" to specify if this Rpc should be executed on the machine it was called from.
-
diff --git a/Samples~/Bomberman/Scenes/Bomberman.unity b/Samples~/Bomberman/Scenes/Bomberman.unity
index b003632..cbade27 100644
--- a/Samples~/Bomberman/Scenes/Bomberman.unity
+++ b/Samples~/Bomberman/Scenes/Bomberman.unity
@@ -38,7 +38,6 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
- m_IndirectSpecularColor: {r: 0.45137393, g: 0.50092196, b: 0.57263935, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -123,6 +122,37 @@ NavMeshSettings:
debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
+--- !u!1 &293298009
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 293298010}
+ m_Layer: 0
+ m_Name: GameObject
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!4 &293298010
+Transform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 293298009}
+ serializedVersion: 2
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
+ m_LocalPosition: {x: -133.02965, y: 72.981926, z: 47.2627}
+ m_LocalScale: {x: 1, y: 1, z: 1}
+ m_ConstrainProportionsScale: 0
+ m_Children: []
+ m_Father: {fileID: 0}
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &1070948396
GameObject:
m_ObjectHideFlags: 0
@@ -7204,3 +7234,4 @@ SceneRoots:
- {fileID: 1070948398}
- {fileID: 1809360484}
- {fileID: 3762179930698311635}
+ - {fileID: 293298010}
diff --git a/Samples~/Bomberman/Scripts/Block.cs b/Samples~/Bomberman/Scripts/Block.cs
index 43bb624..2ff2c0f 100644
--- a/Samples~/Bomberman/Scripts/Block.cs
+++ b/Samples~/Bomberman/Scripts/Block.cs
@@ -4,22 +4,22 @@ using Netick.Unity;
namespace Netick.Samples.Bomberman
{
- public class Block : NetworkBehaviour
+ public class Block : NetworkBehaviour
+ {
+ // Networked Properties
+ [Networked]
+ public NetworkBool Visible { get; set; } = true;
+
+ [OnChanged(nameof(Visible))]
+ private void OnVisibleChanged(OnChangedData onChangedData)
{
- // Networked Properties
- [Networked]
- public NetworkBool Visible { get; set; } = true;
+ // for visual components, don't use "enabled" property when you want to disable/enable it, instead use SetEnabled().
+ // -- GetComponent().enabled = Visible; #### Not like this.
- [OnChanged(nameof(Visible))]
- private void OnVisibleChanged(OnChangedData onChangedData)
- {
- // for visual components, don't use "enabled" property when you want to disable/enable it, instead use SetEnabled().
- // -- GetComponent().enabled = Visible; #### Not like this.
+ GetComponent().SetEnabled(Sandbox, Visible); // #### Like this.
- GetComponent().SetEnabled(Sandbox, Visible); // #### Like this.
-
- GetComponent().enabled = Visible;
- }
+ GetComponent().enabled = Visible;
}
+ }
}
diff --git a/Samples~/Bomberman/Scripts/Bomb.cs b/Samples~/Bomberman/Scripts/Bomb.cs
index e833f32..7ce00cb 100644
--- a/Samples~/Bomberman/Scripts/Bomb.cs
+++ b/Samples~/Bomberman/Scripts/Bomb.cs
@@ -5,68 +5,68 @@ using Netick.Unity;
namespace Netick.Samples.Bomberman
{
- public class Bomb : NetworkBehaviour
- {
- public GameObject ExplosionPrefab;
+ public class Bomb : NetworkBehaviour
+ {
+ public GameObject ExplosionPrefab;
- public BombermanController Bomber;
- public float ExplosionDelay = 3.0f;
+ public BombermanController Bomber;
+ public float ExplosionDelay = 3.0f;
- private readonly Vector3[] _directionsAroundBomb = new Vector3[4] { Vector3.right, Vector3.left, Vector3.up, Vector3.down };
- private static RaycastHit[] _hits = new RaycastHit[20];
+ private readonly Vector3[] _directionsAroundBomb = new Vector3[4] { Vector3.right, Vector3.left, Vector3.up, Vector3.down };
+ private static RaycastHit[] _hits = new RaycastHit[20];
- public override void NetworkStart()
- {
- Bomber?.SpawnedBombs.Add(this);
- GetComponent().enabled = true;
+ public override void NetworkStart()
+ {
+ Bomber?.SpawnedBombs.Add(this);
+ GetComponent().enabled = true;
}
- public override void NetworkDestroy()
- {
- Bomber?.SpawnedBombs.Remove(this);
+ public override void NetworkDestroy()
+ {
+ Bomber?.SpawnedBombs.Remove(this);
- // spawn explosion.
- if (ExplosionPrefab != null)
- Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
- }
+ // spawn explosion.
+ if (ExplosionPrefab != null)
+ Instantiate(ExplosionPrefab, transform.position, Quaternion.identity);
+ }
- public override void NetworkFixedUpdate()
- {
- if (Sandbox.TickToTime(Sandbox.Tick - Object.SpawnTick) >= ExplosionDelay)
- Explode();
- }
+ public override void NetworkFixedUpdate()
+ {
+ if (Sandbox.TickToTime(Sandbox.Tick - Object.SpawnTick) >= ExplosionDelay)
+ Explode();
+ }
- private void Explode()
- {
- // hide bomb after delay.
- GetComponent().enabled = false;
+ private void Explode()
+ {
+ // hide bomb after delay.
+ GetComponent().enabled = false;
- // dealing damage is done on the server only.
- if (IsServer)
- {
- DamageTargetsAroundBomb(transform.position);
- Sandbox.Destroy(Object);
- }
- }
-
- private void DamageTargetsAroundBomb(Vector3 pos)
- {
- // find all objects around the bomb position.
- foreach (var dir in _directionsAroundBomb)
- {
- var hitsCount = Sandbox.Physics.Raycast(pos, dir, _hits, 1f);
+ // dealing damage is done on the server only.
+ if (IsServer)
+ {
+ DamageTargetsAroundBomb(transform.position);
+ Sandbox.Destroy(Object);
+ }
+ }
- for (int i = 0; i < hitsCount; i++)
- {
- var target =_hits[i].collider.gameObject;
- var block = target.GetComponent();
- var bomber = target.GetComponent();
+ private void DamageTargetsAroundBomb(Vector3 pos)
+ {
+ // find all objects around the bomb position.
+ foreach (var dir in _directionsAroundBomb)
+ {
+ var hitsCount = Sandbox.Physics.Raycast(pos, dir, _hits, 1f);
- if (block != null)
- block.Visible = false;
- bomber?.Die();
- }
- }
- }
- }
+ for (int i = 0; i < hitsCount; i++)
+ {
+ var target = _hits[i].collider.gameObject;
+ var block = target.GetComponent();
+ var bomber = target.GetComponent();
+
+ if (block != null)
+ block.Visible = false;
+ bomber?.Die();
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Samples~/Bomberman/Scripts/Bomb.cs.meta b/Samples~/Bomberman/Scripts/Bomb.cs.meta
index c640e44..21f6878 100644
--- a/Samples~/Bomberman/Scripts/Bomb.cs.meta
+++ b/Samples~/Bomberman/Scripts/Bomb.cs.meta
@@ -4,7 +4,7 @@ MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
- executionOrder: 10
+ executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
diff --git a/Samples~/Bomberman/Scripts/BombermanController.cs b/Samples~/Bomberman/Scripts/BombermanController.cs
index 79e6f76..22d2c49 100644
--- a/Samples~/Bomberman/Scripts/BombermanController.cs
+++ b/Samples~/Bomberman/Scripts/BombermanController.cs
@@ -7,129 +7,132 @@ using Netick.Unity;
namespace Netick.Samples.Bomberman
{
- public class BombermanController : NetworkBehaviour
+ public class BombermanController : NetworkBehaviour
+ {
+ public List SpawnedBombs = new(4);
+ [HideInInspector]
+ public Vector3 SpawnPos;
+ [SerializeField]
+ private float _speed = 6.0f;
+ [SerializeField]
+ private float _speedBoostMultiplayer = 2f;
+
+ private GameObject _bombPrefab;
+ private CharacterController _CC;
+ private BombermanInput _lastInput;
+
+ // Networked Properties
+ [Networked]
+ public int Score { get; set; } = 0;
+ [Networked]
+ public NetworkBool Alive { get; set; } = true;
+
+ [Networked(relevancy: Relevancy.InputSource)]
+ public int MaxBombs { get; set; } = 1;
+ [Networked(relevancy: Relevancy.InputSource)]
+ public float SpeedPowerUpTimer { get; set; } = 0;
+ [Networked(relevancy: Relevancy.InputSource)]
+ public float BombPowerUpTimer { get; set; } = 0;
+
+ public override void NetworkStart()
{
- public List SpawnedBombs = new(4);
- [HideInInspector]
- public Vector3 SpawnPos;
- [SerializeField]
- private float _speed = 6.0f;
- [SerializeField]
- private float _speedBoostMultiplayer = 2f;
-
- private GameObject _bombPrefab;
- private CharacterController _CC;
-
- // Networked Properties
- [Networked]
- public int Score { get; set; } = 0;
- [Networked]
- public NetworkBool Alive { get; set; } = true;
-
- [Networked(relevancy: Relevancy.InputSource)]
- public int MaxBombs { get; set; } = 1;
- [Networked(relevancy: Relevancy.InputSource)]
- public float SpeedPowerUpTimer { get; set; } = 0;
- [Networked(relevancy: Relevancy.InputSource)]
- public float BombPowerUpTimer { get; set; } = 0;
-
- public override void NetworkStart()
- {
- _bombPrefab = Sandbox.GetPrefab("Bomb");
- // we store the spawn pos so that we use it later during respawn.
- SpawnPos = transform.position;
- _CC = GetComponent();
- }
-
- public override void OnInputSourceLeft()
- {
- Sandbox.GetComponent().KillPlayer(this);
- // destroy the player object when its input source (controller player) leaves the game.
- Sandbox.Destroy(Object);
- }
-
- public override void NetworkFixedUpdate()
- {
- if (!Alive)
- return;
-
- if (FetchInput(out BombermanInput input))
- {
- // clamp movement inputs.
- input.Movement = new Vector3(Mathf.Clamp(input.Movement.x, -1f, 1f), Mathf.Clamp(input.Movement.y, -1f, 1f));
-
- if (BombPowerUpTimer > 0)
- BombPowerUpTimer -= Sandbox.FixedDeltaTime;
- else
- MaxBombs = 1;
-
- if (SpeedPowerUpTimer > 0)
- SpeedPowerUpTimer -= Sandbox.FixedDeltaTime;
-
- var hasSpeedBoost = SpeedPowerUpTimer > 0;
- var speed = hasSpeedBoost ? _speed * _speedBoostMultiplayer : _speed;
-
- _CC.Move(input.Movement * speed * Sandbox.FixedDeltaTime);
-
- // we make sure the z coord of the pos of the player is always zero.
- transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
-
- if (IsServer && input.PlantBomb && SpawnedBombs.Count < MaxBombs)
- {
- // round the bomb pos so that it snaps to the nearest square.
- var bomb = Sandbox.NetworkInstantiate(_bombPrefab, Round(transform.position), Quaternion.identity).GetComponent();
- bomb.Bomber = this;
- }
- }
- }
-
- public void ReceivePowerUp(PowerUpType type, float boostTime)
- {
- if (type == PowerUpType.IncreaseBombs)
- {
- SpeedPowerUpTimer += boostTime;
- }
- else if (type == PowerUpType.Speed)
- {
- BombPowerUpTimer += boostTime;
- MaxBombs += 1;
- }
- }
-
- public void Die()
- {
- Alive = false;
- Sandbox.GetComponent().KillPlayer(this);
- }
-
- public void Respawn()
- {
- Sandbox.GetComponent().RespawnPlayer(this);
-
- Alive = true;
- SpeedPowerUpTimer = 0;
- BombPowerUpTimer = 0;
- MaxBombs = 1;
-
- transform.position = SpawnPos;
- }
-
- [OnChanged(nameof(Alive))]
- private void OnAliveChanged(OnChangedData onChangedData)
- {
- // based on state of Alive:
-
- // * hide/show player object.
- GetComponentInChildren().SetEnabled(Sandbox,Alive);
-
- // * enable/disable the CharacterController.
- _CC.enabled = Alive;
- }
-
- public Vector3 Round(Vector3 vec)
- {
- return new Vector3(Mathf.Round(vec.x), Mathf.Round(vec.y), Mathf.Round(vec.z));
- }
-
+ _bombPrefab = Sandbox.GetPrefab("Bomb");
+ // we store the spawn pos so that we use it later during respawn.
+ SpawnPos = transform.position;
+ _CC = GetComponent();
}
+
+ public override void OnInputSourceLeft()
+ {
+ Sandbox.GetComponent().KillPlayer(this);
+ // destroy the player object when its input source (controller player) leaves the game.
+ Sandbox.Destroy(Object);
+ }
+
+ public override void NetworkFixedUpdate()
+ {
+ if (!Alive)
+ return;
+
+ FetchInput(out _lastInput);
+
+ if (IsInputSource || IsServer)
+ {
+ // clamp movement inputs.
+ _lastInput.Movement = new Vector3(Mathf.Clamp(_lastInput.Movement.x, -1f, 1f), Mathf.Clamp(_lastInput.Movement.y, -1f, 1f));
+
+ if (BombPowerUpTimer > 0)
+ BombPowerUpTimer -= Sandbox.FixedDeltaTime;
+ else
+ MaxBombs = 1;
+
+ if (SpeedPowerUpTimer > 0)
+ SpeedPowerUpTimer -= Sandbox.FixedDeltaTime;
+
+ var hasSpeedBoost = SpeedPowerUpTimer > 0;
+ var speed = hasSpeedBoost ? _speed * _speedBoostMultiplayer : _speed;
+
+ _CC.Move(_lastInput.Movement * speed * Sandbox.FixedDeltaTime);
+
+ // we make sure the z coord of the pos of the player is always zero.
+ transform.position = new Vector3(transform.position.x, transform.position.y, 0f);
+
+ if (IsServer && _lastInput.PlantBomb && SpawnedBombs.Count < MaxBombs)
+ {
+ // round the bomb pos so that it snaps to the nearest square.
+ var bomb = Sandbox.NetworkInstantiate(_bombPrefab, Round(transform.position), Quaternion.identity).GetComponent();
+ bomb.Bomber = this;
+ }
+ }
+ }
+
+ public void ReceivePowerUp(PowerUpType type, float boostTime)
+ {
+ if (type == PowerUpType.IncreaseBombs)
+ {
+ SpeedPowerUpTimer += boostTime;
+ }
+ else if (type == PowerUpType.Speed)
+ {
+ BombPowerUpTimer += boostTime;
+ MaxBombs += 1;
+ }
+ }
+
+ public void Die()
+ {
+ Alive = false;
+ Sandbox.GetComponent().KillPlayer(this);
+ }
+
+ public void Respawn()
+ {
+ Sandbox.GetComponent().RespawnPlayer(this);
+
+ Alive = true;
+ SpeedPowerUpTimer = 0;
+ BombPowerUpTimer = 0;
+ MaxBombs = 1;
+
+ transform.position = SpawnPos;
+ }
+
+ [OnChanged(nameof(Alive))]
+ private void OnAliveChanged(OnChangedData onChangedData)
+ {
+ // based on state of Alive:
+
+ // * hide/show player object.
+ GetComponentInChildren().SetEnabled(Sandbox, Alive);
+
+ // * enable/disable the CharacterController.
+ _CC.enabled = Alive;
+ }
+
+ public Vector3 Round(Vector3 vec)
+ {
+ return new Vector3(Mathf.Round(vec.x), Mathf.Round(vec.y), Mathf.Round(vec.z));
+ }
+
+ }
}
\ No newline at end of file
diff --git a/Samples~/Bomberman/Scripts/BombermanEventsHandler.cs b/Samples~/Bomberman/Scripts/BombermanEventsHandler.cs
index 1454d41..1551839 100644
--- a/Samples~/Bomberman/Scripts/BombermanEventsHandler.cs
+++ b/Samples~/Bomberman/Scripts/BombermanEventsHandler.cs
@@ -5,157 +5,160 @@ using Netick.Unity;
namespace Netick.Samples.Bomberman
{
- public class BombermanEventsHandler : NetworkBehaviour
+ public class BombermanEventsHandler : NetworkBehaviour
+ {
+ public List AlivePlayers = new(4);
+ private GameObject _playerPrefab;
+ private Vector3[] _spawnPositions = new Vector3[4] { new Vector3(11, 9, 0), new Vector3(11, 1, 0), new Vector3(1, 9, 0), new Vector3(1, 1, 0) };
+ private Queue _freePositions = new(4);
+
+ public override void NetworkAwake()
{
- public List Players = new(4);
- public List AlivePlayers = new(4);
-
- private GameObject _playerPrefab;
- private Vector3[] _spawnPositions = new Vector3[4] { new Vector3(11, 9, 0), new Vector3(11, 1, 0), new Vector3(1, 9, 0), new Vector3(1, 1, 0) };
- private Queue _freePositions = new(4);
-
- public override void NetworkStart()
- {
- Sandbox.Events.OnInputRead += OnInput;
- Sandbox.Events.OnConnectRequest += OnConnectRequest;
- Sandbox.Events.OnPlayerConnected += OnPlayerConnected;
- Sandbox.Events.OnPlayerDisconnected += OnPlayerDisconnected;
+ Sandbox.Events.OnInputRead += OnInput;
+ Sandbox.Events.OnConnectRequest += OnConnectRequest;
+ Sandbox.Events.OnPlayerJoined += OnPlayerJoined;
+ Sandbox.Events.OnPlayerLeft += OnPlayerLeft;
+ _playerPrefab = Sandbox.GetPrefab("Bomberman Player");
+ Sandbox.InitializePool(Sandbox.GetPrefab("Bomb"), 5);
+ Sandbox.InitializePool(_playerPrefab, 4);
- _playerPrefab = Sandbox.GetPrefab("Bomberman Player");
- Sandbox.InitializePool(Sandbox.GetPrefab("Bomb"), 5);
- Sandbox.InitializePool(_playerPrefab,4);
-
- for (int i = 0; i < 4; i++)
- _freePositions.Enqueue(_spawnPositions[i]);
-
- if (IsServer)
- RestartGame();
- }
-
- public void OnConnectRequest(NetworkSandbox sandbox, NetworkConnectionRequest request)
- {
- if (Sandbox.ConnectedPlayers.Count >= 4)
- request.Refuse();
- }
-
- // This is called on the server when a playerObj has connected.
- public void OnPlayerConnected(NetworkSandbox sandbox, NetworkPlayer player)
- {
- var playerObj = sandbox.NetworkInstantiate(_playerPrefab, _spawnPositions[Sandbox.ConnectedPlayers.Count], Quaternion.identity, player).GetComponent();
- player.PlayerObject = playerObj.gameObject;
- AlivePlayers. Add(playerObj);
- Players. Add(playerObj);
- }
-
- // This is called on the server when a client has disconnected.
- public void OnPlayerDisconnected(NetworkSandbox sandbox, Netick.NetworkPlayer player, TransportDisconnectReason reason)
- {
- _freePositions.Enqueue(((GameObject)player.PlayerObject).GetComponent().SpawnPos);
- Players. Remove (((GameObject)player.PlayerObject).GetComponent());
- }
-
- // This is called to read inputs.
- public void OnInput(NetworkSandbox sandbox)
- {
- var input = sandbox.GetInput();
- input.Movement = GetMovementDir();
- input.PlantBomb |= Input.GetKeyDown(KeyCode.Space);
- sandbox.SetInput(input);
- }
-
- public void RestartGame()
- {
- // destroy level.
- foreach (var block in Sandbox.FindObjectsOfType())
- Sandbox.Destroy(block.Object);
- foreach (var bomb in Sandbox.FindObjectsOfType())
- Sandbox.Destroy(bomb.Object);
-
- // create new level.
- var blockPrefab = Sandbox.GetPrefab("DestroyableBlock");
- var powerUpPrefab = Sandbox.GetPrefab("Power Up");
- var numberOfBoosters = Random.Range(2, 4+1);
- var takenPositions = new List();
- var maxX = 11;
- var maxY = 9;
-
- for (int x = 1; x <= maxX; x++)
- {
- for (int y = 1; y <= maxY; y++)
- {
- var spawn = Random.value > 0.5f;
- var pos = new Vector3(x, y);
-
- if (spawn && IsValidPos(pos))
- {
- Sandbox.NetworkInstantiate(blockPrefab, pos, Quaternion.identity);
- takenPositions.Add(pos);
- }
- }
- }
-
- while (numberOfBoosters > 0)
- {
- var randomPos = new Vector3(Random.Range(1, 11+1), Random.Range(1, 9+1), 0);
- var type = (Random.value > 0.5f) ? PowerUpType.Speed : PowerUpType.IncreaseBombs;
-
- if (!takenPositions.Contains(randomPos) && IsValidPos(randomPos))
- {
- var booster = Sandbox.NetworkInstantiate(powerUpPrefab, randomPos, Quaternion.identity).GetComponent();
- booster.Type = type;
- numberOfBoosters--;
- }
- }
-
- // reset players.
- foreach (var player in Players)
- player.Respawn();
- }
-
- private bool IsValidPos(Vector3 pos)
- {
- // if the pos is the position of a static block, we ignore it.
- if ((pos.x >= 2 && pos.x <= 10) && (pos.y >= 2 && pos.y <= 8))
- if (pos.x % 2 == 0 && pos.y % 2 == 0)
- return false;
-
- // if the pos is near the position of the spawn locations of the players, we ignore it.
- foreach (var loc in _spawnPositions)
- {
- if (pos == loc) return false;
- if (pos == loc + Vector3.up || pos == loc + Vector3.down) return false;
- if (pos == loc + Vector3.left || pos == loc + Vector3.right) return false;
- }
-
- return true;
- }
-
- public void KillPlayer(BombermanController bomber)
- {
- AlivePlayers.Remove(bomber);
-
- if (AlivePlayers.Count == 1)
- {
- AlivePlayers[0].Score++;
- RestartGame();
- }
-
- else if (AlivePlayers.Count < 1)
- RestartGame();
- }
-
- public void RespawnPlayer(BombermanController bomber)
- {
- if (!AlivePlayers.Contains(bomber))
- AlivePlayers.Add(bomber);
- }
- private Vector2 GetMovementDir()
- {
- if (Input.GetKey(KeyCode.W)) return Vector2.up;
- else if (Input.GetKey(KeyCode.D)) return Vector2.right;
- else if (Input.GetKey(KeyCode.S)) return Vector2.down;
- else if (Input.GetKey(KeyCode.A)) return Vector2.left;
- else return Vector2.zero;
- }
+ for (int i = 0; i < 4; i++)
+ _freePositions.Enqueue(_spawnPositions[i]);
}
+
+ public override void NetworkStart()
+ {
+ if (IsServer)
+ RestartGame();
+ }
+
+ public void OnConnectRequest(NetworkSandbox sandbox, NetworkConnectionRequest request)
+ {
+ if (Sandbox.Players.Count >= 4)
+ request.Refuse();
+ }
+
+ // This is called when a player has has joined the game.
+ public void OnPlayerJoined(NetworkSandbox sandbox, NetworkPlayerId player)
+ {
+ if (IsClient)
+ return;
+ var playerObj = sandbox.NetworkInstantiate(_playerPrefab, _spawnPositions[Sandbox.Players.Count], Quaternion.identity, player).GetComponent();
+ sandbox.SetPlayerObject(player, playerObj.Object);
+ AlivePlayers.Add(playerObj);
+ }
+
+ // This is called when a player has has left the game.
+ public void OnPlayerLeft(NetworkSandbox sandbox, NetworkPlayerId player)
+ {
+ if (IsClient)
+ return;
+ var playerObj = sandbox.GetPlayerObject(player);
+ _freePositions.Enqueue(playerObj.SpawnPos);
+ }
+
+ // This is called to read inputs.
+ public void OnInput(NetworkSandbox sandbox)
+ {
+ var input = sandbox.GetInput();
+ input.Movement = GetMovementDir();
+ input.PlantBomb |= Input.GetKeyDown(KeyCode.Space);
+ sandbox.SetInput(input);
+ }
+
+ public void RestartGame()
+ {
+ // destroy level.
+ foreach (var block in Sandbox.FindObjectsOfType())
+ Sandbox.Destroy(block.Object);
+ foreach (var bomb in Sandbox.FindObjectsOfType())
+ Sandbox.Destroy(bomb.Object);
+
+ // create new level.
+ var blockPrefab = Sandbox.GetPrefab("DestroyableBlock");
+ var powerUpPrefab = Sandbox.GetPrefab("Power Up");
+ var numberOfBoosters = Random.Range(2, 4 + 1);
+ var takenPositions = new List();
+ var maxX = 11;
+ var maxY = 9;
+
+ for (int x = 1; x <= maxX; x++)
+ {
+ for (int y = 1; y <= maxY; y++)
+ {
+ var spawn = Random.value > 0.5f;
+ var pos = new Vector3(x, y);
+
+ if (spawn && IsValidPos(pos))
+ {
+ Sandbox.NetworkInstantiate(blockPrefab, pos, Quaternion.identity);
+ takenPositions.Add(pos);
+ }
+ }
+ }
+
+ while (numberOfBoosters > 0)
+ {
+ var randomPos = new Vector3(Random.Range(1, 11 + 1), Random.Range(1, 9 + 1), 0);
+ var type = (Random.value > 0.5f) ? PowerUpType.Speed : PowerUpType.IncreaseBombs;
+
+ if (!takenPositions.Contains(randomPos) && IsValidPos(randomPos))
+ {
+ var booster = Sandbox.NetworkInstantiate(powerUpPrefab, randomPos, Quaternion.identity).GetComponent();
+ booster.Type = type;
+ numberOfBoosters--;
+ }
+ }
+
+ // reset players.
+ foreach (var player in Sandbox.Players)
+ Sandbox.GetPlayerObject(player).Respawn();
+ }
+
+ private bool IsValidPos(Vector3 pos)
+ {
+ // if the pos is the position of a static block, we ignore it.
+ if ((pos.x >= 2 && pos.x <= 10) && (pos.y >= 2 && pos.y <= 8))
+ if (pos.x % 2 == 0 && pos.y % 2 == 0)
+ return false;
+
+ // if the pos is near the position of the spawn locations of the players, we ignore it.
+ foreach (var loc in _spawnPositions)
+ {
+ if (pos == loc) return false;
+ if (pos == loc + Vector3.up || pos == loc + Vector3.down) return false;
+ if (pos == loc + Vector3.left || pos == loc + Vector3.right) return false;
+ }
+
+ return true;
+ }
+
+ public void KillPlayer(BombermanController bomber)
+ {
+ AlivePlayers.Remove(bomber);
+
+ if (AlivePlayers.Count == 1)
+ {
+ AlivePlayers[0].Score++;
+ RestartGame();
+ }
+
+ else if (AlivePlayers.Count < 1)
+ RestartGame();
+ }
+
+ public void RespawnPlayer(BombermanController bomber)
+ {
+ if (!AlivePlayers.Contains(bomber))
+ AlivePlayers.Add(bomber);
+ }
+ private Vector2 GetMovementDir()
+ {
+ if (Input.GetKey(KeyCode.W)) return Vector2.up;
+ else if (Input.GetKey(KeyCode.D)) return Vector2.right;
+ else if (Input.GetKey(KeyCode.S)) return Vector2.down;
+ else if (Input.GetKey(KeyCode.A)) return Vector2.left;
+ else return Vector2.zero;
+ }
+ }
}
\ No newline at end of file
diff --git a/Samples~/Bomberman/Scripts/BombermanInput.cs b/Samples~/Bomberman/Scripts/BombermanInput.cs
index ee6f195..ec69488 100644
--- a/Samples~/Bomberman/Scripts/BombermanInput.cs
+++ b/Samples~/Bomberman/Scripts/BombermanInput.cs
@@ -4,11 +4,11 @@ using Netick.Unity;
namespace Netick.Samples.Bomberman
{
+ [Networked]
+ public struct BombermanInput : INetworkInput
+ {
[Networked]
- public struct BombermanInput : INetworkInput
- {
- [Networked]
- public Vector2 Movement { get; set; }
- public NetworkBool PlantBomb;
- }
+ public Vector2 Movement { get; set; }
+ public NetworkBool PlantBomb;
+ }
}
\ No newline at end of file
diff --git a/Samples~/Bomberman/Scripts/PowerUp.cs b/Samples~/Bomberman/Scripts/PowerUp.cs
index 6848b83..149f0ec 100644
--- a/Samples~/Bomberman/Scripts/PowerUp.cs
+++ b/Samples~/Bomberman/Scripts/PowerUp.cs
@@ -4,44 +4,44 @@ using Netick.Unity;
namespace Netick.Samples.Bomberman
{
- public enum PowerUpType
+ public enum PowerUpType
+ {
+ Speed,
+ IncreaseBombs
+ }
+
+ public class PowerUp : NetworkBehaviour
+ {
+ public float PowerUpTime = 35;
+ private Material _mat;
+
+ // Networked Properties
+ [Networked]
+ public PowerUpType Type { get; set; }
+
+ private void Awake()
{
- Speed,
- IncreaseBombs
+ _mat = GetComponentInChildren().material;
}
- public class PowerUp : NetworkBehaviour
+ public override void NetworkRender()
{
- public float PowerUpTime = 35;
- private Material _mat;
-
- // Networked Properties
- [Networked]
- public PowerUpType Type { get; set; }
-
- private void Awake()
- {
- _mat = GetComponentInChildren().material;
- }
-
- public override void NetworkRender()
- {
- var color = Type == PowerUpType.IncreaseBombs ? Color.green : Color.blue;
- _mat.color = Color.Lerp(color, color * 0.5f, Mathf.InverseLerp(-1f, 1f, Mathf.Sin(15f * Time.time)));
- }
-
- public void OnTriggerEnter(Collider other)
- {
- if (Sandbox == null)
- return;
-
- var player = other.gameObject.GetComponent();
-
- if (Sandbox.IsServer && player != null)
- {
- player.ReceivePowerUp(Type, PowerUpTime);
- Sandbox.Destroy(Object);
- }
- }
+ var color = Type == PowerUpType.IncreaseBombs ? Color.green : Color.blue;
+ _mat.color = Color.Lerp(color, color * 0.5f, Mathf.InverseLerp(-1f, 1f, Mathf.Sin(15f * Time.time)));
}
+
+ public void OnTriggerEnter(Collider other)
+ {
+ if (Sandbox == null)
+ return;
+
+ var player = other.gameObject.GetComponent();
+
+ if (Sandbox.IsServer && player != null)
+ {
+ player.ReceivePowerUp(Type, PowerUpTime);
+ Sandbox.Destroy(Object);
+ }
+ }
+ }
}
diff --git a/Samples~/First Person Shooter/Scenes/FPS Scene.unity b/Samples~/First Person Shooter/Scenes/FPS Scene.unity
index f25ad5d..2ebffc9 100644
--- a/Samples~/First Person Shooter/Scenes/FPS Scene.unity
+++ b/Samples~/First Person Shooter/Scenes/FPS Scene.unity
@@ -38,7 +38,6 @@ RenderSettings:
m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
- m_IndirectSpecularColor: {r: 0.43668216, g: 0.48427725, b: 0.56452835, a: 1}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
@@ -503,12 +502,15 @@ MonoBehaviour:
m_GameObject: {fileID: 1293352707}
m_Enabled: 1
m_EditorHideFlags: 0
- m_Script: {fileID: 11500000, guid: fb5a4e3a1e885b04e8f36bf0b0597274, type: 3}
+ m_Script: {fileID: 11500000, guid: 13d95c28de1bac54f8b26fc8dd960077, type: 3}
m_Name:
m_EditorClassIdentifier:
- SpawnPos: {fileID: 10129275}
PlayerPrefab: {fileID: 7011933354638177272, guid: d66d5a97430d3364890108321123b309,
type: 3}
+ SpawnPosition: {fileID: 10129275}
+ HorizontalOffset: 5
+ StaggerSpawns: 1
+ DestroyPlayerObjectWhenLeaving: 1
--- !u!1 &1318413499
GameObject:
m_ObjectHideFlags: 0
@@ -672,6 +674,7 @@ Terrain:
m_DetailObjectDensity: 1
m_HeightmapPixelError: 5
m_SplatMapDistance: 1000
+ m_HeightmapMinimumLODSimplification: 0
m_HeightmapMaximumLOD: 0
m_ShadowCastingMode: 2
m_DrawHeightmap: 1
diff --git a/Samples~/First Person Shooter/Scripts/FPSController.cs b/Samples~/First Person Shooter/Scripts/FPSController.cs
index 7661ed0..8088559 100644
--- a/Samples~/First Person Shooter/Scripts/FPSController.cs
+++ b/Samples~/First Person Shooter/Scripts/FPSController.cs
@@ -4,127 +4,131 @@ using Netick.Unity;
namespace Netick.Samples.FPS
{
- public class FPSController : NetworkBehaviour
+ public class FPSController : NetworkBehaviour
+ {
+ [SerializeField]
+ private Transform _renderTransform;
+
+ [SerializeField]
+ private float _movementSpeed = 10;
+ [SerializeField]
+ private float _sensitivityX = 1.6f;
+ [SerializeField]
+ private float _sensitivityY = -1f;
+ [SerializeField]
+ private Transform _cameraParent;
+ private CharacterController _CC;
+ private Vector2 _camAngles;
+ private FPSInput _lastInput;
+
+ // Networked Properties
+ [Networked]
+ [Smooth]
+ public Vector2 YawPitch { get; set; }
+
+ public override void NetworkStart()
{
- [SerializeField]
- private Transform _renderTransform;
+ _CC = GetComponent();
- [SerializeField]
- private float _movementSpeed = 10;
- [SerializeField]
- private float _sensitivityX = 1.6f;
- [SerializeField]
- private float _sensitivityY = -1f;
- [SerializeField]
- private Transform _cameraParent;
- private CharacterController _CC;
- private Vector2 _camAngles;
-
- // Networked Properties
- [Networked][Smooth]
- public Vector2 YawPitch { get; set; }
-
- public override void NetworkStart()
- {
- _CC = GetComponent();
-
- if (IsInputSource)
- {
- var cam = Sandbox.FindObjectOfType();
- cam.transform.parent = _cameraParent;
- cam.transform.localPosition = Vector3.zero;
- cam.transform.localRotation = Quaternion.identity;
- }
- }
-
- public override void OnInputSourceLeft()
- {
- // destroy the player object when its input source (controller player) leaves the game.
- Sandbox.Destroy(Object);
- }
-
- public override void NetworkUpdate()
- {
- if (!IsInputSource || !Sandbox.InputEnabled)
- return;
-
- Vector2 mouseInputs = new Vector2(Input.GetAxisRaw("Mouse X") * _sensitivityX, Input.GetAxisRaw("Mouse Y") * _sensitivityY);
-
- var networkInput = Sandbox.GetInput();
- networkInput.Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
- networkInput.ShootInput |= Input.GetMouseButton(0);
- networkInput.YawPitch += mouseInputs;
- Sandbox.SetInput(networkInput);
-
- // we apply the rotation in update too to have smooth camera control.
- _camAngles = ClampAngles(_camAngles.x + mouseInputs.x, _camAngles.y + mouseInputs.y);
- ApplyRotations(_camAngles, false);
- }
-
- public override void NetworkFixedUpdate()
- {
- if (FetchInput(out FPSInput input))
- MoveAndRotate(input);
- }
-
- private void MoveAndRotate(FPSInput input)
- {
- // clamp movement inputs.
- input.Movement = new Vector3(Mathf.Clamp(input.Movement.x, -1f, 1f), Mathf.Clamp(input.Movement.y, -1f, 1f));
-
- // rotation.
- YawPitch = ClampAngles(YawPitch.x + input.YawPitch.x, YawPitch.y + input.YawPitch.y);
- ApplyRotations(YawPitch,false);
-
- // movement direction.
- var movement = transform.TransformVector(new Vector3(input.Movement.x, 0, input.Movement.y)) * _movementSpeed;
- movement.y = 0;
-
- var gravity = 15f * Vector3.down;
-
- // move.
- _CC.Move((movement + gravity) * Sandbox.FixedDeltaTime);
- }
-
-
- [OnChanged(nameof(YawPitch), invokeDuringResimulation: true)]
- private void OnYawPitchChanged(OnChangedData onChanged)
- {
- ApplyRotations(YawPitch, false);
- }
-
- public override void NetworkRender()
- {
- if (IsProxy)
- ApplyRotations(YawPitch, true);
- }
-
- private void ApplyRotations(Vector2 camAngles, bool isProxy)
- {
- // on the player transform, we apply yaw.
- if (isProxy)
- _renderTransform.rotation = Quaternion.Euler(new Vector3(0, camAngles.x, 0));
- else
- transform.rotation = Quaternion.Euler(new Vector3(0, camAngles.x, 0));
-
- // on the weapon/camera holder, we apply the pitch angle.
- _cameraParent.localEulerAngles = new Vector3(camAngles.y, 0, 0);
- _camAngles = camAngles;
- }
-
- private Vector2 ClampAngles(float yaw, float pitch)
- {
- return new Vector2(ClampAngle(yaw, -360, 360), ClampAngle(pitch, -80, 80));
- }
-
- private float ClampAngle(float angle, float min, float max)
- {
- if (angle < -360F)
- angle += 360F;
- if (angle > 360F)
- angle -= 360F;
- return Mathf.Clamp(angle, min, max);
- }
+ if (IsInputSource)
+ {
+ var cam = Sandbox.FindObjectOfType();
+ cam.transform.parent = _cameraParent;
+ cam.transform.localPosition = Vector3.zero;
+ cam.transform.localRotation = Quaternion.identity;
+ }
}
+
+ public override void OnInputSourceLeft()
+ {
+ // destroy the player object when its input source (controller player) leaves the game.
+ Sandbox.Destroy(Object);
+ }
+
+ public override void NetworkUpdate()
+ {
+ if (!IsInputSource || !Sandbox.InputEnabled)
+ return;
+
+ Vector2 mouseInputs = new Vector2(Input.GetAxisRaw("Mouse X") * _sensitivityX, Input.GetAxisRaw("Mouse Y") * _sensitivityY);
+
+ var networkInput = Sandbox.GetInput();
+ networkInput.Movement = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
+ networkInput.ShootInput |= Input.GetMouseButton(0);
+ networkInput.YawPitch += mouseInputs;
+ Sandbox.SetInput(networkInput);
+
+ // we apply the rotation in update too to have smooth camera control.
+ _camAngles = ClampAngles(_camAngles.x + mouseInputs.x, _camAngles.y + mouseInputs.y);
+ ApplyRotations(_camAngles, false);
+ }
+
+ public override void NetworkFixedUpdate()
+ {
+ FetchInput(out _lastInput);
+
+ if (IsInputSource || IsServer)
+ MoveAndRotate(_lastInput);
+ }
+
+ private void MoveAndRotate(FPSInput input)
+ {
+ // clamp movement inputs.
+ input.Movement = new Vector3(Mathf.Clamp(input.Movement.x, -1f, 1f), Mathf.Clamp(input.Movement.y, -1f, 1f));
+
+ // rotation.
+ YawPitch = ClampAngles(YawPitch.x + input.YawPitch.x, YawPitch.y + input.YawPitch.y);
+ ApplyRotations(YawPitch, false);
+
+ // movement direction.
+ var movement = transform.TransformVector(new Vector3(input.Movement.x, 0, input.Movement.y)) * _movementSpeed;
+ movement.y = 0;
+
+ var gravity = 15f * Vector3.down;
+
+ // move.
+ _CC.Move((movement + gravity) * Sandbox.FixedDeltaTime);
+ }
+
+
+ [OnChanged(nameof(YawPitch), invokeDuringResimulation: true)]
+ private void OnYawPitchChanged(OnChangedData onChanged)
+ {
+ ApplyRotations(YawPitch, false);
+ }
+
+ public override void NetworkRender()
+ {
+ if (!IsInputSource)
+ ApplyRotations(YawPitch, true);
+ }
+
+ private void ApplyRotations(Vector2 camAngles, bool isProxy)
+ {
+ // on the player transform, we apply yaw.
+ if (isProxy)
+ _renderTransform.rotation = Quaternion.Euler(new Vector3(0, camAngles.x, 0));
+ else
+ transform.rotation = Quaternion.Euler(new Vector3(0, camAngles.x, 0));
+
+ // on the weapon/camera holder, we apply the pitch angle.
+ _cameraParent.localEulerAngles = new Vector3(camAngles.y, 0, 0);
+ _camAngles = camAngles;
+ }
+
+ private Vector2 ClampAngles(float yaw, float pitch)
+ {
+ return new Vector2(ClampAngle(yaw, -360, 360), ClampAngle(pitch, -80, 80));
+ }
+
+ private float ClampAngle(float angle, float min, float max)
+ {
+ if (angle < -360F)
+ angle += 360F;
+ if (angle > 360F)
+ angle -= 360F;
+ return Mathf.Clamp(angle, min, max);
+ }
+ }
}
diff --git a/Samples~/First Person Shooter/Scripts/FPSInput.cs b/Samples~/First Person Shooter/Scripts/FPSInput.cs
index 2f6dac9..cb78705 100644
--- a/Samples~/First Person Shooter/Scripts/FPSInput.cs
+++ b/Samples~/First Person Shooter/Scripts/FPSInput.cs
@@ -3,13 +3,13 @@ using Netick;
namespace Netick.Samples.FPS
{
+ [Networked]
+ public struct FPSInput : INetworkInput
+ {
[Networked]
- public struct FPSInput : INetworkInput
- {
- [Networked]
- public Vector2 YawPitch { get; set; }
- [Networked]
- public Vector2 Movement { get; set; }
- public NetworkBool ShootInput;
- }
+ public Vector2 YawPitch { get; set; }
+ [Networked]
+ public Vector2 Movement { get; set; }
+ public NetworkBool ShootInput;
+ }
}
\ No newline at end of file
diff --git a/Scripts/GameStarter.cs b/Scripts/GameStarter.cs
index f899eef..d319353 100644
--- a/Scripts/GameStarter.cs
+++ b/Scripts/GameStarter.cs
@@ -45,7 +45,8 @@ namespace Netick.Samples
{
if (Application.isBatchMode)
{
- Application.targetFrameRate = FPS;
+ if (Cap)
+ Application.targetFrameRate = FPS;
Network.StartAsServer(Transport, Port, SandboxPrefab);
}
diff --git a/Scripts/PlayerSpawner.cs b/Scripts/PlayerSpawner.cs
index e20f2a5..d69f2e3 100644
--- a/Scripts/PlayerSpawner.cs
+++ b/Scripts/PlayerSpawner.cs
@@ -17,25 +17,27 @@ namespace Netick.Samples
public bool StaggerSpawns = true;
public bool DestroyPlayerObjectWhenLeaving = true;
- // This is called on the server when a player has connected.
- public override void OnPlayerConnected(NetworkSandbox sandbox, Netick.NetworkPlayer client)
+ // This is called when a player has joined the game.
+ public override void OnPlayerJoined(NetworkSandbox sandbox, NetworkPlayerId player)
{
+ if (sandbox.IsClient)
+ return;
var spawnPos = SpawnPosition.position;
if (StaggerSpawns)
- spawnPos += (HorizontalOffset * Vector3.left) * (sandbox.ConnectedPlayers.Count - 1);
- var player = sandbox.NetworkInstantiate(PlayerPrefab, spawnPos, SpawnPosition.rotation, client);
- client.PlayerObject = player;
+ spawnPos += (HorizontalOffset * Vector3.left) * (sandbox.Players.Count - 1);
+ var playerObj = sandbox.NetworkInstantiate(PlayerPrefab, spawnPos, SpawnPosition.rotation, player);
+ sandbox.SetPlayerObject(player, playerObj);
}
- // This is called on the server when a player has disconnected.
- public override void OnPlayerDisconnected(NetworkSandbox sandbox, Netick.NetworkPlayer client, TransportDisconnectReason transportDisconnectReason)
+ // This is called when a player has left the game.
+ public override void OnPlayerLeft(NetworkSandbox sandbox, NetworkPlayerId player)
{
+ if (sandbox.IsClient)
+ return;
if (!DestroyPlayerObjectWhenLeaving)
return;
-
- var netObj = client.PlayerObject as NetworkObject;
- if (netObj != null)
- Sandbox.Destroy(netObj);
+ if (sandbox.TryGetPlayerObject(player, out var playerObj))
+ Sandbox.Destroy(playerObj);
}
}
}
diff --git a/package.json b/package.json
index 69ae589..bcf67a3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "com.karrar.netick",
- "version": "0.13.71",
+ "version": "0.14.2",
"displayName": "Netick",
"description": "A networking solution for Unity",
"unity": "2021.3",