|
| 1 | +# PurrNet Conversion Tool |
| 2 | + |
| 3 | +Switching networking solutions mid-project is painful. The PurrNet Conversion Tool takes care of the heavy lifting for you, converting your code, prefabs, and scenes from other networking systems to [PurrNet](https://github.com/PurrNet/PurrNet). |
| 4 | + |
| 5 | +It works through a recipe system where each source networking library has its own set of mappings and conversion logic. Right now, **FishNet** is supported out of the box, with more converters coming. |
| 6 | + |
| 7 | +## What it does |
| 8 | + |
| 9 | +The tool handles three layers of conversion: |
| 10 | + |
| 11 | +**Code** uses Roslyn to parse your C# files and apply type, namespace, method, property, and attribute mappings. It also handles trickier cases like merging FishNet's separate `OnStartServer`/`OnStartClient` into PurrNet's unified `OnSpawned(bool asServer)`. |
| 12 | + |
| 13 | +**Prefabs** finds networking components on your prefabs (like `NetworkTransform`, `NetworkAnimator`, `NetworkObject`) and swaps them out for the PurrNet equivalents, copying over relevant settings. |
| 14 | + |
| 15 | +**Scenes** does the same for scene objects, including full `NetworkManager` conversion with transport setup and tick rate transfer. |
| 16 | + |
| 17 | +Each step runs independently so you stay in control of the process. |
| 18 | + |
| 19 | +## Getting started |
| 20 | + |
| 21 | +### Install via PurrNet Package Manager |
| 22 | + |
| 23 | +The easiest way. If you already have PurrNet installed, open the **PurrNet Package Manager** in Unity and install the Conversion Tool with a single click. |
| 24 | + |
| 25 | +### Install via git URL |
| 26 | + |
| 27 | +You can also add the package through the Unity Package Manager using this git URL: |
| 28 | + |
| 29 | +``` |
| 30 | +https://github.com/PurrNet/PurrNet-Conversion-Tool.git?path=/Assets/PurrNet-Conversion |
| 31 | +``` |
| 32 | + |
| 33 | +Or add it directly to your `Packages/manifest.json`: |
| 34 | + |
| 35 | +```json |
| 36 | +"dev.purrnet.conversion": "https://github.com/PurrNet/PurrNet-Conversion-Tool.git?path=/Assets/PurrNet-Conversion" |
| 37 | +``` |
| 38 | + |
| 39 | +### Requirements |
| 40 | + |
| 41 | +You'll need [PurrNet](https://github.com/PurrNet/PurrNet) installed in your project. The source networking library you're converting from (e.g. FishNet) also needs to be present since the tool reads its components during prefab and scene conversion. |
| 42 | + |
| 43 | +## How to use it |
| 44 | + |
| 45 | +Open the tool from **Tools > PurrNet > Conversion Tool**. |
| 46 | + |
| 47 | +1. Select the networking system you're converting from in the dropdown |
| 48 | +2. Set which folders to include for scripts, prefabs, and scenes (defaults to the entire Assets folder) |
| 49 | +3. Run each conversion step in order: **Convert Code**, then **Convert Prefabs**, then **Convert Scenes** |
| 50 | + |
| 51 | +The conversion log at the bottom of the window shows you what changed. A `ConversionChangelog.txt` file is also written to your project root with timestamped details of every modification. |
| 52 | + |
| 53 | +After conversion, you can remove the old networking library from your project. |
| 54 | + |
| 55 | +## Creating your own converter |
| 56 | + |
| 57 | +The tool uses a recipe system that makes it straightforward to add support for other networking libraries. Each converter lives in its own folder and consists of three classes. |
| 58 | + |
| 59 | +### 1. Mappings |
| 60 | + |
| 61 | +Extend `NetworkSystemMappings` and define your mappings in the constructor: |
| 62 | + |
| 63 | +```csharp |
| 64 | +using PurrNet.ConversionTool; |
| 65 | + |
| 66 | +public class MySystemMappings : NetworkSystemMappings |
| 67 | +{ |
| 68 | + public MySystemMappings() |
| 69 | + { |
| 70 | + SystemName = "MyNetworkLib"; |
| 71 | + SystemIdentifiers = new List<string> { "MyNetworkLib" }; |
| 72 | + |
| 73 | + NamespaceMappings = new Dictionary<string, string> |
| 74 | + { |
| 75 | + { "MyNetworkLib", "PurrNet" } |
| 76 | + }; |
| 77 | + |
| 78 | + TypeMappings = new Dictionary<string, string> |
| 79 | + { |
| 80 | + { "NetConnection", "PlayerID" }, |
| 81 | + { "NetObject", "NetworkIdentity" } |
| 82 | + }; |
| 83 | + |
| 84 | + PropertyMappings = new Dictionary<string, string> |
| 85 | + { |
| 86 | + { "IsOwner", "isOwner" }, |
| 87 | + { "IsServer", "isServer" } |
| 88 | + }; |
| 89 | + |
| 90 | + MethodMappings = new Dictionary<string, string> |
| 91 | + { |
| 92 | + { "OnClientStart", "OnSpawned" } |
| 93 | + }; |
| 94 | + |
| 95 | + // ... and so on for MemberMappings, MethodCallMappings, |
| 96 | + // AttributeMappings, AttributeParameterMappings, etc. |
| 97 | + } |
| 98 | +} |
| 99 | +``` |
| 100 | + |
| 101 | +For cases that don't fit into simple mappings, override `SpecialCaseHandler` to do custom Roslyn syntax tree transformations. |
| 102 | + |
| 103 | +### 2. Prefab handling |
| 104 | + |
| 105 | +Extend `NetworkPrefabHandling` and override `ConvertPrefab`: |
| 106 | + |
| 107 | +```csharp |
| 108 | +using PurrNet.ConversionTool; |
| 109 | +using UnityEngine; |
| 110 | + |
| 111 | +public class MySystemPrefabHandling : NetworkPrefabHandling |
| 112 | +{ |
| 113 | + public override bool ConvertPrefab(GameObject prefab) |
| 114 | + { |
| 115 | + // Find old components, add PurrNet equivalents, copy settings |
| 116 | + // Return true if anything was changed |
| 117 | + return false; |
| 118 | + } |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +### 3. Scene handling |
| 123 | + |
| 124 | +Extend `NetworkSceneHandling` and override `ConvertSceneObject`: |
| 125 | + |
| 126 | +```csharp |
| 127 | +using PurrNet.ConversionTool; |
| 128 | +using UnityEngine; |
| 129 | + |
| 130 | +public class MySystemSceneHandling : NetworkSceneHandling |
| 131 | +{ |
| 132 | + public override bool ConvertSceneObject(GameObject sceneObject) |
| 133 | + { |
| 134 | + // Convert scene-specific objects like NetworkManager |
| 135 | + // Return true if anything was changed |
| 136 | + return false; |
| 137 | + } |
| 138 | +} |
| 139 | +``` |
| 140 | + |
| 141 | +### Assembly setup |
| 142 | + |
| 143 | +Your converter folder needs its own `.asmdef` that references `PurrNet.ConversionTool` and the source networking library. Set it to **Editor only** and add a `defineConstraints` entry so it only compiles when the source library is present. |
| 144 | + |
| 145 | +Take a look at the [FishNet converter](Assets/PurrNet-Conversion/Converters/FishNet%20Converter/) for a full working example. |
| 146 | + |
| 147 | +### Discovery |
| 148 | + |
| 149 | +The tool automatically discovers converters through reflection. As long as your three classes are in the same folder and extend the right base classes, they'll show up in the dropdown. No registration needed. |
| 150 | + |
| 151 | +## Links |
| 152 | + |
| 153 | +[PurrNet](https://github.com/PurrNet/PurrNet) | [Documentation](https://purrnet.gitbook.io/) | [Discord](https://discord.gg/purrnet) |
| 154 | + |
| 155 | +## License |
| 156 | + |
| 157 | +MIT |
0 commit comments