Beispiel #1
0
        private void CreateChild(InAudioNode parent, AudioNodeType type)
        {
            UndoHelper.RecordObjectFull(new UnityEngine.Object[] { parent, parent.GetBank().LazyBankFetch },
                                        "Create Audio Node");
            var newNode = AudioNodeWorker.CreateChild(parent, type);

            if (type == AudioNodeType.Audio)
            {
                AudioBankWorker.AddNodeToBank(newNode, null);
            }
        }
        private static void NodeDuplicate(InAudioNode oldNode, InAudioNode newNode, GameObject gameObject)
        {
            Type type = oldNode._nodeData.GetType();

            newNode._nodeData = gameObject.AddComponentUndo(type) as InAudioNodeBaseData;
            EditorUtility.CopySerialized(oldNode._nodeData, newNode._nodeData);
            if (newNode._type == AudioNodeType.Audio)
            {
                AudioBankWorker.AddNodeToBank(newNode);
            }
        }
Beispiel #3
0
        protected override void OnDrop(InAudioNode node, UnityEngine.Object[] objects)
        {
            if (objects[0] as InAudioNode != null) //Drag N Drop internally in the tree, change the parent
            {
                node.IsFoldedOut = true;
                var nodeToMove = objects[0] as InAudioNode;

                UndoHelper.RecordObject(
                    new UnityEngine.Object[] { node, node.NodeData, nodeToMove.Parent.NodeData, nodeToMove, nodeToMove.Parent }.AddObj(
                        TreeWalker.FindAll(InAudioInstanceFinder.DataManager.BankLinkTree,
                                           link => link.Type == AudioBankTypes.Link ? link.LazyBankFetch : null).ToArray()),
                    "Audio Node Move");

                NodeWorker.ReasignNodeParent(nodeToMove, node);
                AudioBankWorker.RebuildBanks(InAudioInstanceFinder.DataManager.BankLinkTree,
                                             InAudioInstanceFinder.DataManager.AudioTree);
            }
            else if (node.Type != AudioNodeType.Audio) //Create new audio nodes when we drop clips
            {
                UndoHelper.RecordObject(UndoHelper.NodeUndo(node), "Adding Nodes to " + node.Name);

                AudioClip[] clips = objects.Convert(o => o as AudioClip);

                Array.Sort(clips, (clip, audioClip) => StringLogicalComparer.Compare(clip.name, audioClip.name));

                for (int i = 0; i < clips.Length; ++i)
                {
                    var clip  = clips[i];
                    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 InAudioData).EditorClip  = clip;
                    (child.NodeData as InAudioData).RuntimeClip = 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 nodeData = (node.NodeData as InAudioData);
                if (nodeData != null)
                {
                    UndoHelper.RecordObject(UndoHelper.NodeUndo(node), "Change Audio Clip In " + node.Name);
                    nodeData.EditorClip = objects[0] as AudioClip;
                    if (Application.isPlaying)
                    {
                        if (node.GetBank().IsLoaded)
                        {
                            nodeData.RuntimeClip = objects[0] as AudioClip;
                        }
                    }
                    AudioBankWorker.SwapClipInBank(node, objects[0] as AudioClip);
                }
            }
        }
        protected override void OnDrop(InAudioNode node, UnityEngine.Object[] objects)
        {
            if (objects[0] as InAudioNode != null) //Drag N Drop internally in the tree, change the parent
            {
                InUndoHelper.DoInGroup(() =>
                {
                    node.IsFoldedOut = true;
                    var nodeToMove   = objects[0] as InAudioNode;

                    if (node.gameObject != nodeToMove.gameObject)
                    {
                        if (EditorUtility.DisplayDialog("Move?",
                                                        "Warning, this will break all external references to this and all child nodes!\n" +
                                                        "Move node from\"" + nodeToMove.gameObject.name +
                                                        "\" to \"" + node.gameObject.name + "\"?", "Ok", "Cancel"))
                        {
                            treeDrawer.SelectedNode = treeDrawer.SelectedNode._getParent;
                            isDirty = false;
                            AudioNodeWorker.CopyTo(nodeToMove, node);
                            AudioNodeWorker.DeleteNodeNoGroup(nodeToMove);
                        }
                    }
                    else
                    {
                        MoveNode(node, nodeToMove);
                    }
                });
            }
            else if (node._type != AudioNodeType.Audio) //Create new audio nodes when we drop clips
            {
                InUndoHelper.DoInGroup(() =>
                {
                    InUndoHelper.RecordObject(InUndoHelper.NodeUndo(node), "Adding Nodes to " + node.Name);

                    AudioClip[] clips = objects.Convert(o => o as AudioClip);

                    Array.Sort(clips, (clip, audioClip) => StringLogicalComparer.Compare(clip.name, audioClip.name));

                    for (int i = 0; i < clips.Length; ++i)
                    {
                        var clip  = clips[i];
                        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";
                        }

                        var audioData   = (child._nodeData as InAudioData);
                        audioData._clip = clip;

                        AudioBankWorker.AddNodeToBank(child);
                        Event.current.UseEvent();
                    }
                });
            }
            else //Then it must be an audio clip dropped on an audio node, so assign the clip to that node
            {
                InUndoHelper.DoInGroup(() =>
                {
                    var nodeData = (node._nodeData as InAudioData);
                    if (nodeData != null)
                    {
                        InUndoHelper.RecordObject(InUndoHelper.NodeUndo(node), "Change Audio Clip In " + node.Name);
                        nodeData._clip = objects[0] as AudioClip;
                    }
                });
                Event.current.UseEvent();
            }
        }