Show / Hide Table of Contents

Class NetworkManager

The network manager for multiplayer.
多人連線的網絡管理員。

Inheritance
System.Object
UnityEngine.Object
UnityEngine.Component
UnityEngine.Behaviour
UnityEngine.MonoBehaviour
NetworkManager
vGear_Networking
Namespace: Votanic.vNet.Networking
Assembly: Votanic.vNet.dll
Syntax
[AddComponentMenu("")]
public class NetworkManager : MonoBehaviour

Fields

address

Address of connection.
連線位址。

Declaration
[Tooltip("Address of connection.\n連線位址。")]
public string address
Field Value
Type Description
System.String

autoConnect

Auto start connection on start if true.
當 true 時在開始時自動開始連線。

Declaration
[Tooltip("Auto start connection on start.\n在開始時自動開始連線。")]
public bool autoConnect
Field Value
Type Description
System.Boolean

connectingBuffer

Buffer for connection.
連線緩衝。

Declaration
[Tooltip("Buffer for connection.\n連線緩衝。")]
public float connectingBuffer
Field Value
Type Description
System.Single

defaultSendID

By default include user ID in sent message.
預設傳送訊息包含使用者編號。

Declaration
[Tooltip("By default include user ID in sent message.\n預設傳送訊息包含使用者編號。")]
public bool defaultSendID
Field Value
Type Description
System.Boolean

defaultSendName

By default include user name in sent message.
預設傳送訊息包含使用者名稱。

Declaration
[Tooltip("By default include user name in sent message.\n預設傳送訊息包含使用者名稱。")]
public bool defaultSendName
Field Value
Type Description
System.Boolean

errorLog

Error log of connection.
連線錯誤訊息。

Declaration
[Tooltip("Error log of connection.\n連線錯誤訊息。")]
public string errorLog
Field Value
Type Description
System.String

hostMsg

Start hosting message.
開始主持訊息。

Declaration
[Header("[Host]")]
[Tooltip("Start hosting message.\n開始主持訊息。")]
public string hostMsg
Field Value
Type Description
System.String

joinMsg

Joined connection message.
加入連線的訊息。

Declaration
[Header("[Client]")]
[Tooltip("Joined connection message.\n加入連線的訊息。")]
public string joinMsg
Field Value
Type Description
System.String

maxConnections

Maximum number of users.
最大使用者數目。

Declaration
[Tooltip("Maximum number of users.\n最大使用者數目。")]
public int maxConnections
Field Value
Type Description
System.Int32

messageLog

Display received messages on debug log.
在偵錯日誌顯示已接收的訊息。

Declaration
[Tooltip("Display received messages on debug log.\n在偵錯日誌顯示已接收的訊息。")]
public bool messageLog
Field Value
Type Description
System.Boolean

messages

All received messages.
所有已接收訊息。

Declaration
[Tooltip("All received messages.\n所有已接收訊息。")]
public List<string> messages
Field Value
Type Description
System.Collections.Generic.List<System.String>

networkID

Network ID of current connection.
目前連線使用的識別碼。

Declaration
[Tooltip("Network ID of current connection.\n目前連線使用的識別碼。")]
public uint networkID
Field Value
Type Description
System.UInt32

networkName

Network user name.
網絡使用者名稱。

Declaration
[Tooltip("Network user name.\n網絡使用者名稱。")]
public string networkName
Field Value
Type Description
System.String

numOfUsers

Number of users.
使用者數目。

Declaration
[Tooltip("Number of users.\n使用者數目。")]
public int numOfUsers
Field Value
Type Description
System.Int32

port

Port of connection.
連接埠。

Declaration
[Tooltip("Port of connection.\n連接埠。")]
public int port
Field Value
Type Description
System.Int32

quitMsg

Quit connection message.
離開連線的訊息。

Declaration
[Tooltip("Quit connection message.\n離開連線的訊息。")]
public string quitMsg
Field Value
Type Description
System.String

ReceivedMessage

The delegate function.
委託的功能。

Declaration
public NetworkManager.OnReceived ReceivedMessage
Field Value
Type Description
NetworkManager.OnReceived

reconnect

Auto reconnect times when connection is failed.
當連線失敗時的自動重連次數。

Declaration
[Tooltip("Auto reconnect times when connection is failed.\n當連線失敗時的自動重連次數。")]
public int reconnect
Field Value
Type Description
System.Int32

spawnPrefabs

Networking spawnable prefabes.
網絡可生成的預製件。

Declaration
[Tooltip("Networking spawnable prefabes.\n網絡可生成的預製件。")]
public List<GameObject> spawnPrefabs
Field Value
Type Description
System.Collections.Generic.List<UnityEngine.GameObject>

state

Connection state of networking.
網絡連線狀態。

Declaration
[Header("[Status]")]
[Tooltip("Connection state of networking.\n網絡連線狀態。")]
public ConnectionState state
Field Value
Type Description
ConnectionState

stopMsg

Stop hosting message.
結束主持訊息。

Declaration
[Tooltip("Stop hosting message.\n結束主持訊息。")]
public string stopMsg
Field Value
Type Description
System.String

type

User type of current connection.
目前連線的使用者類型。

Declaration
[Header("[Settings]")]
[Tooltip("User type of current connection.\n目前連線的使用者類型。")]
public UserType type
Field Value
Type Description
UserType

userPrefab

User prefab for networking.
網絡使用者預製件。

Declaration
[Header("[Components]")]
[Tooltip("User prefab for networking.\n網絡使用者預製件。")]
public GameObject userPrefab
Field Value
Type Description
UnityEngine.GameObject

Properties

uNetManager

The Unity Network Manager component.
Unity 網絡管理員組件。

Declaration
public NetworkManager uNetManager { get; }
Property Value
Type Description
UnityEngine.Networking.NetworkManager

Methods

AddNetworkMessage(Int16, NetworkMessageDelegate)

Add custom network message handler.
新增自定義網絡訊息處理器。

AddNetworkMessage(300, OnReceivedCustom)

Declaration
protected void AddNetworkMessage(short channel, NetworkMessageDelegate handler)
Parameters
Type Name Description
System.Int16 channel

Message channel, please choose from 1000
訊息頻道,請由 1000 開始選擇

UnityEngine.Networking.NetworkMessageDelegate handler

The handler of message.
訊息處理器

ChangeName(String, Boolean)

Change the own network user name.
更改自身網絡使用者名稱。

ChangeName("UserB")

Declaration
public virtual void ChangeName(string name, bool message = true)
Parameters
Type Name Description
System.String name

New name
新名稱

System.Boolean message

Show message if true
當 true 時顯示訊息

ChangeScene(Int32)

Change all users' scene by name.

ChangeScene(0)

Declaration
public void ChangeScene(int index)
Parameters
Type Name Description
System.Int32 index

Scene index
場景編號

ChangeScene(String)

Change all users' scene by name.

ChangeScene("Scene1")

Declaration
public void ChangeScene(string name)
Parameters
Type Name Description
System.String name

Scene name
場景名稱

Connect()

Connect to server.
連線至伺服器。

Declaration
public void Connect()

Connect(String, Int32)

Connect to server.
連線至伺服器。

Connect("localhost", 7777)

Declaration
public void Connect(string address, int port = 7777)
Parameters
Type Name Description
System.String address

IP address
IP 位址

System.Int32 port

Port
連接埠

Disconnect()

Disconnect to server.
中斷連線。

Declaration
public void Disconnect()

GetAllNetworkIdentities()

Get all Network Identity compnoents.
取得所有網絡識別器組件。

Declaration
public List<NetworkIdentity> GetAllNetworkIdentities()
Returns
Type Description
System.Collections.Generic.List<UnityEngine.Networking.NetworkIdentity>

GetAllNetworkObjects()

Get all Network Object compnoents.
取得所有網絡物件。

Declaration
public List<NetworkObject> GetAllNetworkObjects()
Returns
Type Description
System.Collections.Generic.List<NetworkObject>

GetAllNetworkUsers()

Get all Network Users in connection.
取得連線中的所有網絡使用者。

Declaration
public List<NetworkUser> GetAllNetworkUsers()
Returns
Type Description
System.Collections.Generic.List<NetworkUser>

GetNetworkIdentity(UInt32)

Get the Network Identity compnoent.
取得網絡識別器組件。

GetNetworkIdentity(0)

Declaration
public NetworkIdentity GetNetworkIdentity(uint netID)
Parameters
Type Name Description
System.UInt32 netID

Network ID of object
物件網絡識別碼

Returns
Type Description
UnityEngine.Networking.NetworkIdentity

GetNetworkObject(UInt32)

Get the Network Object compnoent.
取得網絡物件。

GetNetworkObject(0)

Declaration
public NetworkObject GetNetworkObject(uint netID)
Parameters
Type Name Description
System.UInt32 netID

Network ID of object
物件網絡識別碼

Returns
Type Description
NetworkObject

GetNetworkUser(UInt32)

Get the Network User in connection.
取得連線中的網絡使用者。

GetNetworkUser(0)

Declaration
public NetworkUser GetNetworkUser(uint userID)
Parameters
Type Name Description
System.UInt32 userID

Connection ID of user
使用者的連線識別碼

Returns
Type Description
NetworkUser

Host()

Start hosting.
開始主持。

Declaration
public void Host()

Host(Int32)

Start hosting.
開始主持。

Host(7777)

Declaration
public void Host(int port = 7777)
Parameters
Type Name Description
System.Int32 port

Port
連接埠

Initialize()

Initialization of network manager.
網絡管理員初始化功能。

Declaration
protected virtual void Initialize()

OnDestroy()

Declaration
[Obfuscation(Exclude = true)]
public virtual void OnDestroy()

ReturnAuthority(NetworkIdentity)

Return the authority of a network object to host. 交還一個網絡物件的控制權給主持。

ReturnAuthority(gameObject.GetComponent("NetworkIdentity"))

Declaration
public void ReturnAuthority(NetworkIdentity identity)
Parameters
Type Name Description
UnityEngine.Networking.NetworkIdentity identity

Network identity component
網絡識別器

Send(String, Boolean, Boolean, Int32[])

Send message.
傳送訊息。

Send("Hello World!")

Declaration
public virtual void Send(string message, bool withName = true, bool withID = false, params int[] usersID)
Parameters
Type Name Description
System.String message

Content
內容

System.Boolean withName

Display [Name]
顯示 [名稱]

System.Boolean withID

Display (ID)
顯示 (識別碼)

System.Int32[] usersID

Specific users ID
指定的使用者識別碼

SetAuthority(NetworkIdentity, Boolean)

Set the authority of a network object as own user. 設定一個網絡物件的控制者為自身使用者。

SetAuthority(gameObject.GetComponent("NetworkIdentity"))

Declaration
public void SetAuthority(NetworkIdentity identity, bool forceSyncTransform = false)
Parameters
Type Name Description
UnityEngine.Networking.NetworkIdentity identity

Network identity component
網絡識別器

System.Boolean forceSyncTransform

Force instantly sync network object transform
強制馬上同步網絡物件的 Transform

Start()

Declaration
[Obfuscation(Exclude = true)]
public virtual void Start()

StartNetworkConnection()

Start network connection by your current user type.
根據你的使用者類型開始網絡連線。

Declaration
public void StartNetworkConnection()

Stop()

Stop hosting.
結束主持。

Declaration
public void Stop()

StopNetworkConnection()

Stop network connection by your current user type.
根據你的使用者類型終止網絡連線。

Declaration
public void StopNetworkConnection()

SyncUsers()

Sync users information.
同步使用者資訊。

Declaration
protected virtual void SyncUsers()

Update()

Declaration
[Obfuscation(Exclude = true)]
public virtual void Update()
In This Article
Back to top Generated by DocFX