Skip to main content

Posts

FlatBuffers for Unity, part 3 (examples)

This is a third and hoping last part of cycle about using flatbuffers in Unity. Here we take a look at usage example. There is an example of PingPong game. It is not about fascinating gameplay it is just demonstration of flatbuffers usage. First of all, there are three .fbs-files (BallCoordinates, MoveDirection and PlayerAction) that we need to compile into c# and python (.cs and .py respectively). Do not forget that you can choose a flatc-compiler (although there is default one for each of platforms: Windows, MacOS, Linux). After compiling you have to move python files into server-part folder. (Scripts->Server->FbsCompilled). It is time to prepare server: Install python and pip   Optionally you can create python environment: python -m venv /path/to/new/virtual/environment Install requirements from file "requirements.txt" (with the help of pip): pip install -r requirements.txt Run flask server with the help of script run_server.bat. There should be output:

FlatBuffers for Unity, part 2

In previous part we have considered different ways to serialize and deserialize data. In this chapter I tell about tool that facilitates using of flatbuffers in Unity. What should it do? I have highlighted three main points. First of all it should enable to create .fbs messages from Unity Editor. Just as right-click action. Next, it should allow to compile .fbs messages to C# classes (and some other languages). And finally, it should be flexible and allow user to tune tool for his needs. Creating .fbs messages This point is quite easy: we need to add a new menu item "Create .fbs" to Assets menu. You can do it easily by adding a MenuItem attribute to your method. Additionally you can add a validation method that enables/disables menu item. I used this opportunity to check that there is a selected folder (when we need to create a new file). More information you can find here . [MenuItem("Assets/Create/FlatBuffers message")] [MenuItem("Assets/UnityFbs/C

FlatBuffers for Unity, part 1 (overview)

Seems every game development faces a problem: how to serialize and deserialize data? This question occurs in two main scenarios: saving/loading and network communication (how to send data to server or computer). In both cases you want to save some game data (items, players or perhaps game state or action) and restore this data later (might be on other server). Most common solutions What approaches does Unity suggest for that? I have found these variants: PlayerPrefs ( link ); String serializers ( JSON or XML ); Binary serilization; Let me take short overview of each of them. PlayerPrefs  It is one of the most simple way to store data in Unity. It uses built-in system PlayerPrefs that allows to save data in system key-value storage. It has only three functions to store base types of data (int, float and string). PlayerPrefs is not about performance or data transferring. Pros and cons: + Simple to use + Built-in - Does not support data transferring - Does not support co

About me and this blog

Hello everyone! I have played computer games a lot previously (and sometimes continue playing, especially with friends) and now it is time for game creation. By professional skills I am a programmer so almost all my posts would be about scripting and coding. In this blog I will share with my projects, thoughts or some tricks. If you find something interesting for you I will be happy. Of course do not hesitate to ask questions, start a conversation or just give me advice.

Unity: procedure-generated levels

To begin with, let me give some explanation what was the original goal. As a weekend project I was writing a 2d game. And there was a need for a dungeon map: number of rooms somehow connected with roads. I think that it should be auto-generator, that will create various levels by input parameters (like number of rooms). At the very beginning I decided to divide the functionality into separate classes: one for generating level and another for rendering. Generator I have decided that generator has take maze X-length and  number of rooms to generate as input parameters. Additionally it has to try keep the Y-limit, but it is not so strictly as X-limit.  Well, generator will take these parameters in constructor: What about internals? I decided to use a container that can hold existing nodes and generate new one. I named it MapGrid. Inside it has a grid of nodes (List of List). First List - list of levels. It contains list of Nodes that have the same X-coordinate. On adding new N