High level c# Networking for Godot based on popular open source Unity networking solutions Mirror and Mirage
Video Demo of example project: https://youtu.be/Ty55PZWtsJI
Documentation for the unity version of Mirage can be found at https://miragenet.github.io/Mirage/. Most of the same concepts will apply to the Godot version.
git clone [email protected]:James-Frowen/Mirage.Godot.git
src/Mirage.Godot/Scripts
into your godot project
.csproj
add reference to:
Mirage.Logging.csproj
Mirage.SocketLayer.csproj
dotnet build Mirage.CodeGen.csproj -c Release
[-o|--output <OUTPUT_DIRECTORY>]
to make the path easier to find<Project Sdk="Godot.NET.Sdk/4.1.1">
...
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="path/to/Mirage.CodeGen.exe $(TargetPath) -force" />
<Error Condition="$(ExitCode) == 1" />
</Target>
<Target Name="PrePublish" BeforeTargets="Publish">
<Exec Command="path/to/Mirage.CodeGen.exe $(PublishDir)$(TargetFileName) $(TargetDir) -force" />
<Error Condition="$(ExitCode) == 1" />
</Target>
</Project>
Mirage.CodeGen.csproj
currently uses reference to Mirage.Godot.csproj
to find Mirage types, but when running will use the types inside the target csproj.
Commands to run steps above (replace path/to/project
with your project)
git clone [email protected]:James-Frowen/Mirage.Godot.git
cd Mirage.Godot
cp src/Mirage.Godot/Scripts "path/to/project/Mirage.Godot"
dotnet build src/Mirage.Core/Mirage.CodeGen/Mirage.CodeGen.csproj -o ./CodeGen
and then add PostBuild
target manually with path to CodeGen/CodeGen.exe
note: you may want to exclude the src/Mirage.Godot/Scripts/Example1
folder when building or it will end up in the Mirage.Godot dll
Mirage.Godot uses Mono.Cecil to modify the c# source code after it is compiled, this allows for features to have high performance and easy to use.
To Setup add this code to the default csproj for the godot project
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="path/to/Mirage.CodeGen.exe $(TargetPath) -force" />
<Error Condition="$(ExitCode) == 1" />
</Target>
<Target Name="PrePublish" BeforeTargets="Publish">
<Exec Command="path/to/Mirage.CodeGen.exe $(PublishDir)$(TargetFileName) $(TargetDir) -force" />
<Error Condition="$(ExitCode) == 1" />
</Target>
and modify the Path/To/Mirage.CodeGen.exe
path to where you built the Mirage.CodeGen.exe
file.
Note, both targets are required:
TargetPath
works best in editor to ensure code gen changes are applied before runningPublishDir
is needed because TargetPath
is not the path copied when exporting the buildThe example use symlinks to include the Mirage.Godot scripts in the 2nd project.
To clone this repo with those symlinks run as administrator:
git clone -c core.symlinks=true [email protected]:James-Frowen/Mirage.Godot.git
If downloading without symlinks (like from zip file) then you will need to manually copy (not move) the files from src/Mirage.Godot/Scripts
to src/Mirage.Godot.Example1/Mirage.Godot
when developing the code gen locally you might want to add this step to the start of PostBuild targets so that it will rebuild the codegen project before running it
<Exec Command="dotnet build $(ProjectDir)/../Mirage.Core/Mirage.CodeGen/Mirage.CodeGen.csproj -c Release" />