Created
February 13, 2019 17:11
-
-
Save TyounanMOTI/cca64d29c39ac082cad51d099442c46c to your computer and use it in GitHub Desktop.
VRC_AudioBankに一気にD&Dしたノート別AudioClipを音階順に並び替えるスクリプト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using UnityEditor; | |
public class AudioBankSortByNote { | |
readonly static string[] noteNames = { | |
"C1", | |
"C#1", | |
"D1", | |
"D#1", | |
"E1", | |
"F1", | |
"F#1", | |
"G1", | |
"G#1", | |
"A1", | |
"A#1", | |
"B1", | |
"C2", | |
"C#2", | |
"D2", | |
"D#2", | |
"E2", | |
"F2", | |
"F#2", | |
"G2", | |
"G#2", | |
"A2", | |
"A#2", | |
"B2", | |
"C3", | |
"C#3", | |
"D3", | |
"D#3", | |
"E3", | |
"F3", | |
"F#3", | |
"G3", | |
"G#3", | |
"A3", | |
"A#3", | |
"B3", | |
"C4", | |
}; | |
[MenuItem("CONTEXT/VRC_AudioBank/Sort By Note")] | |
static void SortByNote(MenuCommand menuCommand) { | |
var audioBank = menuCommand.context as VRCSDK2.VRC_AudioBank; | |
var serializedObject = new SerializedObject(audioBank); | |
var clipsProperty = serializedObject.FindProperty("Clips"); | |
var clipsLength = clipsProperty.arraySize; | |
var sortedClips = new AudioClip[noteNames.Length]; | |
for (int originalClipIndex = 0; originalClipIndex < clipsLength; originalClipIndex++) { | |
for (int nameIndex = 0; nameIndex < noteNames.Length; nameIndex++) { | |
if (audioBank.Clips[originalClipIndex].name.Contains(noteNames[nameIndex])) { | |
sortedClips[nameIndex] = audioBank.Clips[originalClipIndex]; | |
} | |
} | |
} | |
for (int clipIndex = 0; clipIndex < clipsProperty.arraySize; clipIndex++) { | |
var element = clipsProperty.GetArrayElementAtIndex(clipIndex); | |
element.objectReferenceValue = sortedClips[clipIndex]; | |
} | |
serializedObject.ApplyModifiedProperties(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment