-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoopMarkerScanner.cs
More file actions
39 lines (32 loc) · 1.45 KB
/
Copy pathLoopMarkerScanner.cs
File metadata and controls
39 lines (32 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
public class LoopMarkerScanner : EditorWindow
{
[MenuItem("Assets/Get Loop Markers", false, 1)]
private static void GetSelectedAudioMarkers()
{
Object[] selectedObjects = Selection.GetFiltered(typeof(AudioClip), SelectionMode.DeepAssets);
if (selectedObjects.Length == 0) return;
foreach (AudioClip clip in selectedObjects)
{
string path = AssetDatabase.GetAssetPath(clip);
string fullPath = Path.GetFullPath(path);
// Binary Read to find hidden markers
byte[] fileBytes = File.ReadAllBytes(fullPath);
string content = Encoding.Default.GetString(fileBytes);
string loopStart = FindValue(content, "LOOPSTART");
string loopEnd = FindValue(content, "LOOPEND");
Debug.Log($"<color=cyan><b>[LoopScanner]</b></color> Track: <b>{clip.name}</b>\n" +
$"<color=lime>LOOPSTART: {loopStart}</color> | <color=orange>LOOPEND: {loopEnd}</color>");
}
}
private static string FindValue(string text, string key)
{
// Search for the key and extract the digits immediately following it
Match match = Regex.Match(text, key + @"\D*(\d+)");
return match.Success ? match.Groups[1].Value : "Not Found";
}
}