diff --git a/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs b/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs index b09102f..322199f 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs @@ -1,5 +1,7 @@ +using System.Collections.Generic; using System.IO; using System.Linq; +using ArtNet.Packets; using UnityEditor; using UnityEngine; @@ -81,7 +83,29 @@ private static void ConvertPacket(ConvertAnim convertAnim) } var timelineConverter = new TimelineConverter(artNetDmxClip); - var dmxPackets = timelineConverter.ToDmxPackets(); + var universeDataList = timelineConverter.ToUniverseData(); + var dmxPackets = new List<(int, DmxPacket)>(); + byte sequence = 0; + foreach (var universeData in universeDataList) + { + var packet = new DmxPacket + { + Sequence = sequence++, + Universe = (ushort) universeData.Universe, + Dmx = universeData.Values + }; + dmxPackets.Add(((int) (universeData.Time * 1000f), packet)); ; + + if (sequence >= 255) + { + sequence = 0; + } + else + { + sequence++; + } + } + var storeData = RecordData.Serialize(dmxPackets); diff --git a/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs b/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs index 49976cf..c036391 100644 --- a/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs +++ b/Assets/ArtNet/Editor/DmxRecorder/TimelineConverter.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using ArtNet.Packets; using UnityEditor; using UnityEngine; @@ -60,10 +59,9 @@ public void SaveDmxTimelineClips(string directory) AssetDatabase.Refresh(); } - public List<(int time, DmxPacket packet)> ToDmxPackets() + public List ToUniverseData() { - return Timelines.SelectMany(x => x.ToDmxPackets()).OrderBy(x => x.time).Select(x => ((int) (x.time * 1000f), x - .packet)).ToList(); + return Timelines.SelectMany(x => x.ToUniverseData()).OrderBy(x => x.Time).ToList(); } private static void SaveAsset(T asset, string directory, string fileName) where T : UnityEngine.Object @@ -209,10 +207,9 @@ private static bool IsOmittedFrame( return Math.Abs(prevDiff / prevDiffTime - nextDiff / nextDiffTime) <= tolerance; } - public IEnumerable<(float time, DmxPacket packet)> ToDmxPackets() + public IEnumerable ToUniverseData() { - byte sequence = 0; - var packets = new List<(float time, DmxPacket packet)>(); + var universeData = new List(); var allFrameTimes = AllFrameTimes().OrderBy(x => x).ToList(); foreach (var time in allFrameTimes) @@ -223,19 +220,10 @@ private static bool IsOmittedFrame( dmx[i] = FrameValue(i, time); } - var packet = new DmxPacket { Sequence = sequence, Universe = (ushort) Universe, Dmx = dmx }; - packets.Add((time, packet)); - if (sequence >= 255) - { - sequence = 0; - } - else - { - sequence++; - } + universeData.Add(new UniverseData(time, (uint) Universe, dmx)); } - return packets; + return universeData; } }