Skip to content

Commit 20a767d

Browse files
committed
DxmPacket に変換できるようにする
1 parent cef42bb commit 20a767d

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.IO;
12
using UnityEditor;
23
using UnityEngine;
34

@@ -16,15 +17,22 @@ public override void OnInspectorGUI()
1617

1718
EditorGUILayout.BeginVertical(GUI.skin.box);
1819
{
19-
if (GUILayout.Button("Convert"))
20+
if (GUILayout.Button("ConvertAnim"))
2021
{
21-
Convert(convertAnim);
22+
ConvertAnim(convertAnim);
23+
}
24+
25+
GUILayout.Space(5);
26+
27+
if (GUILayout.Button("ConvertPacket"))
28+
{
29+
ConvertPacket(convertAnim);
2230
}
2331
}
2432
EditorGUILayout.EndVertical();
2533
}
2634

27-
private static void Convert(ConvertAnim convertAnim)
35+
private static void ConvertAnim(ConvertAnim convertAnim)
2836
{
2937
var binary = convertAnim.binary;
3038
if (!binary)
@@ -44,5 +52,41 @@ private static void Convert(ConvertAnim convertAnim)
4452

4553
Debug.Log("Conversion complete");
4654
}
55+
56+
private static void ConvertPacket(ConvertAnim convertAnim)
57+
{
58+
var binary = convertAnim.binary;
59+
if (!binary)
60+
{
61+
Debug.LogError("Binary is null");
62+
return;
63+
}
64+
if (string.IsNullOrEmpty(convertAnim.OutputDirectory))
65+
{
66+
Debug.LogError("Output directory is null or empty");
67+
return;
68+
}
69+
70+
var timelineSettingPath = convertAnim.OutputDirectory + "/DmxTimeline.asset";
71+
var dmxTimelineSetting = AssetDatabase.LoadAssetAtPath(timelineSettingPath, typeof(DmxTimelineSetting)) as DmxTimelineSetting;
72+
if (dmxTimelineSetting is null)
73+
{
74+
Debug.LogError("DmxTimelineSetting is null");
75+
return;
76+
}
77+
78+
Debug.Log($"ArtNet Recorder: {dmxTimelineSetting.DmxTimelines.Count} timelines found");
79+
var timelineConverter = new TimelineConverter(dmxTimelineSetting);
80+
var dmxPackets = timelineConverter.ToDmxPackets();
81+
var storeData = RecordData.Serialize(dmxPackets);
82+
83+
84+
var path = convertAnim.OutputDirectory + "/DmxPackets.bytes";
85+
var exists = File.Exists(path);
86+
File.WriteAllBytes(path, storeData);
87+
var message = exists ? "Data updated" : "Data stored";
88+
Debug.Log($"ArtNet Recorder: {message} at {path}");
89+
Debug.Log("Conversion complete");
90+
}
4791
}
4892
}

Assets/ArtNet/Editor/DmxRecorder/RecordData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class RecordData
1515
private static readonly byte[] ReservedBuffer = new byte[11];
1616
private static byte Version = 0x01;
1717

18-
public static byte[] Serialize(List<(int time, DmxPacket packet)> dmxPackets)
18+
public static byte[] Serialize(IReadOnlyList<(int time, DmxPacket packet)> dmxPackets)
1919
{
2020
var startTime = dmxPackets.Select(x => x.time).OrderBy(x => x).First();
2121
using var memoryStream = new MemoryStream();

0 commit comments

Comments
 (0)