新增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,19 @@
---
description: >-
Scene Data is the data types used that the user will interface with when using
the SceneManager.
---
# Scene Data
{% embed url="https://www.youtube.com/watch?index=2&list=PLkx8oFug638qBthd3n_F98zAtOdI8o_Gb&v=T23OiTKy500" %}
SceneLoadData video guide
{% endembed %}
## General
See Sub-Pages below for the different Scene Data Classes.
* [**SceneLookupData**](scenelookupdata.md)
* [**SceneLoadData**](sceneloaddata.md)
* [**SceneUnloadData**](sceneunloaddata.md)
@@ -0,0 +1,125 @@
---
description: >-
The Data Class needed for the SceneManager to know how to handle loading a
scene.
---
# SceneLoadData
## General
Loading scenes of all types depend upon SceneLoadData. The SceneLoadData class contains information about what scenes to load, how to load them, which objects to move to new scenes, and more. You can view the SceneLoadData API [here](https://fish-networking.com/FishNet/api/api/FishNet.Managing.Scened.SceneLoadData.html).
## Default values
```csharp
SceneLoadData sld = new SceneLoadData()
{
PreferredActiveScene = null,
SceneLookupDatas = new SceneLookupData[0],
MovedNetworkObjects = new NetworkObject[0],
ReplaceScenes = ReplaceOption.None,
Params = new LoadParams()
{
ServerParams = new object[0],
ClientParams = new byte[0]
},
Options = new LoadOptions()
{
AutomaticallyUnload = true,
AllowStacking = false,
LocalPhysics = LocalPhysicsMode.None,
ReloadScenes = false, // Obsolete, Coming Soon.
Addressables = false
}
};
```
<details>
<summary>PreferredActiveScene</summary>
Preferred Active Scene will allow you to choose what scene will be active on the server and/or client. You can choose to have the chosen SceneLookupData apply to both the server and client or separate ones for each.
If left with the default value of null, the first valid scene loaded will become the ActiveScene.
</details>
<details>
<summary>SceneLookupDatas</summary>
This Array is populated with scenes you would like to load, depending on the parameters you pass into the SceneLoadData when constructed.
See [**Loading Scenes**](../loading-scenes/) for examples.
</details>
<details>
<summary>MovedNetworkObjects</summary>
Instantiated NetworkObjects can be moved when loading new scenes, such as if you want to move a player to a different scene as you load the new scene. You may include an array of NetworkObjects to move to the new scenes. NetworkObjects within this array will be moved to the first scene specified in SceneLookupData.\
\
See [**Persisting NetworkObjects**](../persisting-networkobjects.md) for more details on what type of NetworkObjects you are allowed to move.
</details>
<details>
<summary>ReplaceScenes</summary>
Like the Unity SceneManager when loading a single scene, ReplaceScenes allows you to replace currently loaded scenes with new ones. There are a variety of options to use.\
\
See [**Replacing Scenes**](../loading-scenes/#replacing-scenes) Section of Loading Scenes guide for more details and examples.
</details>
<details>
<summary>Params</summary>
Params are an optional way to assign data to your scene loads/unloads. This data will be available within[ **Scene Events**](../scene-events.md), Information used in Params can be useful for storing information about the scene load/unload and referencing it later when the scene load/unload completes.
**ServerParams**
_ServerParams_ are only included on the server side, and are not networked. It is an array of objects, meaning you can send anything you want. However when accessing the Params through event args, you will have to cast the object to the data you want.
**ClientParams**
_ClientParams_ is a byte array which may contain anything, and will be sent to clients when they receive the load scene instructions. Clients can access the _ClientParams_ within the scene change events.
</details>
<details>
<summary>Options</summary>
You may further enhance how you load/unload scenes with Options.
**AutomaticallyUnload**
* When _set to_ true scenes will be unloaded automatically on the server when there are no more connections present. This is the default behaviour.
* When set to false the scene will remain if connections leave the scene unexpected, such as being disconnected.
* However, discussed in UnloadSceneData, this behavior can be overriden using the UnloadOptions of UnloadSceneData.
* Only scenes loaded for connections will be automatically unloaded when emptied.
* Global scenes can only be unloaded using ReplaceScenes or by calling unload on them.
**AllowStacking**
* When _AllowStacking_ remains false the SceneManager will not stack scenes in your SceneLoadDatas.
* If true, then scenes can be stacked (loaded multiple times).
* In the SceneLookupData section it was mentioned that if a Scene reference or handle is specified then the SceneManager will favor loading a scene using a scene handle. When you would like to load connections into the same stacked scene over multiple load calls, you will populate your SceneLookupDatas by Scene reference or handle.
* See [**Scene Stacking**](../scene-stacking.md) for more detail and examples
**LocalPhysics**
* [_LocalPhysics_](https://docs.unity3d.com/ScriptReference/SceneManagement.LocalPhysicsMode.html) is a Unity property that lets you determine how physics are simulated in your scenes.
* Generally, if you are stacking scenes you will want to set a LocalPhysics mode so that stacked scenes do not collide with each other.
**Addressables**
* _Addressables_ is only used as a reference and performs no additional functionality.
* You may set this value to know if a scene is loading using addressables, without having to create Params.
</details>
@@ -0,0 +1,36 @@
---
description: >-
SceneLookupData is how the server determines to load clients into a new
instance of a Scene, or load a client into a scene that the server already has
loaded.
---
# SceneLookupData
## General
{% hint style="warning" %}
When Creating [**SceneLoadData**](sceneloaddata.md) or [**SceneUnloadData**](sceneunloaddata.md) there are provided constructors that automatically create SceneLookupData for you. Most likely you will be using these constructors and will not be creating a separate SceneLookupData.
{% endhint %}
When you specify a scene by reference, or handle, the SceneManager will prefer to lookup that scene using the scene handle. This is important information when [**Scene Stacking**](../scene-stacking.md). Looking up a scene by handle or object reference will place connections in the scene specified, but when using scene names, the server will create a new scene instance for the specified connections and place them into that scene. The described behavior only applies when loading scenes over multiple load calls; such as if you call LoadConnectionScene twice, each with its own connection.
## Default values
{% hint style="info" %}
A Scene Handle is an integer that Unity generates for a scene instance when it is loaded. You can use it to specify an instance of a scene that is already loaded, but not for loading a new instance of that scene. Read more about it here: [https://docs.unity3d.com/ScriptReference/SceneManagement.Scene-handle.html](https://docs.unity3d.com/ScriptReference/SceneManagement.Scene-handle.html)
{% endhint %}
```csharp
// SceneLookupData default values
SceneLookupData slud = new SceneLookupData()
{
// If Handle is greater than 0 then it will ignore Name and use Handle
// to look up the scene.
Handle = 0,
// If Handle is set to 0, then Name is used to lookup the scene instead.
Name = null
};
```
See[ **Loading Scenes**](../loading-scenes/) and [**Unloading Scenes**](../unloading-scenes.md) for implementation.
@@ -0,0 +1,76 @@
---
description: >-
The Data Class needed for the SceneManager to know how to handle unloading a
scene.
---
# SceneUnloadData
## General
When unloading scenes information on what to unload is constructed within the SceneUnloadData class. SceneUnloadData is very similar to SceneLoadData. The API for SceneUnloadData can be found [here](https://fish-networking.com/FishNet/api/api/FishNet.Managing.Scened.SceneUnloadData.html).
## Default values
```csharp
SceneUnloadData sud = new SceneUnloadData()
{
SceneLookupDatas = new SceneLookupData[0],
Params = new UnloadParams()
{
ServerParams = new object[0],
ClientParams = new byte[0]
},
Options = new UnloadOptions()
{
Mode = ServerUnloadMode.UnloadUnused,
Addressables = false
}
};
```
<details>
<summary>SceneLookupDatas</summary>
This Array is populated with the scenes you want to unload, depending on the parameters you pass into the SceneUnloadData when constructed.
See [**Unloading Scenes**](../unloading-scenes.md) for examples.
</details>
<details>
<summary>Params</summary>
Params are an optional way to assign data to your scene loads/unloads. This data will be available within[ **Scene Events**](../scene-events.md), Information used in Params can be useful for storing information about the scene load/unload and referencing it later when the scene load/unload completes.
**ServerParams**
_ServerParams_ are only included on the server side and are not networked. It is an array of objects, meaning you can send anything you want. However when accessing the Params through event args, you will have to cast the object to the data you want.
**ClientParams**
_ClientParams_ is a byte array which may contain anything. It will be sent to clients when they receive the load scene instructions. Clients can access the _ClientParams_ within the scene change events.
</details>
<details>
<summary>Options</summary>
Like with Options in loading, the UnloadOptions offer additional settings when unloading.
**Mode**
These values will override the AutomaticallyUnload Option that was used when loaded the scene. If you set _AutomaticallyUnload_ to false but specified _ServerUnloadModes.UnloadUnused_ then the scene would be unloaded when emptied.
**ServerUnloadModes.UnloadUnused**
* This is the default setting which will only unload a scene which is no longer used.
**ServerUnloadModes.KeepUnused**
* This option will keep the scene loaded on the server if all clients have been removed. See [**Scene Caching**](../scene-caching.md) for more details
</details>