Esempio n. 1
0
    public static void Draw(AudioBankLink node)
    {
        UndoHandler.CheckUndo(node);
        //UndoCheck.Instance.CheckUndo(node, "Audio Bank:" + node.Name);
        EditorGUILayout.BeginVertical();
        node.Name = EditorGUILayout.TextField("Name", node.Name);
        if (node.Type != AudioBankTypes.Folder)
        {
            EditorGUILayout.IntField("ID", node.GUID);
            EditorGUILayout.Separator();
            node.AutoLoad = EditorGUILayout.Toggle("Auto load", node.AutoLoad);
        }


        Rect lastArea = GUILayoutUtility.GetLastRect();

        lastArea.y    += 28;
        lastArea.width = 200;
        if (GUI.Button(lastArea, "Find Folders using this bank"))
        {
            EditorWindow.GetWindow <AudioWindow>().Find(audioNode => AudioBankWorker.GetParentBank(audioNode) != node);
        }

        EditorGUILayout.EndVertical();
        //UndoCheck.Instance.CheckDirty(node);
        UndoHandler.CheckGUIChange();
    }
    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);
        }
    }
    public static void Draw(AudioNode node)
    {
        UndoHandler.CheckUndo(new Object[] { node, node.NodeData });
        node.Name = EditorGUILayout.TextField("Name", node.Name);
        UndoHandler.CheckGUIChange();
        EditorGUILayout.Separator();
        AudioData audio = node.NodeData as AudioData;
        var       clip  = (AudioClip)EditorGUILayout.ObjectField(audio.Clip, typeof(AudioClip), false);

        if (clip != audio.EditorClip) //Assign new clip
        {
            Undo.RegisterUndo(new Object[] { node.NodeData, AudioBankWorker.GetParentBank(node).LazyBankFetch }, "Changed " + node.Name + " Clip");
            audio.EditorClip = clip;
            AudioBankWorker.SwapClipInBank(node, clip);
        }

        NodeTypeDataDrawer.Draw(node);
    }