using EvilEngine.Mounts; namespace EvilEngine.Adapters.Unity; public static class BuildSettings { public const int Class = 141; private const int LongestPath = 1024; public static IReadOnlyList? ReadScenes(SerializedFile file, IRandomAccess access, out string? why) { var settings = file.Objects.Where(item => item.ClassId == Class).ToArray(); if (settings.Length != 1) { why = $"the file holds {settings.Length} BuildSettings objects rather than one"; return null; } try { var reader = new ObjectReader(file, access, settings[0]); var scenes = new string[reader.Count(4)]; for (var index = 0; index < scenes.Length; index++) scenes[index] = reader.String(LongestPath); why = null; return scenes; } catch (InvalidDataException error) { why = $"BuildSettings' scene list doesn't read: {error.Message}"; return null; } } public static string SceneName(string path) { var name = path[(path.LastIndexOf('/') + 1)..]; return name.EndsWith(".unity", StringComparison.OrdinalIgnoreCase) ? name[..^".unity".Length] : name; } public static string LevelFile(int index) { return $"level{index}"; } public static string SharedAssetsFile(int index) { return $"sharedassets{index}.assets"; } }