Ship CultMath 0.2.0 to Unity with a UnityEngine conversion bridge
- Bump GameCult.Math and org.gamecult.cultmath to 0.2.0; the CultCache Unity tools package now depends on cultmath 0.2.0. - Rebuild the tracked netstandard2.1 CultMath.dll/pdb with the builder's deterministic command; build-unity-package.ps1 verifies it byte-for-byte. - Add Runtime/UnityBridge (CultMath.UnityBridge asmdef) with ToCultMath / ToUnity / ToColor extension methods for Vector2/3/4, Vector2Int/3Int, Quaternion and Color. C# only admits conversion operators on the source or target type, and the core DLL stays engine-free. - The builder admits exactly that one bridge assembly: it must reference UnityEngine and CultMath.dll, and no core source may be compiled in the package. - Sync the Unity copy of CultMath.hlsl and the third-party notice. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
d514efebba
commit
23cc86c4e9
15 changed files with 179 additions and 29 deletions
|
|
@ -52,6 +52,10 @@ $requiredTemplateFiles = @(
|
|||
"Runtime\Plugins\CultMath.dll.meta",
|
||||
"Runtime\Plugins\CultMath.pdb",
|
||||
"Runtime\Plugins\CultMath.pdb.meta",
|
||||
"Runtime\UnityBridge\CultMath.UnityBridge.asmdef",
|
||||
"Runtime\UnityBridge\CultMath.UnityBridge.asmdef.meta",
|
||||
"Runtime\UnityBridge\UnityConversions.cs",
|
||||
"Runtime\UnityBridge\UnityConversions.cs.meta",
|
||||
"Shaders\CultMath.hlsl",
|
||||
"Shaders\CultMath.hlsl.meta"
|
||||
)
|
||||
|
|
@ -62,7 +66,7 @@ foreach ($relativePath in $requiredTemplateFiles) {
|
|||
}
|
||||
|
||||
$unityAssetFiles = @(Get-ChildItem -LiteralPath $templateRoot -Recurse -File | Where-Object {
|
||||
$_.Extension -in @(".asmdef", ".dll", ".pdb", ".hlsl")
|
||||
$_.Extension -in @(".asmdef", ".cs", ".dll", ".pdb", ".hlsl")
|
||||
})
|
||||
$missingAssetMetas = @($unityAssetFiles | Where-Object { -not (Test-Path -LiteralPath ($_.FullName + ".meta")) })
|
||||
$missingDirectoryMetas = @(Get-ChildItem -LiteralPath $templateRoot -Recurse -Directory | Where-Object {
|
||||
|
|
@ -78,9 +82,18 @@ $pluginMeta = Get-Content -LiteralPath ($trackedAssembly + ".meta") -Raw
|
|||
if ($pluginMeta -notmatch '(?m)^\s*isExplicitlyReferenced:\s*0\s*$') {
|
||||
throw "CultMath.dll must be auto-referenced; explicit-only plugins do not reach dependent Unity asmdefs"
|
||||
}
|
||||
$facadeDefinitions = @(Get-ChildItem -LiteralPath $templateRoot -Recurse -File -Filter "*.asmdef")
|
||||
if ($facadeDefinitions.Count -ne 0) {
|
||||
throw "CultMath's precompiled DLL is the Unity assembly authority; empty asmdef facades are forbidden"
|
||||
# The precompiled DLL is the only authority for CultMath's numeric types. The one
|
||||
# compiled assembly allowed beside it is the UnityEngine conversion bridge, which
|
||||
# references that DLL and must not re-declare core sources.
|
||||
$bridgeRoot = Join-Path $templateRoot "Runtime\UnityBridge"
|
||||
$bridgeDefinition = Join-Path $bridgeRoot "CultMath.UnityBridge.asmdef"
|
||||
$definitions = @(Get-ChildItem -LiteralPath $templateRoot -Recurse -File -Filter "*.asmdef")
|
||||
if ($definitions.Count -ne 1 -or $definitions[0].FullName -ne $bridgeDefinition) {
|
||||
throw "CultMath's Unity package may define only the Runtime\UnityBridge assembly; found: $($definitions.FullName -join ', ')"
|
||||
}
|
||||
$bridge = Get-Content -LiteralPath $bridgeDefinition -Raw | ConvertFrom-Json
|
||||
if ($bridge.noEngineReferences -or -not $bridge.overrideReferences -or @($bridge.precompiledReferences) -notcontains "CultMath.dll") {
|
||||
throw "CultMath.UnityBridge must reference UnityEngine and the precompiled CultMath.dll"
|
||||
}
|
||||
$expectedFileVersion = "$($manifest.version).0"
|
||||
$trackedFileVersion = [Diagnostics.FileVersionInfo]::GetVersionInfo($trackedAssembly).FileVersion
|
||||
|
|
@ -97,23 +110,29 @@ foreach ($pair in @(@($freshAssembly, $trackedAssembly), @($freshSymbols, $track
|
|||
}
|
||||
}
|
||||
|
||||
$coreSourceNames = @(Get-ChildItem -LiteralPath (Join-Path $repoRoot "src\CultMath") -File -Filter "*.cs" | ForEach-Object Name)
|
||||
$trackedSourceFiles = @(Get-ChildItem -LiteralPath $templateRoot -Recurse -File -Filter "*.cs")
|
||||
if ($trackedSourceFiles.Count -ne 0) {
|
||||
throw "CultMath Unity package must not compile repository C# sources: $($trackedSourceFiles.FullName -join ', ')"
|
||||
$strayOrCoreSources = @($trackedSourceFiles | Where-Object {
|
||||
$_.DirectoryName -ne $bridgeRoot -or $coreSourceNames -contains $_.Name
|
||||
})
|
||||
if ($trackedSourceFiles.Count -eq 0 -or $strayOrCoreSources.Count -ne 0) {
|
||||
throw "CultMath Unity package may compile only bridge sources under Runtime\UnityBridge, never core sources: $($strayOrCoreSources.FullName -join ', ')"
|
||||
}
|
||||
|
||||
New-Item -ItemType Directory -Force -Path $outputRoot | Out-Null
|
||||
Copy-Item -Path (Join-Path $templateRoot "*") -Destination $outputRoot -Recurse -Force
|
||||
|
||||
$stagedAssemblies = @(Get-ChildItem -LiteralPath (Join-Path $outputRoot "Runtime\Plugins") -Filter "*.dll")
|
||||
$stagedBridgeRoot = Join-Path $outputRoot "Runtime\UnityBridge"
|
||||
$stagedSources = @(Get-ChildItem -LiteralPath $outputRoot -Recurse -File -Filter "*.cs")
|
||||
$stagedFacades = @(Get-ChildItem -LiteralPath $outputRoot -Recurse -File -Filter "*.asmdef")
|
||||
if ($stagedAssemblies.Count -ne 1 -or $stagedAssemblies[0].Name -ne "CultMath.dll" -or $stagedSources.Count -ne 0 -or $stagedFacades.Count -ne 0) {
|
||||
throw "CultMath package must contain one owned auto-referenced DLL, no C# source files, and no asmdef facade"
|
||||
$stagedDefinitions = @(Get-ChildItem -LiteralPath $outputRoot -Recurse -File -Filter "*.asmdef")
|
||||
$stagedStraySources = @($stagedSources | Where-Object { $_.DirectoryName -ne $stagedBridgeRoot })
|
||||
if ($stagedAssemblies.Count -ne 1 -or $stagedAssemblies[0].Name -ne "CultMath.dll" -or $stagedStraySources.Count -ne 0 -or $stagedDefinitions.Count -ne 1) {
|
||||
throw "CultMath package must contain one owned auto-referenced DLL and only the UnityBridge assembly as source"
|
||||
}
|
||||
|
||||
Write-Host "CultMath Unity package: $outputRoot"
|
||||
Write-Host "Package: $($manifest.name)@$($manifest.version)"
|
||||
Write-Host "Managed assemblies: $($stagedAssemblies.Count)"
|
||||
Write-Host "C# source files: $($stagedSources.Count)"
|
||||
Write-Host "Asmdef facades: $($stagedFacades.Count)"
|
||||
Write-Host "Bridge C# source files: $($stagedSources.Count)"
|
||||
Write-Host "Asmdef definitions: $($stagedDefinitions.Count)"
|
||||
|
|
|
|||
Loading…
Reference in a new issue