C# Класс ChatApp, webrtcnetwork

Contains a complete chat example. It can either run in the editor using the old unity network or in the browser as WebGL/HTML5 using WebRtc. The chat app will report during start which system it uses. The user can enter a room name and click the "Open room" button to start a server and wait for incomming connections or use the "Join room" button to join an already existing room. Note: Unity network uses random numbers / guid to idendify a server. The room name entered by the user will be ignored. As the system implements a server/client style connection all messages will first be sent to the server and the server delivers it to each client. The server side ConnectionId is used to idendify a user.
Наследование: MonoBehaviour
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
uJoin Button
uMessageField InputField,
uOpenRoom Button
uOutput MessageList,
uRoomName InputField,
uSend Button
uShutdown Button

Открытые методы

Метод Описание
Exit ( ) : void

Called if the Exit button is pressed. Quits the scene and shuts everything down.

Join ( ) : void

Join button pressed. Tries to join a room.

OpenRoom ( ) : void

Open room button pressed. Opens a room / starts a server

SendButtonPressed ( ) : void

This is called if the send button

Shutdown ( ) : void

Shutdown button pressed. Shuts the network down.

Приватные методы

Метод Описание
Append ( string text ) : void

Adds a new message to the message view

FixedUpdate ( ) : void
HandleIncommingMessage ( NetworkEvent &evt ) : void
HandleNetwork ( ) : void
OnGUI ( ) : void
SendString ( string msg, bool reliable = true ) : void

Sends a string as UTF8 byte array to all connections

SetGuiState ( bool isDisconnected ) : void

Changes the gui depending on if the user is connected or disconnected

Start ( ) : void

Описание методов

Exit() публичный Метод

Called if the Exit button is pressed. Quits the scene and shuts everything down.
public Exit ( ) : void
Результат void

Join() публичный Метод

Join button pressed. Tries to join a room.
public Join ( ) : void
Результат void

OpenRoom() публичный Метод

Open room button pressed. Opens a room / starts a server
public OpenRoom ( ) : void
Результат void

SendButtonPressed() публичный Метод

This is called if the send button
public SendButtonPressed ( ) : void
Результат void

Shutdown() публичный Метод

Shutdown button pressed. Shuts the network down.
public Shutdown ( ) : void
Результат void

Описание свойств

uJoin публичное свойство

Join button to connect to a server.
public Button uJoin
Результат Button

uMessageField публичное свойство

Input field to enter a new message.
public InputField, uMessageField
Результат InputField,

uOpenRoom публичное свойство

Open room button to start a server.
public Button uOpenRoom
Результат Button

uOutput публичное свойство

Output message list to show incomming and sent messages + output messages of the system itself.
public MessageList, uOutput
Результат MessageList,

uRoomName публичное свойство

Input field used to enter the room name.
public InputField, uRoomName
Результат InputField,

uSend публичное свойство

Send button.
public Button uSend
Результат Button

uShutdown публичное свойство

Shutdown button. Disconnects all connections + shuts down the server if started.
public Button uShutdown
Результат Button