Is a small source generator which generates methods for serializing and deserializing structs.
[TinyIni.IniSerializable]
public struct Config
{
public int Version = 0;
public Display Display = new()
{
Height = 1080,
Width = 1920,
VSync = VSync.Enabled
};
public Graphics Graphics = new()
{
MSAA = 16,
Advanced = new AdvancedGraphics
{
GraphicsAPI = GraphicsAPI.Vulkan
}
};
public Input InputKeyboard = new()
{
JumpKey = 32
};
public Input InputGamepad = new()
{
JumpKey = 16
};
public Config() {}
}[omitted for brevity]
public struct Graphics
{
public byte MSAA;
public AdvancedGraphics Advanced;
}
public struct AdvancedGraphics
{
public GraphicsAPI GraphicsAPI;
}
public struct Display
{
public int Width;
public int Height;
public VSync VSync;
}
public struct Input
{
public byte JumpKey;
}
public enum VSync
{
Enabled,
Disabled,
Adaptive
}
public enum GraphicsAPI
{
Vulkan,
DirectX12
}TinyIni.Save("config.ini", in config);config.ini
Version=0
[Display]
Width=1920
Height=1080
VSync=Enabled
[Graphics]
MSAA=16
[Graphics/Advanced]
GraphicsAPI=Vulkan
[InputKeyboard]
JumpKey=32
[InputGamepad]
JumpKey=16TinyIni.Load("config.ini", ref config);Clone this repository into your solution directory.
git clone https://github.com/AQtun81/TinyIni
<ItemGroup>
<ProjectReference Include="..\TinyIni\TinyIni.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"/>
</ItemGroup>You won't see IntelliSense for any generated code until the project is built at least once.
[TinyIni.IniSerializable]
public struct Config
{
// ...// this will additionally create a new file if one isn't already present
TinyIni.Load($"config.ini", ref config);
// this will generate new fields and remove obsolete ones
TinyIni.Save($"config.ini", in config);You'll have to do some additional steps in order to use Tiny Ini with Unity.
git clone https://github.com/AQtun81/TinyIni- Inside of
TinyIni.csprojdowngradeMicrosoft.CodeAnalysis.CommonandMicrosoft.CodeAnalysis.CSharpto4.3.0-3.final - Uncomment
//#define TINY_INI_COMPATIBILITYinside ofProgram.csto enable support for older versions of C# - Build the project for release
dotnet build -c release - Copy the dll file to somewhere inside of your
Assetsfolder - Click on the .dll file to open the Plugin Inspector window
- Uncheck
Any Platform,EditorandStandalonecheckmarks, under Asset Labels create and assign a new label calledRoslynAnalyzer
Refer to Unity's documentation for more details.
Godot 4 C# projects use MSBuild so following the default instructions for C# projects will work.
Versions prior to that are not supported.