I’m writing an audio editor and I have a visual timeline in an Editor Window that lets me edit audio sources and clips.
In OnGUI I call:
Undo.RecordObject(sequence.blender, “Edit Tracks”);
Before I run any code for editing the tracks and this works perfectly - when I hit undo, it works for all kinds of changes I’ve made to the timeline except for:
- Deleting
- Adding new objects
Since I’m using arrays, deleting and adding clips works by allocating a new array and writing to it:
public void RemoveClip(int index)
{
if (index < 0 || index >= clips.Length) throw new UnityException("Clip " + index + " does not exist");
clips[index].Destroy();
BlendClip[] newClips = new BlendClip[clips.Length - 1];
for (int i = 0; i < clips.Length; i++)
{
if (i == index) continue;
if (i < index) newClips[i] = clips[i];
if (i > index) newClips[i - 1] = clips[i];
}
clips = newClips;
}
Does anyone have any idea how I can record this as an undo action? Changes to properties of array elements get recorded well but not this.