private void CreateChild(AudioNode parent, AudioNodeType type) { var newNode = AudioNodeWorker.CreateChild(parent, type); if (type == AudioNodeType.Audio) { AudioBankWorker.AddNodeToBank(newNode, null); } }
protected override void OnDrop(AudioNode node, UnityEngine.Object[] objects) { if (objects[0] as AudioNode != null) //Drag N Drop internally in the tree, change the parent { node.IsFoldedOut = true; var nodeToMove = objects[0] as AudioNode; var oldBank = AudioBankWorker.GetParentBank(nodeToMove); AudioBankLink newBank = null; if (nodeToMove.OverrideParentBank) { newBank = AudioBankWorker.GetParentBank(nodeToMove); } else { newBank = AudioBankWorker.GetParentBank(node); } Undo.RegisterUndo(new UnityEngine.Object[] { node, nodeToMove, nodeToMove.Parent, oldBank, newBank }, "Audio Node Move"); NodeWorker.ReasignNodeParent(nodeToMove, node); AudioBankWorker.MoveNode(nodeToMove, oldBank); } else if (node.Type != AudioNodeType.Audio) //Create new audio nodes when we drop clips { for (int i = 0; i < objects.Length; ++i) { var clip = objects[i] as AudioClip; var child = AudioNodeWorker.CreateChild(node, AudioNodeType.Audio); var path = AssetDatabase.GetAssetPath(clip); try { //Try and get the name of the clip. Gets the name and removes the end. Assets/IntroSound.mp3 -> IntroSound int lastIndex = path.LastIndexOf('/') + 1; child.Name = path.Substring(lastIndex, path.LastIndexOf('.') - lastIndex); } catch (Exception) //If it happens to be a mutant path. Not even sure if this is possible, but better safe than sorry { child.Name = node.Name + " Child"; } (child.NodeData as AudioData).EditorClip = clip; AudioBankWorker.AddNodeToBank(child, clip); Event.current.Use(); } } else //Then it must be an audio clip dropped on an audio node, so assign the clip to that node { var bank = AudioBankWorker.GetParentBank(node); Undo.RegisterUndo(new UnityEngine.Object[] { node, bank.LazyBankFetch, node.NodeData }, "Undo Changing Node In Bank"); (node.NodeData as AudioData).EditorClip = objects[0] as AudioClip; AudioBankWorker.SwapClipInBank(node, objects[0] as AudioClip); } }