MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / LoadTrack

Method LoadTrack

Source/Editor/GUI/Timeline/Tracks/EventTrack.cs:41–102  ·  view source on GitHub ↗
(int version, Track track, BinaryReader stream)

Source from the content-addressed store, hash-verified

39 }
40
41 private static void LoadTrack(int version, Track track, BinaryReader stream)
42 {
43 var e = (EventTrack)track;
44
45 var paramsCount = stream.ReadInt32();
46 e.EventParamsSizes = new int[paramsCount];
47 e.EventParamsTypes = new Type[paramsCount];
48 int eventsCount = stream.ReadInt32();
49 e.MemberName = LoadName(stream);
50
51 bool isInvalid = false;
52 for (int i = 0; i < paramsCount; i++)
53 {
54 e.EventParamsSizes[i] = stream.ReadInt32();
55 var paramTypeName = LoadName(stream);
56 e.EventParamsTypes[i] = TypeUtils.GetManagedType(paramTypeName);
57 if (e.EventParamsTypes[i] == null)
58 {
59 Editor.LogError($"Unknown type {paramTypeName}.");
60 isInvalid = true;
61 }
62 }
63
64 if (isInvalid)
65 {
66 e.Events.ResetKeyframes();
67 stream.ReadBytes(eventsCount * (sizeof(float) + e.EventParamsSizes.Sum()));
68 Editor.LogError("Cannot load track " + e.MemberName + " of type " + e.MemberTypeName + ". Failed to find the value type information.");
69 return;
70 }
71
72 e.OnEventParamsChanged();
73
74 var events = new KeyframesEditor.Keyframe[eventsCount];
75 var dataBuffer = paramsCount != 0 ? new byte[e.EventParamsSizes.Max()] : null;
76 GCHandle handle = paramsCount != 0 ? GCHandle.Alloc(dataBuffer, GCHandleType.Pinned) : new GCHandle();
77 for (int i = 0; i < eventsCount; i++)
78 {
79 var time = stream.ReadSingle();
80
81 var key = new EventKey
82 {
83 Parameters = new object[paramsCount]
84 };
85
86 for (int j = 0; j < paramsCount; j++)
87 {
88 stream.Read(dataBuffer, 0, e.EventParamsSizes[j]);
89 key.Parameters[j] = Utilities.Utils.ByteArrayToStructure(handle.AddrOfPinnedObject(), e.EventParamsTypes[j], e.EventParamsSizes[j]);
90 }
91
92 events[i] = new KeyframesEditor.Keyframe
93 {
94 Time = time,
95 Value = key,
96 };
97 }
98 if (handle.IsAllocated)

Callers

nothing calls this directly

Calls 13

GetManagedTypeMethod · 0.80
ResetKeyframesMethod · 0.80
OnEventParamsChangedMethod · 0.80
ByteArrayToStructureMethod · 0.80
ReadInt32Method · 0.45
LogErrorMethod · 0.45
ReadBytesMethod · 0.45
MaxMethod · 0.45
AllocMethod · 0.45
ReadSingleMethod · 0.45
ReadMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected