新增FishNet文档

This commit is contained in:
2026-09-20 15:53:11 +08:00
parent c403145db9
commit 179c282405
431 changed files with 15476 additions and 0 deletions
@@ -0,0 +1,8 @@
---
description: >-
The following pages give some commonly used terminology for Fish-Networking as
well as general networking terms you are likely to encounter.
---
# Terminology
@@ -0,0 +1,105 @@
---
description: There are a variety of ways to send communications between server and clients.
---
# Communicating
Below are several terms you will become familiar with when wanting to send data.
## [SyncTypes](../../features/network-communication/synchronizing/) <a href="#server-and-host" id="server-and-host"></a>
{% tabs %}
{% tab title="Description" %}
SyncTypes reside on objects and are data driven variables or collections. SyncTypes send at adjustable intervals. When a SyncType is modified on an object the changes are automatically sent from the server to clients. Clients will receive the changes locally on the same object. A great example is a health variable. You may update the health variable as a player takes damage, and the new values will be sent to clients.
{% endtab %}
{% tab title="Example" %}
This basic example shows a simple integer variable that will automatically be synchronized to all clients whenever the server changes it.
```csharp
using FishNet.Object;
using FishNet.Object.Synchronizing;
public class Player : NetworkBehaviour
{
private readonly SyncVar<int> _health = new SyncVar<int>(100);
public void StepOnLego()
{
if (!IsServerInitialized)
return;
_health. Value -= 10;
}
}
```
{% endtab %}
{% endtabs %}
## [Remote Procedure Calls](../../features/network-communication/remote-procedure-calls.md) <a href="#server-and-host" id="server-and-host"></a>
{% tabs %}
{% tab title="Description" %}
[Remote Procedure Calls](#user-content-fn-1)[^1] are another object bound communication type. While SyncTypes are used to synchronize variables, RPCs allow you to run logic on server and clients. RPCs are not limited to an interval like states, RPCs can be sent immediately on the next network tick or as soon as possible. They are required to be within a NetworkBehaviour class.
{% endtab %}
{% tab title="Example" %}
This is a simple example that shows a [Server Remote Procedure Call](#user-content-fn-2)[^2]. The method should be called from a client and the body will not execute locally, instead, the arguments will be sent across the network and the method body with those arguments will run remotely on the server.
```csharp
using FishNet.Object;
public class Player : NetworkBehaviour
{
[ServerRpc]
private void UpdatePlayerName(string newName)
{
print($"Player {OwnerId} has updated their name to {newName}");
}
}
```
{% endtab %}
{% endtabs %}
## [Broadcasts](../../features/network-communication/broadcasts.md) <a href="#server-and-host" id="server-and-host"></a>
{% tabs %}
{% tab title="Description" %}
Unlike states, broadcasts are not object bound. Broadcasts can be used for any number of tasks but are more commonly preferred for communicating data groups between server and clients. Broadcasts can be received and sent from anywhere in your code and do not need to be within a NetworkBehaviour class as RPCs do.
{% endtab %}
{% tab title="Example" %}
This example shows how a client could send a broadcast to the server.
```csharp
using FishNet;
using UnityEngine;
public class ChatSystem : MonoBehaviour
{
public void SendChatMessage(string text)
{
ChatBroadcast msg = new ChatBroadcast()
{
Message = text,
FontColor = Color.white
};
InstanceFinder.ClientManager.Broadcast(msg);
}
}
```
{% endtab %}
{% endtabs %}
{% hint style="info" %}
For all of the above communication methods, two channels are supported, Reliable and Unreliable. Data sent reliably is guaranteed to arrive and be processed in the order it was sent. Data sent unreliably uses less bandwidth, but can occasionally arrive out of order, or not at all.
{% endhint %}
{% hint style="info" %}
Some features of Fish-Networking internally use eventual consistency; an example of this are unreliable SyncVars or the NetworkTransform component. These features use the unreliable channel to send datas to consume less bandwidth and provide better performance, but you can still use them knowing that even if data is dropped or arrives out of order the features will eventually resolve the desynchronizations automatically.
{% endhint %}
[^1]: Often called RPCs
[^2]: These are commonly called ServerRPCs
@@ -0,0 +1,27 @@
---
description: >-
There are a several commonly terms which you may encounter throughout your
development experience with FishNet.
---
# Miscellaneous
## Scene object
A scene object is an object which is placed in a scene's hierarchy during edit-time. Scene objects are objects which may be spawned over the network, but do not require instantiating as they are already placed in the scene.
## Instantiated object
An instantiated object is an object which was instantiated at run-time, and is not a scene object. For example, `Instantiate(yourPrefab)`.
## Predicted object
An object which utilizes the prediction system. Predicted features generally run on the client and server at the same time to allow real-time gameplay interactions. These types of behaviors require more work but a proper prediction setup will prevent cheating.
## Client authoritative
Often means an object is controlled by the client and results are sent to the server without validation. Client authortative coding is easier to understand but may allow players to cheat more easily. An example of this is a NetworkTransform component with Client Authoritative set to true; the client controls the object locally and the server updates to client's values.
## Server authoritative
Values are controlled or verified by the server, such as SyncTypes. Predicted objects are server authoritative.
@@ -0,0 +1,37 @@
# Server, Client, Host
## Ownership and controller <a href="#server-and-host" id="server-and-host"></a>
Ownership is when a specific client _owns_ the object, while _controller_ is whichever entity controls the object. By our terms, only a client can own an object, but either the server or a client may be the controller.
When a client owns an object they are the 'controller' and are able to send [remote procedure calls](../../features/network-communication/remote-procedure-calls.md) without disabling authority checks, among other tasks such as generating prediction data.
A controller is the server if the object is not owned by any client, but again, the client becomes the controller when they own the object.
## Server <a href="#server-and-host" id="server-and-host"></a>
Server is an instance of your project which clients connect to. A server allows clients to interact with each other and will often be responsible for important aspects of your game such as score keeping, world spawning, and more.
#### Local server
When a server is started the build or instance running the server is referred to as the local server.
#### Remote client
A remote client is a term only applicable when running as the server. A remote client is a player connection established with the server. It's possible for a remote client to be the same as a local client. The main difference is the local client refers to the player-side logic while a remote client refers to the server's connection with the client.
## Client <a href="#server-and-host" id="server-and-host"></a>
A client connects to the server, whether the server be local or online. A client is the player for your game. A client experiences the game-play while the server synchronizes data between clients.
#### Local client
Local client refers to the client controlling their game. If you join the server as a player, you are the local client.
#### Remote server
When the local client connects to a server, they are connecting to a remote server. It's possible the remote server is also the local server if the client is running as host.
## Host <a href="#server-and-host" id="server-and-host"></a>
When behaving as a host you are both the client and the server. An individual can become host without having to compile additional executables, nor having to provide any special access to their computer. Host is ideal for speedy development.