Sending Events
This section covers how to send events over the network.
First, you need to create a unique identifier for this event, this identifier shall be a positive integer number.
const int CUSTOM_EVENT = 10000;
Note: Is highly recommenced to group events to avoid two events using the same code.
Events provide the possibility to send data, for example, in an event to restart a player position you may wish to send position information in the message. ObjectNet allows us to do this by using DataWritter.
This code illustrates how to send an event over the network, you can include data on the message to be received at the target destination.
using (DataStream writer = new DataStream()) {
writer.Write(this.targetPosition); // Vector3
writer.Write(this.remaingLife); // float
writer.Write(this.money); // int
// Send event
NetworkManager.Instance().Send(CUSTOM_EVENT, writer, DeliveryMode.Reliable);
}
You can include the following data types on the event message.
int
uint
long
ulong
short
ushort
float
double
byte
byte[]
string
char
char[]
bool
Vector3
Color