├── .github └── workflows │ ├── cd.yml │ ├── ci.yml │ └── pr.yml ├── .vscode └── settings.json ├── Dockerfile ├── LICENSE ├── Makefile └── README.md /.github/workflows/cd.yml: -------------------------------------------------------------------------------- 1 | name: CD 2 | on: 3 | push: 4 | tags: 5 | - '*' 6 | jobs: 7 | build: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout 11 | uses: actions/checkout@v2 12 | 13 | - name: Get tag version 14 | id: get_version 15 | run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//} 16 | 17 | - name: Build Docker image 18 | run: docker build -t gameroasters/flatbuffers-unity:${{ steps.get_version.outputs.version }} --build-arg FLATBUFFER_TAG=${{ steps.get_version.outputs.version }} -f Dockerfile . 19 | 20 | - name: Extract .net DLL 21 | run: make extract-dll 22 | 23 | - uses: actions/upload-artifact@v1 24 | with: 25 | name: FlatBuffers.dll 26 | path: ./FlatBuffers.dll 27 | 28 | - name: Login to Docker Hub 29 | run: | 30 | docker login \ 31 | -u ${{ secrets.DOCKER_USERNAME }} \ 32 | -p ${{ secrets.DOCKER_PASSWORD }} 33 | 34 | - name: Publish Docker image 35 | run: docker push gameroasters/flatbuffers-unity:${{ steps.get_version.outputs.version }} 36 | 37 | - name: Release 38 | uses: softprops/action-gh-release@v1 39 | with: 40 | prerelease: ${{ contains(github.ref, '-') }} 41 | files: | 42 | ./FlatBuffers.dll 43 | env: 44 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | schedule: 4 | - cron: '0 1 * * *' # run at 2 AM UTC 5 | push: 6 | branches: [ '*' ] 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout 12 | uses: actions/checkout@v2 13 | 14 | - name: Login to Docker Hub 15 | run: | 16 | docker login \ 17 | -u ${{ secrets.DOCKER_USERNAME }} \ 18 | -p ${{ secrets.DOCKER_PASSWORD }} 19 | 20 | - name: Build Docker image 21 | run: make docker-build 22 | 23 | - name: Extract .net DLL 24 | run: make extract-dll 25 | 26 | - uses: actions/upload-artifact@v1 27 | with: 28 | name: FlatBuffers.dll 29 | path: ./FlatBuffers.dll 30 | 31 | - name: Publish Docker image 32 | run: docker push gameroasters/flatbuffers-unity:latest -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | name: PR 2 | on: 3 | pull_request: 4 | branches: [ main ] 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - name: Checkout 10 | uses: actions/checkout@v2 11 | 12 | - name: Build Docker image 13 | run: make docker-build 14 | 15 | - name: Extract .net DLL 16 | run: make extract-dll 17 | 18 | - uses: actions/upload-artifact@v1 19 | with: 20 | name: FlatBuffers.dll 21 | path: ./FlatBuffers.dll -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true 3 | } -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM mcr.microsoft.com/dotnet/sdk:5.0-focal 2 | ARG FLATBUFFER_TAG=v1.12.0 3 | LABEL maintainer="extrawurst" 4 | ENV DEBIAN_FRONTEND=noninteractive 5 | RUN apt-get update && \ 6 | apt-get install -y \ 7 | g++ git cmake make 8 | RUN echo "repo tag: $FLATBUFFER_TAG" 9 | RUN git clone --branch ${FLATBUFFER_TAG} --depth 1 https://github.com/google/flatbuffers.git 10 | # build flatc bin 11 | RUN cd flatbuffers && cmake -G "Unix Makefiles" && make 12 | RUN cp flatbuffers/flatc /usr/local/bin 13 | # build .net DLL 14 | RUN dotnet --version 15 | RUN dotnet build -m:1 -o ./flatbuffers/net/FlatBuffers/bin/Debug/ "flatbuffers/net/FlatBuffers/FlatBuffers.csproj" 16 | RUN dotnet build -m:1 -c Release -o ./flatbuffers/net/FlatBuffers/bin/Release/ "flatbuffers/net/FlatBuffers/FlatBuffers.csproj" -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Gameroasters GmbH 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CONTAINER=gameroasters/flatbuffers-unity 2 | FLATBUFFER_TAG=master 3 | 4 | docker-build: 5 | docker build -t ${CONTAINER}:latest --build-arg FLATBUFFER_TAG=${FLATBUFFER_TAG} -f Dockerfile . 6 | 7 | extract-dll: 8 | docker run -v $(shell pwd):/dotnet ${CONTAINER}:latest /bin/bash -c "\ 9 | cp /flatbuffers/net/FlatBuffers/bin/Release/FlatBuffers.dll /dotnet && \ 10 | cp /flatbuffers/net/FlatBuffers/bin/Debug/FlatBuffers.dll /dotnet/Flatbuffers.Debug.dll" 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # flatbuffers-unity 2 | 3 | convenient cross platform way to use flatbuffers for unity: 4 | 5 | 1. build flatbuffers .net DLL compatible with Unity 6 | 2. easy flatc schema code generation using docker container 7 | 8 | based on [dotnet docker image](https://hub.docker.com/_/microsoft-dotnet-sdk/) 9 | 10 | Uses [latest master commit](https://github.com/google/flatbuffers) of flatbuffers 11 | 12 | # Usage 13 | 14 | 1. create your schema fbs (`schema.fbs`) 15 | 2. use flatc to generate your code (flatc bin in docker image) 16 | 3. grab .net DLL for unity from [releases](https://github.com/gameroasters/flatbuffers-unity-docker/releases) 17 | 4. done 18 | 19 | ## example for using flatc 20 | 21 | Use: 22 | 23 | ```sh 24 | docker run -it -v $(pwd):/fb gameroasters/flatbuffers-unity:latest /bin/bash -c "cd /fb && \ 25 | flatc -n --gen-onefile schema.fbs && \ 26 | flatc -r --gen-onefile schema.fbs" 27 | mv schema_generated.rs schema.rs 28 | ``` 29 | 30 | this will generate a `schema.cs` and `schema.rs` with your `schema.fbs` schema type serialiation in rust and csharp. 31 | 32 | ## extract .dll for unity 33 | 34 | use: 35 | 36 | `make extract-dll` 37 | 38 | _or_ 39 | 40 | ```sh 41 | docker run -v $(pwd):/dotnet gameroasters/flatbuffers-unity:latest /bin/bash -c "\ 42 | cp /flatbuffers/net/FlatBuffers/bin/Release/FlatBuffers.dll /dotnet && \ 43 | cp /flatbuffers/net/FlatBuffers/bin/Debug/FlatBuffers.dll /dotnet/Flatbuffers.Debug.dll" 44 | ``` 45 | 46 | this extracts the `Flatbuffers.dll` 47 | --------------------------------------------------------------------------------