Dank @zayedupal, ist diese vollständige Antwort auf Gameobject automatisch erstellt, Komponenten für die Objekt und fügt automatisch UnityEvent im Editor hinzu.
[MenuItem("GameObject/Create Animation/With SFX", false, -1)]
static void CreateAnimationWithSFX()
{
GameObject go = new GameObject("animationWithSFX");
go.transform.SetParent(Selection.activeTransform);
AudioSource audioSource = go.AddComponent<AudioSource>();
audioSource.playOnAwake = false;
// Automate-add the right channel for audio source
AudioMixer mixer = Resources.Load("Master") as AudioMixer;
audioSource.outputAudioMixerGroup = mixer.FindMatchingGroups("SFX")[0];
SceneAnimationEvent script = go.AddComponent<SceneAnimationEvent>();
// Automate-add the unity built-in function into UnityEvent
script.Events = new UnityEvent();
UnityAction methodDelegate = System.Delegate.CreateDelegate (typeof(UnityAction), audioSource, "Play") as UnityAction;
UnityEventTools.AddPersistentListener (script.Events, methodDelegate);
Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);
Selection.activeObject = go;
}
Es funktioniert, ich werde meinen vollständigen Code veröffentlichen, wenn jemand anderes das gleiche Problem auftritt. –