mirror of
https://github.com/AssetRipper/AssetRipper.git
synced 2025-12-11 20:15:29 +01:00
Add unit test for UnityEngine.UI guid
* Resolves #1787 * Resolves #1813
This commit is contained in:
parent
3ec12fad63
commit
ff1f7377be
@ -39,6 +39,9 @@ public static class ReferenceAssemblies
|
|||||||
referenceAssemblies.TryAdd(assembly, UnityEngineGUID);
|
referenceAssemblies.TryAdd(assembly, UnityEngineGUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Todo: investigate why 5.4.0a0 does not have UnityEngine
|
||||||
|
referenceAssemblies.TryAdd("UnityEngine", UnityEngineGUID);
|
||||||
|
|
||||||
return referenceAssemblies;
|
return referenceAssemblies;
|
||||||
|
|
||||||
static IReadOnlyList<string> GetMonoAssemblies(IAssemblyManager assemblyManager, AssemblyData assemblyData)
|
static IReadOnlyList<string> GetMonoAssemblies(IAssemblyManager assemblyManager, AssemblyData assemblyData)
|
||||||
|
|||||||
@ -42,7 +42,7 @@ namespace AssetRipper.Import.Structure.Platforms
|
|||||||
Backend = Assemblies.Count > 0 ? ScriptingBackend.Mono : ScriptingBackend.Unknown;
|
Backend = Assemblies.Count > 0 ? ScriptingBackend.Mono : ScriptingBackend.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<string> SelectUniquePaths(IEnumerable<string> paths)
|
private static IEnumerable<string> SelectUniquePaths(IEnumerable<string> paths)
|
||||||
{
|
{
|
||||||
return paths.Select(t => MultiFileStream.GetFilePath(t)).Distinct();
|
return paths.Select(t => MultiFileStream.GetFilePath(t)).Distinct();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,16 @@ public static class UnityVersionExtensions
|
|||||||
{
|
{
|
||||||
extension(UnityVersion)
|
extension(UnityVersion)
|
||||||
{
|
{
|
||||||
|
public static UnityVersion V_5_3 => new UnityVersion(5, 3);
|
||||||
|
public static UnityVersion V_5_4 => new UnityVersion(5, 4);
|
||||||
|
public static UnityVersion V_5_5 => new UnityVersion(5, 5);
|
||||||
|
public static UnityVersion V_5_6 => new UnityVersion(5, 6);
|
||||||
|
public static UnityVersion V_2017 => new UnityVersion(2017);
|
||||||
|
public static UnityVersion V_2018 => new UnityVersion(2018);
|
||||||
|
public static UnityVersion V_2019 => new UnityVersion(2019);
|
||||||
|
public static UnityVersion V_2020 => new UnityVersion(2020);
|
||||||
|
public static UnityVersion V_2021 => new UnityVersion(2021);
|
||||||
public static UnityVersion V_2022 => new UnityVersion(2022);
|
public static UnityVersion V_2022 => new UnityVersion(2022);
|
||||||
|
public static UnityVersion V_2023 => new UnityVersion(2023);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\AssetRipper.Export.PrimaryContent\AssetRipper.Export.PrimaryContent.csproj" />
|
<ProjectReference Include="..\AssetRipper.Export.PrimaryContent\AssetRipper.Export.PrimaryContent.csproj" />
|
||||||
<ProjectReference Include="..\AssetRipper.Export.UnityProjects\AssetRipper.Export.UnityProjects.csproj" />
|
<ProjectReference Include="..\AssetRipper.Export.UnityProjects\AssetRipper.Export.UnityProjects.csproj" />
|
||||||
|
<ProjectReference Include="..\UnityEngine\UnityEngine.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using AssetRipper.Assets.Bundles;
|
using AsmResolver.DotNet;
|
||||||
|
using AssetRipper.Assets.Bundles;
|
||||||
using AssetRipper.Assets.Collections;
|
using AssetRipper.Assets.Collections;
|
||||||
using AssetRipper.Export.UnityProjects;
|
using AssetRipper.Export.UnityProjects;
|
||||||
using AssetRipper.Import.Structure.Assembly.Managers;
|
using AssetRipper.Import.Structure.Assembly.Managers;
|
||||||
@ -6,6 +7,7 @@ using AssetRipper.IO.Files;
|
|||||||
using AssetRipper.Primitives;
|
using AssetRipper.Primitives;
|
||||||
using AssetRipper.Processing;
|
using AssetRipper.Processing;
|
||||||
using AssetRipper.SourceGenerated.Classes.ClassID_114;
|
using AssetRipper.SourceGenerated.Classes.ClassID_114;
|
||||||
|
using AssetRipper.SourceGenerated.Classes.ClassID_115;
|
||||||
using AssetRipper.SourceGenerated.Classes.ClassID_43;
|
using AssetRipper.SourceGenerated.Classes.ClassID_43;
|
||||||
using AssetRipper.SourceGenerated.Extensions;
|
using AssetRipper.SourceGenerated.Extensions;
|
||||||
using NUnit.Framework.Internal;
|
using NUnit.Framework.Internal;
|
||||||
@ -64,15 +66,74 @@ internal class ExportTests
|
|||||||
Assert.That(fileSystem.File.Exists("/output/ExportedProject/Assets/Mesh/Mesh.asset"));
|
Assert.That(fileSystem.File.Exists("/output/ExportedProject/Assets/Mesh/Mesh.asset"));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static VirtualFileSystem Export(ProcessedAssetCollection collection, string outputPath = "output", VirtualFileSystem? fileSystem = null)
|
static readonly (string AssemblyName, string AssemblyGuid)[] AssemblyGuidTestCases =
|
||||||
|
[
|
||||||
|
("UnityEngine.UI", "f5f67c52d1564df4a8936ccd202a3bd8"),
|
||||||
|
];
|
||||||
|
static readonly UnityVersion[] AssemblyGuidTestVersions =
|
||||||
|
[
|
||||||
|
UnityVersion.V_5_3,
|
||||||
|
UnityVersion.V_5_4,
|
||||||
|
UnityVersion.V_5_5,
|
||||||
|
UnityVersion.V_5_6,
|
||||||
|
UnityVersion.V_2017,
|
||||||
|
UnityVersion.V_2018,
|
||||||
|
];
|
||||||
|
[Theory]
|
||||||
|
public void AssembliesHaveCorrectGuid([ValueSource(nameof(AssemblyGuidTestCases))] (string, string) pair, [ValueSource(nameof(AssemblyGuidTestVersions))] UnityVersion version)
|
||||||
|
{
|
||||||
|
(string assemblyName, string assemblyGuid) = pair;
|
||||||
|
MonoManager assemblyManager = CreateAssemblyManager();
|
||||||
|
const string TypeName = "ExampleBehaviour";
|
||||||
|
{
|
||||||
|
assemblyManager.Load(typeof(UnityEngine.Object).Assembly.Location);
|
||||||
|
ModuleDefinition unityEngineModule = assemblyManager.GetAssemblies().Single().ManifestModule!;
|
||||||
|
TypeDefinition monoBehaviourType = unityEngineModule.TopLevelTypes.Single(t => t.Name == "MonoBehaviour");
|
||||||
|
AssemblyDefinition newAssembly = new(assemblyName, new());
|
||||||
|
ModuleDefinition newModule = new(assemblyName, unityEngineModule.AssemblyReferences.First(a => a.IsCorLib));
|
||||||
|
newAssembly.Modules.Add(newModule);
|
||||||
|
TypeDefinition newType = new(null, TypeName, monoBehaviourType.Attributes, newModule.DefaultImporter.ImportType(monoBehaviourType));
|
||||||
|
newModule.TopLevelTypes.Add(newType);
|
||||||
|
MemoryStream stream = new();
|
||||||
|
newModule.Write(stream);
|
||||||
|
stream.Position = 0;
|
||||||
|
assemblyManager.Read(stream, $"{assemblyName}.dll");
|
||||||
|
}
|
||||||
|
|
||||||
|
ProcessedAssetCollection collection = AssetCreator.CreateCollection(version);
|
||||||
|
|
||||||
|
IMonoScript monoScript = collection.CreateMonoScript();
|
||||||
|
monoScript.ClassName_R = TypeName;
|
||||||
|
monoScript.AssemblyName = assemblyName;
|
||||||
|
|
||||||
|
IMonoBehaviour monoBehaviour = collection.CreateMonoBehaviour();
|
||||||
|
monoBehaviour.ScriptP = monoScript;
|
||||||
|
monoBehaviour.Name = "TestBehaviour";
|
||||||
|
|
||||||
|
VirtualFileSystem fileSystem = Export(collection, assemblyManager: assemblyManager);
|
||||||
|
|
||||||
|
using (Assert.EnterMultipleScope())
|
||||||
|
{
|
||||||
|
Assert.That(fileSystem.File.Exists("/output/ExportedProject/Assets/MonoBehaviour/TestBehaviour.asset"));
|
||||||
|
Assert.That(fileSystem.File.Exists("/output/ExportedProject/Assets/MonoBehaviour/TestBehaviour.asset.meta"));
|
||||||
|
}
|
||||||
|
Assert.That(fileSystem.File.ReadAllText("/output/ExportedProject/Assets/MonoBehaviour/TestBehaviour.asset"), Does.Contain(assemblyGuid));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static VirtualFileSystem Export(ProcessedAssetCollection collection, string outputPath = "output", IAssemblyManager? assemblyManager = null, VirtualFileSystem? fileSystem = null)
|
||||||
{
|
{
|
||||||
fileSystem ??= new();
|
fileSystem ??= new();
|
||||||
new ExportHandler(new()).Export(CreateGameData(collection), outputPath, fileSystem);
|
new ExportHandler(new()).Export(CreateGameData(collection, assemblyManager), outputPath, fileSystem);
|
||||||
return fileSystem;
|
return fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GameData CreateGameData(ProcessedAssetCollection collection)
|
private static GameData CreateGameData(ProcessedAssetCollection collection, IAssemblyManager? assemblyManager = null)
|
||||||
{
|
{
|
||||||
return new((GameBundle)collection.Bundle, collection.Version, new BaseManager((s) => { }), null);
|
return new((GameBundle)collection.Bundle, collection.Version, assemblyManager ?? new BaseManager((s) => { }), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MonoManager CreateAssemblyManager()
|
||||||
|
{
|
||||||
|
return new MonoManager((str) => { });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user