Skip to content

Commit e5ca519

Browse files
authored
Merge pull request #241 from Cysharp/hadashiA/nuget-for-unity
Migrate Unity support to NuGetUnity
2 parents 285ac2a + 035bd1e commit e5ca519

248 files changed

Lines changed: 8527 additions & 13488 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-debug.yml

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,45 +21,31 @@ jobs:
2121

2222
build-unity:
2323
if: "((github.event_name == 'push' && github.repository_owner == 'Cysharp') || startsWith(github.event.pull_request.head.label, 'Cysharp:'))"
24-
strategy:
25-
matrix:
26-
unity: ["2021.3.11f1"]
24+
# strategy:
25+
# matrix:
26+
# unity: ["2021.3.11f1"]
2727
runs-on: ubuntu-latest
2828
timeout-minutes: 15
2929
steps:
3030
- uses: actions/checkout@v3
3131
# Execute scripts: RuntimeUnitTestToolkit
3232
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod UnitTestBuilder.BuildUnitTest /headless /ScriptBackend mono /BuildTarget StandaloneLinux64
33-
- name: Build UnitTest(Linux64, mono)
34-
uses: Cysharp/Actions/.github/actions/unity-builder@main
35-
env:
36-
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
37-
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
38-
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
39-
with:
40-
projectPath: src/MemoryPack.Unity
41-
unityVersion: ${{ matrix.unity }}
42-
targetPlatform: StandaloneLinux64
43-
buildMethod: UnitTestBuilder.BuildUnitTest
44-
customParameters: /headless /ScriptBackend mono
33+
# - name: Build UnitTest(Linux64, mono)
34+
# uses: Cysharp/Actions/.github/actions/unity-builder@main
35+
# env:
36+
# UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
37+
# UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
38+
# UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
39+
# with:
40+
# projectPath: src/MemoryPack.Unity
41+
# unityVersion: ${{ matrix.unity }}
42+
# targetPlatform: StandaloneLinux64
43+
# buildMethod: UnitTestBuilder.BuildUnitTest
44+
# customParameters: /headless /ScriptBackend mono
4545
# Unity 2021.2 and above changed Headless mode. It seems require Dedicated Server currently and investigating alternative api to enable batch mode.
4646
# - name: Execute UnitTest
4747
# run: ./src/MemoryPack.Unity/bin/UnitTest/StandaloneLinux64_Mono2x/test -batchmode
4848

49-
# Execute scripts: Export Package
50-
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
51-
- name: Build Unity (.unitypacakge)
52-
uses: Cysharp/Actions/.github/actions/unity-builder@main
53-
env:
54-
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
55-
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
56-
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
57-
with:
58-
projectPath: src/MemoryPack.Unity
59-
unityVersion: ${{ matrix.unity }}
60-
targetPlatform: StandaloneLinux64
61-
buildMethod: PackageExporter.Export
62-
6349
- uses: Cysharp/Actions/.github/actions/check-metas@main # check meta files
6450
with:
6551
directory: src/MemoryPack.Unity

.github/workflows/build-release.yml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,17 @@ jobs:
4343

4444
build-unity:
4545
needs: [update-packagejson]
46-
strategy:
47-
matrix:
48-
unity: ["2021.3.11f1"]
4946
runs-on: ubuntu-latest
5047
timeout-minutes: 15
5148
steps:
5249
- run: echo ${{ needs.update-packagejson.outputs.sha }}
5350
- uses: actions/checkout@v3
5451
with:
5552
ref: ${{ needs.update-packagejson.outputs.sha }}
56-
# Execute scripts: Export Package
57-
# /opt/Unity/Editor/Unity -quit -batchmode -nographics -silent-crashes -logFile -projectPath . -executeMethod PackageExporter.Export
58-
- name: Build Unity (.unitypacakge)
59-
uses: Cysharp/Actions/.github/actions/unity-builder@main
60-
env:
61-
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
62-
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
63-
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
64-
with:
65-
projectPath: src/MemoryPack.Unity
66-
unityVersion: ${{ matrix.unity }}
67-
targetPlatform: StandaloneLinux64
68-
buildMethod: PackageExporter.Export
69-
7053
# check meta files
7154
- uses: Cysharp/Actions/.github/actions/check-metas@main
7255
with:
7356
directory: src/MemoryPack.Unity
74-
# Store artifacts.
75-
- uses: actions/upload-artifact@v3
76-
with:
77-
name: MemoryPack.${{ inputs.tag }}.unitypackage
78-
path: ./src/MemoryPack.Unity/MemoryPack.${{ inputs.tag }}.unitypackage
79-
if-no-files-found: error
8057

8158
# release
8259
create-release:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,5 @@ src/MemoryPack.Unity/Logs/*
129129
src/MemoryPack.Unity/*.csproj
130130
src/MemoryPack.Unity/*.sln
131131
src/MemoryPack.Unity/MemoryPack.*.unitypackage
132+
133+
.DS_Store

MemoryPack.sln

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SandboxNet6", "sandbox\Sand
3131
EndProject
3232
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{C56A9A52-EE3A-44A5-A8EA-AE36C79FFB6C}"
3333
EndProject
34-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostBuildUtility", "tools\PostBuildUtility\PostBuildUtility.csproj", "{06384E50-13CE-4AA2-90B3-5EC116B06D01}"
35-
EndProject
36-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Tests.Roslyn3", "tests\MemoryPack.Tests.Roslyn3\MemoryPack.Tests.Roslyn3.csproj", "{E2C01D05-E7F1-4151-B536-90B138AF18EF}"
37-
EndProject
38-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MemoryPack.Generator.Roslyn3", "src\MemoryPack.Generator.Roslyn3\MemoryPack.Generator.Roslyn3.csproj", "{0F57F162-9C68-4E0F-B89B-2EED31B69F38}"
39-
EndProject
4034
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ClassLibrary", "sandbox\ClassLibrary\ClassLibrary.csproj", "{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}"
4135
EndProject
4236
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NativeAot", "sandbox\NativeAot\NativeAot.csproj", "{6E18AECF-34B2-48F9-9694-54150FB156EB}"
@@ -112,24 +106,6 @@ Global
112106
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.Release|Any CPU.Build.0 = Release|Any CPU
113107
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.WinBenchmark|Any CPU.ActiveCfg = Release|Any CPU
114108
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2}.WinBenchmark|Any CPU.Build.0 = Release|Any CPU
115-
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
116-
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Debug|Any CPU.Build.0 = Debug|Any CPU
117-
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Release|Any CPU.ActiveCfg = Release|Any CPU
118-
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.Release|Any CPU.Build.0 = Release|Any CPU
119-
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.WinBenchmark|Any CPU.ActiveCfg = WinBenchmark|Any CPU
120-
{06384E50-13CE-4AA2-90B3-5EC116B06D01}.WinBenchmark|Any CPU.Build.0 = WinBenchmark|Any CPU
121-
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
122-
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
123-
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
124-
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.Release|Any CPU.Build.0 = Release|Any CPU
125-
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU
126-
{E2C01D05-E7F1-4151-B536-90B138AF18EF}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU
127-
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
128-
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Debug|Any CPU.Build.0 = Debug|Any CPU
129-
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Release|Any CPU.ActiveCfg = Release|Any CPU
130-
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.Release|Any CPU.Build.0 = Release|Any CPU
131-
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.WinBenchmark|Any CPU.ActiveCfg = Debug|Any CPU
132-
{0F57F162-9C68-4E0F-B89B-2EED31B69F38}.WinBenchmark|Any CPU.Build.0 = Debug|Any CPU
133109
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
134110
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
135111
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -169,9 +145,6 @@ Global
169145
{F9D66CB1-8D28-426B-BB12-C9F5D30EC6A0} = {796FB992-A35C-405B-82A7-4C90C5673174}
170146
{64B20612-4990-40C7-8191-E2A033CD1EF5} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF}
171147
{87C0CEAA-E511-46AA-93AB-AF742A1F8EE2} = {796FB992-A35C-405B-82A7-4C90C5673174}
172-
{06384E50-13CE-4AA2-90B3-5EC116B06D01} = {C56A9A52-EE3A-44A5-A8EA-AE36C79FFB6C}
173-
{E2C01D05-E7F1-4151-B536-90B138AF18EF} = {204004F9-9B91-4DD1-812C-80D629169ED5}
174-
{0F57F162-9C68-4E0F-B89B-2EED31B69F38} = {81B295E0-EEDE-4D5B-B4AC-1202D5E6B3CF}
175148
{0ADCE3AF-C900-4FCB-938B-654211EDD6BE} = {796FB992-A35C-405B-82A7-4C90C5673174}
176149
{6E18AECF-34B2-48F9-9694-54150FB156EB} = {796FB992-A35C-405B-82A7-4C90C5673174}
177150
{5612B811-586A-4EB3-9AE7-60CAD4969A1B} = {796FB992-A35C-405B-82A7-4C90C5673174}

README.md

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ public abstract class MemoryPackCustomFormatterAttribute<T> : Attribute
705705
}
706706
```
707707

708-
MemorySharp provides the following formatting attributes: `Utf8StringFormatterAttribute`, `Utf16StringFormatterAttribute`, `InternStringFormatterAttribute`, `OrdinalIgnoreCaseStringDictionaryFormatterAttribute<TValue>`, `BitPackFormatterAttribute`, `BrotliFormatter`, `BrotliStringFormatter`, `BrotliFormatter<T>`, `MemoryPoolFormatter<T>`, `ReadOnlyMemoryPoolFormatter<T>`.
708+
MemoryPack provides the following formatting attributes: `Utf8StringFormatterAttribute`, `Utf16StringFormatterAttribute`, `InternStringFormatterAttribute`, `OrdinalIgnoreCaseStringDictionaryFormatterAttribute<TValue>`, `BitPackFormatterAttribute`, `BrotliFormatter`, `BrotliStringFormatter`, `BrotliFormatter<T>`, `MemoryPoolFormatter<T>`, `ReadOnlyMemoryPoolFormatter<T>`.
709709

710710
```csharp
711711
[MemoryPackable]
@@ -1311,36 +1311,43 @@ RPC
13111311

13121312
Unity
13131313
---
1314-
Install via UPM git URL package or asset package (MemoryPack.*.*.*.unitypackage) available in [MemoryPack/releases](https://github.com/Cysharp/MemoryPack/releases) page.
13151314

1316-
* https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack
1315+
Minimum supported Unity version is `2022.3.12f1`.
13171316

1318-
If you want to set a target version, MemoryPack uses the `*.*.*` release tag, so you can specify a version like #1.8.0. For example `https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/Plugins/MemoryPack#1.8.0`.
1317+
The `MemoryPack` core package is provided by nuget. It is also available in Unity. If you want to get Unity built-in type support, we additionally provide MemoryPack.Unity extension.
13191318

1320-
Minimum supported Unity version is `2021.3`. The dependency managed DLL `System.Runtime.CompilerServices.Unsafe/6.0.0` is included with unitypackage. For git references, you will need to add them in another way as they are not included to avoid unnecessary dependencies; either extract the dll from unitypackage or download it from the [NuGet page](https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/6.0.0).
1319+
1. Install `MemoryPack` from NuGet using [NuGetForUnity](https://github.com/GlitchEnzo/NuGetForUnity)
13211320

1322-
As with the .NET version, the code is generated by a code generator (`MemoryPack.Generator.Roslyn3.dll`). Reflection-free implementation also provides the best performance in IL2CPP.
1321+
* Open Window from NuGet -> Manage NuGet Packages, Search "MemoryPack" and Press Install.
1322+
![screenshot](https://github.com/Cysharp/MemoryPack/assets/727159/599ff1ed-6cca-4724-be67-3edddb5e62ee)
1323+
1324+
* If you encount version conflicts error, please disable version validation in Player Settings(Edit -> Project Settings -> Player -> Scroll down and expand "Other Settings" than uncheck "Assembly Version Validation" under the "Configuration" section).
1325+
1326+
2. Install the `MemoryPack.Unity` package by referencing the git URL
1327+
1328+
* `https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/MemoryPack.Unity`
1329+
![screenshot](https://github.com/Cysharp/ZLogger/assets/46207/7325d266-05b4-47c9-b06a-a67a40368dd2)
1330+
![screenshot](https://github.com/Cysharp/MemoryPack/assets/727159/9a4af1df-ce07-49d7-9420-922dfb139b55)
1331+
1332+
1333+
MemoryPack uses the *.*.* release tag, so you can specify a version like #1.0.0. For example: `https://github.com/Cysharp/MemoryPack.git?path=src/MemoryPack.Unity/Assets/MemoryPack.Unity#1.0.0`
1334+
1335+
1336+
As with the .NET version, the code is generated by a code generator (`MemoryPack.Generator.dll`). Reflection-free implementation also provides the best performance in IL2CPP.
13231337

13241338
For more information on Unity and Source Generator, please refer to the [Unity documentation](https://docs.unity3d.com/Manual/roslyn-analyzers.html).
13251339

13261340
Source Generator is also used officially by Unity by [com.unity.properties](https://docs.unity3d.com/Packages/[email protected]/manual/index.html) and [com.unity.entities](https://docs.unity3d.com/Packages/[email protected]/changelog/CHANGELOG.html). In other words, it is the standard for code generation in the next generation of Unity.
13271341

1328-
Unity version does not support CustomFormatter and ImmutableCollections.
1342+
> [!WARNING]
1343+
> Unity version does not support CustomFormatter.
13291344
13301345
You can serialize all unmanaged types (such as `Vector3`, `Rect`, etc...) and some classes(`AnimationCurve`, `Gradient`, `RectOffset`). If you want to serialize other Unity-specific types, see [Serialize external types](#serialize-external-types) section.
13311346

13321347
In Unity performance, MemoryPack is x3~x10 faster than JsonUtility.
13331348

13341349
![image](https://user-images.githubusercontent.com/46207/209254561-79ec18fe-c421-4d8c-9c86-b55276dd1a45.png)
13351350

1336-
Unity version's MemoryPack does not compatible with .NET MemoryPack in NuGet so can't do creating netstandard 2.1 dll in .NET and use in Unity. If you want to share type between .NET and Unity, share source-code, for example place source code in Unity directory and .NET project reference by code link.
1337-
1338-
```xml
1339-
<ItemGroup>
1340-
<Compile Include="..\ChatApp.Unity\Assets\Scripts\ServerShared\**\*.cs" />
1341-
</ItemGroup>
1342-
```
1343-
13441351
If shared code has Unity's type(`Vector2`, etc...), MemoryPack provides `MemoryPack.UnityShims` package in NuGet.
13451352

13461353
The `MemoryPack.UnityShims` package provides shims for Unity's standard structs (`Vector2`, `Vector3`, `Vector4`, `Quaternion`, `Color`, `Bounds`, `Rect`, `Keyframe`, `WrapMode`, `Matrix4x4`, `GradientColorKey`, `GradientAlphaKey`, `GradientMode`, `Color32`, `LayerMask`, `Vector2Int`, `Vector3Int`, `RangeInt`, `RectInt`, `BoundsInt`) and some classes(`AnimationCurve`, `Gradient`, `RectOffset`).

sandbox/SandboxConsoleApp/SandboxConsoleApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<ImplicitUsings>disable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<IsPackable>false</IsPackable>
9-
<PublishAot>true</PublishAot>
9+
<!-- <PublishAot>true</PublishAot> -->
1010
</PropertyGroup>
1111

1212
<ItemGroup>

src/MemoryPack.Core/Compression/BrotliCompressor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,12 @@ public void CopyTo<TBufferWriter>(in TBufferWriter destBufferWriter)
132132
var writtenNotAdvanced = 0;
133133
foreach (var item in bufferWriter)
134134
{
135-
writtenNotAdvanced = CompressCore(ref encoder, item.Span, ref Unsafe.AsRef(destBufferWriter), initialLength: null, isFinalBlock: false);
135+
writtenNotAdvanced = CompressCore(ref encoder, item.Span, ref Unsafe.AsRef(in destBufferWriter), initialLength: null, isFinalBlock: false);
136136
}
137137

138138
// call BrotliEncoderOperation.Finish
139139
var finalBlockLength = (writtenNotAdvanced == 0) ? null : (int?)(writtenNotAdvanced + 10);
140-
CompressCore(ref encoder, ReadOnlySpan<byte>.Empty, ref Unsafe.AsRef(destBufferWriter), initialLength: finalBlockLength, isFinalBlock: true);
140+
CompressCore(ref encoder, ReadOnlySpan<byte>.Empty, ref Unsafe.AsRef(in destBufferWriter), initialLength: finalBlockLength, isFinalBlock: true);
141141
}
142142
finally
143143
{

src/MemoryPack.Core/Formatters/MemoryPackableFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public sealed class MemoryPackableFormatter<T> : MemoryPackFormatter<T>
1212
[Preserve]
1313
public override void Serialize<TBufferWriter>(ref MemoryPackWriter<TBufferWriter> writer, scoped ref T? value)
1414
{
15-
T.Serialize(ref writer, ref Unsafe.AsRef(value));
15+
T.Serialize(ref writer, ref Unsafe.AsRef(in value));
1616
}
1717

1818
[Preserve]

src/MemoryPack.Core/MemoryPack.Core.csproj

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,4 @@
6767
</Compile>
6868
</ItemGroup>
6969

70-
<!-- Copy files for Unity -->
71-
<PropertyGroup>
72-
<DestinationRoot>$(MSBuildProjectDirectory)\..\MemoryPack.Unity\Assets\Plugins\MemoryPack\Runtime\MemoryPack.Core</DestinationRoot>
73-
</PropertyGroup>
74-
<ItemGroup>
75-
<TargetFiles1 Include="$(MSBuildProjectDirectory)\**\*.cs" Exclude="**\bin\**\*.*;**\obj\**\*.*;**\CollectionsMarshalEx.cs;**\ImmutableCollectionFormatters.cs" />
76-
</ItemGroup>
77-
78-
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="$(TargetFramework) == 'net7.0'">
79-
<Copy SourceFiles="@(TargetFiles1)" DestinationFiles="$(DestinationRoot)\%(RecursiveDir)%(Filename)%(Extension)" SkipUnchangedFiles="true" />
80-
81-
<!-- After copy, replace for unity codes -->
82-
<Exec Command="dotnet run -c $(ConfigurationName) --project $(MSBuildProjectDirectory)\..\..\tools\PostBuildUtility\PostBuildUtility.csproj -- $(DestinationRoot)" />
83-
</Target>
84-
8570
</Project>

src/MemoryPack.Core/MemoryPackSerializer.NonGenerics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static unsafe void Serialize<TBufferWriter>(Type type, in TBufferWriter b
4747

4848
try
4949
{
50-
var writer = new MemoryPackWriter<TBufferWriter>(ref Unsafe.AsRef(bufferWriter), state);
50+
var writer = new MemoryPackWriter<TBufferWriter>(ref Unsafe.AsRef(in bufferWriter), state);
5151
Serialize(type, ref writer, value);
5252
}
5353
finally

0 commit comments

Comments
 (0)