Skip to content

Commit

Permalink
DxmPacket に変換できるようにする
Browse files Browse the repository at this point in the history
  • Loading branch information
nasshu2916 committed Oct 20, 2024
1 parent cef42bb commit 20a767d
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
50 changes: 47 additions & 3 deletions Assets/ArtNet/Editor/DmxRecorder/ConvertAnimInspector.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
using UnityEditor;
using UnityEngine;

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

EditorGUILayout.BeginVertical(GUI.skin.box);
{
if (GUILayout.Button("Convert"))
if (GUILayout.Button("ConvertAnim"))
{
Convert(convertAnim);
ConvertAnim(convertAnim);
}

GUILayout.Space(5);

if (GUILayout.Button("ConvertPacket"))
{
ConvertPacket(convertAnim);
}
}
EditorGUILayout.EndVertical();
}

private static void Convert(ConvertAnim convertAnim)
private static void ConvertAnim(ConvertAnim convertAnim)
{
var binary = convertAnim.binary;
if (!binary)
Expand All @@ -44,5 +52,41 @@ private static void Convert(ConvertAnim convertAnim)

Debug.Log("Conversion complete");
}

private static void ConvertPacket(ConvertAnim convertAnim)
{
var binary = convertAnim.binary;
if (!binary)
{
Debug.LogError("Binary is null");
return;
}
if (string.IsNullOrEmpty(convertAnim.OutputDirectory))
{
Debug.LogError("Output directory is null or empty");
return;
}

var timelineSettingPath = convertAnim.OutputDirectory + "/DmxTimeline.asset";
var dmxTimelineSetting = AssetDatabase.LoadAssetAtPath(timelineSettingPath, typeof(DmxTimelineSetting)) as DmxTimelineSetting;
if (dmxTimelineSetting is null)
{
Debug.LogError("DmxTimelineSetting is null");
return;
}

Debug.Log($"ArtNet Recorder: {dmxTimelineSetting.DmxTimelines.Count} timelines found");
var timelineConverter = new TimelineConverter(dmxTimelineSetting);
var dmxPackets = timelineConverter.ToDmxPackets();
var storeData = RecordData.Serialize(dmxPackets);


var path = convertAnim.OutputDirectory + "/DmxPackets.bytes";
var exists = File.Exists(path);
File.WriteAllBytes(path, storeData);
var message = exists ? "Data updated" : "Data stored";
Debug.Log($"ArtNet Recorder: {message} at {path}");
Debug.Log("Conversion complete");
}
}
}
2 changes: 1 addition & 1 deletion Assets/ArtNet/Editor/DmxRecorder/RecordData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class RecordData
private static readonly byte[] ReservedBuffer = new byte[11];
private static byte Version = 0x01;

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

0 comments on commit 20a767d

Please sign in to comment.