Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A library that simplifies repetitive tasks with the DarkRift library.

License

NotificationsYou must be signed in to change notification settings

Penca53/DarkRiftLibrary-MLAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 

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.

Getting Started

In this section you will learn how to setup and use the library.

Installing

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.

How to use

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 thetagparameter. 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).

Documentation

Serialization

  • SerializeOptional(DarkRiftWriter, int) Used to serialize data depending on thetag condition.
  • Extensions (which callSerializeOptional(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 callDeserializeOptional(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!

Built With

License

Apache-2.0

Authors

  • Penca53

About

A library that simplifies repetitive tasks with the DarkRift library.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp