Gets the attributes collection from the data. The graph metadata serialized with JsonSerializer. The graph metadata serialized with BinaryFormatter. The attributes collection.
(byte[] data, byte[] oldData)
| 56 | /// <param name="oldData">The graph metadata serialized with BinaryFormatter.</param> |
| 57 | /// <returns>The attributes collection.</returns> |
| 58 | public static Attribute[] GetAttributes(byte[] data, byte[] oldData) |
| 59 | { |
| 60 | if (data != null && data.Length != 0) |
| 61 | { |
| 62 | try |
| 63 | { |
| 64 | var json = Encoding.Unicode.GetString(data); |
| 65 | return FlaxEngine.Json.JsonSerializer.Deserialize<Attribute[]>(json); |
| 66 | } |
| 67 | catch (Exception ex) |
| 68 | { |
| 69 | Editor.LogError("Failed to deserialize Visject attributes array."); |
| 70 | Editor.LogWarning(ex); |
| 71 | } |
| 72 | } |
| 73 | if (oldData != null && oldData.Length != 0) |
| 74 | { |
| 75 | // [Deprecated on 8.12.2023, expires on 8.12.2025] |
| 76 | using (var stream = new MemoryStream(oldData)) |
| 77 | { |
| 78 | try |
| 79 | { |
| 80 | // Ensure we are in the correct load context (https://github.com/dotnet/runtime/issues/42041) |
| 81 | using var ctx = AssemblyLoadContext.EnterContextualReflection(typeof(Editor).Assembly); |
| 82 | #pragma warning disable SYSLIB0011 |
| 83 | var formatter = new BinaryFormatter(); |
| 84 | return (Attribute[])formatter.Deserialize(stream); |
| 85 | #pragma warning restore SYSLIB0011 |
| 86 | } |
| 87 | catch (Exception ex) |
| 88 | { |
| 89 | Editor.LogError("Failed to deserialize Visject attributes array."); |
| 90 | Editor.LogWarning(ex); |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return Utils.GetEmptyArray<Attribute>(); |
| 95 | } |
| 96 | |
| 97 | /// <summary> |
| 98 | /// Serializes surface attributes into byte[] data using the current format. |
no test coverage detected