0.2.0-dev Download ZIP
51 lines ·1.5 KB Raw
| 1 | using EvilEngine.Mounts; |
| 2 | |
| 3 | namespace EvilEngine.Adapters.Unity; |
| 4 | |
| 5 | public static class BuildSettings |
| 6 | { |
| 7 | public const int Class = 141; |
| 8 | |
| 9 | private const int LongestPath = 1024; |
| 10 | |
| 11 | public static IReadOnlyList<string>? ReadScenes(SerializedFile file, IRandomAccess access, out string? why) |
| 12 | { |
| 13 | var settings = file.Objects.Where(item => item.ClassId == Class).ToArray(); |
| 14 | if (settings.Length != 1) |
| 15 | { |
| 16 | why = $"the file holds {settings.Length} BuildSettings objects rather than one"; |
| 17 | return null; |
| 18 | } |
| 19 | |
| 20 | try |
| 21 | { |
| 22 | var reader = new ObjectReader(file, access, settings[0]); |
| 23 | var scenes = new string[reader.Count(4)]; |
| 24 | for (var index = 0; index < scenes.Length; index++) |
| 25 | scenes[index] = reader.String(LongestPath); |
| 26 | why = null; |
| 27 | return scenes; |
| 28 | } |
| 29 | catch (InvalidDataException error) |
| 30 | { |
| 31 | why = $"BuildSettings' scene list doesn't read: {error.Message}"; |
| 32 | return null; |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public static string SceneName(string path) |
| 37 | { |
| 38 | var name = path[(path.LastIndexOf('/') + 1)..]; |
| 39 | return name.EndsWith(".unity", StringComparison.OrdinalIgnoreCase) ? name[..^".unity".Length] : name; |
| 40 | } |
| 41 | |
| 42 | public static string LevelFile(int index) |
| 43 | { |
| 44 | return $"level{index}"; |
| 45 | } |
| 46 | |
| 47 | public static string SharedAssetsFile(int index) |
| 48 | { |
| 49 | return $"sharedassets{index}.assets"; |
| 50 | } |
| 51 | } |