예제 #1
0
        public static void Draw(InAudioNode node)
        {
            UndoHelper.GUIUndo(node, "Name Change", ref node.Name, () =>
                               EditorGUILayout.TextField("Name", node.Name));

            Rect area = GUILayoutUtility.GetLastRect();

            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            InAudioData audioData = node.NodeData as InAudioData;

            EditorGUILayout.BeginVertical();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("");
            area = GUILayoutUtility.GetLastRect();
            Rect objectArea = area;

            if (Application.isPlaying)
            {
                objectArea.width -= 100;
            }
            var  clip       = (AudioClip)EditorGUI.ObjectField(objectArea, audioData.EditorClip, typeof(AudioClip), false);
            Rect buttonArea = area;

            if (Application.isPlaying)
            {
                buttonArea.x    += buttonArea.width - 100;
                buttonArea.width = 70;
                GUI.enabled      = false;
                EditorGUI.LabelField(buttonArea, "Is Loaded");
                buttonArea.x    += 70;
                buttonArea.width = 10;
                EditorGUI.Toggle(buttonArea, audioData.RuntimeClip != null);
                GUI.enabled = true;
            }



            if (GUILayout.Button("Preview", GUILayout.Width(60)))
            {
                AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>();
                var         root   = TreeWalker.FindParentBeforeFolder(node);
                source.volume = RuntimeHelper.ApplyVolume(root, node);
                source.pitch  = RuntimeHelper.ApplyPitch(root, node);
                source.clip   = audioData.EditorClip;
                source.Play();
            }

            if (GUILayout.Button("Raw", GUILayout.Width(45)))
            {
                AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>();
                source.clip   = audioData.EditorClip;
                source.volume = 1.0f;
                source.pitch  = 1.0f;
                source.Play();
            }

            if (GUILayout.Button("Stop", GUILayout.Width(45)))
            {
                AudioSource source = InAudioInstanceFinder.Instance.GetComponent <AudioSource>();
                source.Stop();
                source.clip = null;
            }


            EditorGUILayout.EndHorizontal();

            EditorGUILayout.EndVertical();

            if (audioData.RuntimeClip != null && Application.isPlaying)
            {
                audioData.RuntimeClip = clip;
            }

            if (clip != audioData.EditorClip) //Assign new clip
            {
                UndoHelper.RecordObjectFull(new Object[] { audioData, node.GetBank().LazyBankFetch }, "Changed " + node.Name + " Clip");
                audioData.EditorClip  = clip;
                audioData.RuntimeClip = clip;
                AudioBankWorker.SwapClipInBank(node, clip);

                EditorUtility.SetDirty(node.GetBank().LazyBankFetch.gameObject);
                EditorUtility.SetDirty(node.NodeData.gameObject);
            }

            EditorGUILayout.EndHorizontal();

            NodeTypeDataDrawer.Draw(node);
        }
예제 #2
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);
                }
            }
        }