- Notifications
You must be signed in to change notification settings - Fork2
A library that simplifies repetitive tasks with the DarkRift library.
License
Penca53/DarkRiftLibrary-MLAPI
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This library is focused on simplifing similar repetitive tasks that you have to deal with writing and reading messages from server to client and vice versa.
In this section you will learn how to setup and use the library.
To download it you have to go in the GitHub's release section and download the lastest release. Then you just have to add to thereferencesDarkRiftLibrary-MLAPI.dll
: Go inSolution Explorer
/ Right click onReference
/Add Reference
/Browse
and search for it. If you're usingUnity, then you have to create a folder calledPlugins and move theDarkRiftLibrary-MLAPI.dll
file to the folder.
This library is simple and immediate... It provides you a new interface calledISync
that you can implement in your classes that need to be synced. Once you derive from it, you have to implement a property calledTypeID
, which stores the ID of the current class. It is used to unpack a received message into one specific type. Then there are 2 methods which you should already know:Serialize
andDeserialize
. They can be used toserialize anddeserializeall the object. Finally there are 2 new methods calledSerializeOptional
andDeserializeOptional
. As the name suggests, they are used toserialize anddeserialize data depending on acondition, which is thetag
parameter. You can use thetag
to know in which situation you're in and, depending on it, you canserialize anddeserialize one field instead of another. In GitHub you can find a folder called Example where there are 2 Visual Studio projects: the client and the server. You can try them starting theserver and then starting theclient: you will be asked to write a number between0 and 6, and you will have to write in twice because you will get anerror (don't worry).
Serialization
SerializeOptional(DarkRiftWriter, int)
Used to serialize data depending on thetag
condition.- Extensions (which call
SerializeOptional(DarkRiftWriter, int)
)DarkRiftWriter.Write(ISync sync, bool sendTypeID = false)
Serializessync
using the default tag (-1) and it has the condition to send theTypeID
.DarkRiftWriter.Write(ISync sync, int tag, bool sendTag = false, bool sendTypeID = false)
Serializessync
using thetag
, it has the condition to send theTag
and has the condition to send theTypeID
.DarkRiftWriter.Write(ISync sync, ExtraSyncData extraSyncData, int tag = -1)
Serializessync
using thetag
, it has the conditionenumextraSyncData
where you can choose the extra data to send.
Deserialization
DeserializeOptional(DarkRiftReader, int)
Used to deserialize data depending on thetag
condition.- Extenstions (which call
DeserializeOptional(DarkRiftReader, int)
)ISync ReadSerializable()
Deserializes the message into a new instance of a type written in the message (which has to implement ISync) and as tag it uses the one written in the message or -1 if there isn't (default).T ReadSerializable<T>()
Deserializes the message into a new instance of the type given (which has to implement ISync) and as tag it uses the one written in the message or -1 if there isn't (default).ISync ReadSerializable(int tag)
Deserializes the message into a new instance of a type written in the message (which has to implement ISync) and as tag it uses the parametertag
.T ReadSerializable<T>(int tag)
Deserializes the message into a new instance of a type given (which has to implement ISync) and as tag it uses the parametertag
.ReadSerializable(DarkRiftReader reader)
Deserializes the message and updates the given instance (which has to implement ISync) and as tag it uses the one written in the message or -1 if there isn't (default).ReadSerializable(DarkRiftReader reader, int tag)
Deserializes the message and updates the given instance (which has to implement ISync) and as tag it uses the parametertag
.
ExtrasISync
has 1 property:TypeID
which stores the ID of the type of the class. You have to assign one unique number to each class that implementsISync
so that when you will read a message without knowing the type to cast to, the library will use theTypeID
written in the message to return the correctType.NOTE: if you know the type everytime you receive a message, then you can don't useTypeID
and choose to not send it to slightly reduce the bandwidth!
- .NET Framework 4.7.2
- DarkRift 2
Apache-2.0
- Penca53
About
A library that simplifies repetitive tasks with the DarkRift library.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.