Пример #1
0
        void OnRemovedGlobalSequence(UnityEditorInternal.ReorderableList list)
        {
            if (list.index < 0 || list.index >= list.count)
            {
                return;
            }
            Sequence toRemove = m_globalSequences.GetArrayElementAtIndex(list.index).objectReferenceValue as Sequence;

            m_globalSequences.DeleteArrayElementAtIndex(list.index);
            if (Application.isPlaying && toRemove != null && !AmbienceManager.WasSequenceAdded(toRemove))
            {
                AmbienceManager.OnEditorRemovedSequence(toRemove);
            }
        }
Пример #2
0
        /// <summary> Main GUI Function </summary>
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            m_editorUtils.Initialize(); // Do not remove this!
            m_editorUtils.GUIHeader();
            m_editorUtils.TitleNonLocalized(m_editorUtils.GetContent("SequenceDataHeader").text + serializedObject.targetObject.name);

            EditorGUI.BeginDisabledGroup(!Application.isPlaying);
            if (!Application.isPlaying || !AmbienceManager.WasSequenceAdded(target as Sequence))
            {
                if (m_editorUtils.Button("EditorPlayButton"))
                {
                    Sequence seq = target as Sequence;
                    seq.m_forcePlay = true;
                    AmbienceManager.AddSequence(seq);
                }
            }
            else
            {
                if (m_editorUtils.Button("EditorStopButton"))
                {
                    Sequence seq = target as Sequence;
                    seq.m_forcePlay = false;
                    AmbienceManager.RemoveSequence(seq);
                }
            }
            EditorGUI.EndDisabledGroup();

            m_editorUtils.Panel("RequirementsPanel", RequirementsPanel, true);
            m_editorUtils.Panel("ClipsPanel", ClipsPanel, true);
            m_editorUtils.Panel("OutputPanel", OutputPanel, true);
            m_editorUtils.Panel("RandomizationPanel", RandomizationPanel, true);
            m_editorUtils.Panel("ModifiersPanel", ModifiersPanel, true);
            m_editorUtils.Panel("EventsPanel", EventsPanel, true);
            m_editorUtils.Panel("SyncPanel", SyncPanel, true);

            //m_editorUtils.GUIFooter();
            serializedObject.ApplyModifiedProperties();
        }
Пример #3
0
 bool CanAddStopMenuItem()
 {
     return(Application.isPlaying && AmbienceManager.WasSequenceAdded(this));
 }
Пример #4
0
        /// <summary> Displays a list of all Sequence assets in project </summary>
        /// <param name="inlineHelp">Should help be displayed?</param>
        void SequencesPanel(bool inlineHelp)
        {
            GUIStyle playButtonNormal;
            GUIStyle playButtonPressed;

            playButtonNormal         = EditorStyles.miniButtonLeft;
            playButtonPressed        = new GUIStyle(playButtonNormal);
            playButtonPressed.normal = playButtonNormal.active;
            GUIStyle muteButtonNormal;
            GUIStyle muteButtonPressed;

            muteButtonNormal         = EditorStyles.miniButtonRight;
            muteButtonPressed        = new GUIStyle(muteButtonNormal);
            muteButtonPressed.normal = muteButtonNormal.active;
            foreach (Sequence data in AllSequences)
            {
                EditorGUILayout.BeginHorizontal();
                Rect r = EditorGUILayout.GetControlRect();
                if (r.yMax > m_scrollPosition.y)
                {
                    if (Event.current.type == EventType.MouseDown && r.Contains(Event.current.mousePosition))
                    {
                        lastClickedOn = data;
                    }
                    else if (Event.current.type == EventType.MouseDrag && lastClickedOn == data && r.Contains(Event.current.mousePosition))
                    {
                        DragAndDrop.PrepareStartDrag();
                        DragAndDrop.objectReferences = new Object[] { data };
                        DragAndDrop.StartDrag("Sequence:" + data.name);
                        Event.current.Use();
                        weStartedDrag = true;
                    }
                    else if (Event.current.type == EventType.DragUpdated && r.Contains(Event.current.mousePosition))
                    {
                        bool found = false;
                        for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                        {
                            if (DragAndDrop.objectReferences[o] is AudioClip)
                            {
                                DragAndDrop.visualMode = DragAndDropVisualMode.Link;
                                Event.current.Use();
                                found = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
                            Event.current.Use();
                        }
                    }
                    else if (Event.current.type == EventType.DragPerform && r.Contains(Event.current.mousePosition))
                    {
                        List <Sequence.ClipData> clips = new List <Sequence.ClipData>(data.m_clipData);
                        bool foundOne = false;
                        for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                        {
                            if (DragAndDrop.objectReferences[o] is AudioClip)
                            {
                                foundOne = true;
                                clips.Add(DragAndDrop.objectReferences[o] as AudioClip);
                            }
                        }
                        if (foundOne)
                        {
                            data.m_clipData = clips.ToArray();
                        }
                    }
                    else if ((Event.current.type == EventType.DragExited || Event.current.type == EventType.MouseUp) && lastClickedOn == data && weStartedDrag)
                    {
                        weStartedDrag = false;
                        lastClickedOn = null;
                        DragAndDrop.PrepareStartDrag();
                    }
                }
                EditorGUI.ObjectField(r, data, typeof(Sequence), false);

                EditorGUI.BeginDisabledGroup(!Application.isPlaying);
                if (!Application.isPlaying || !AmbienceManager.WasSequenceAdded(data))
                {
                    if (m_editorUtils.Button(EditorGUIUtility.IconContent("PlayButton"), playButtonNormal, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(false)))
                    {
                        data.m_forcePlay = true;
                        AmbienceManager.AddSequence(data);
                    }
                }
                else
                {
                    if (m_editorUtils.Button(EditorGUIUtility.IconContent("PlayButton On"), playButtonPressed, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(false)))
                    {
                        data.m_forcePlay = false;
                        AmbienceManager.RemoveSequence(data);
                    }
                }

                Color    startColor  = GUI.color;
                GUIStyle buttonStyle = muteButtonNormal;
                if (data.m_forceMuted)
                {
                    GUI.color   = Color.red;
                    buttonStyle = muteButtonPressed;
                }
                if (m_editorUtils.Button(EditorGUIUtility.IconContent("preAudioAutoPlayOff"), buttonStyle, GUILayout.Height(EditorGUIUtility.singleLineHeight), GUILayout.ExpandWidth(false)))
                {
                    if (Event.current.button == 1)
                    {
                        data.m_forceMuted = false;
                        bool curMuted = true;
                        foreach (Sequence s in AllSequences)
                        {
                            if (s != null && s != data)
                            {
                                curMuted &= s.m_forceMuted;
                            }
                        }
                        foreach (Sequence s in AllSequences)
                        {
                            if (s != null && s != data)
                            {
                                s.m_forceMuted = !curMuted;
                            }
                        }
                    }
                    else
                    {
                        data.m_forceMuted = !data.m_forceMuted;
                    }
                }
                GUI.color = startColor;
                EditorGUI.EndDisabledGroup();
                EditorGUILayout.EndHorizontal();
            }
            ++EditorGUI.indentLevel;
            EditorGUILayout.BeginHorizontal();
            if (m_editorUtils.Button("SequenceCreateButton", GUILayout.ExpandWidth(false)))
            {
                GUIContent dialogContent = m_editorUtils.GetContent("SequenceCreateDialog");
                string     newPath       = EditorUtility.SaveFilePanelInProject(dialogContent.text, "Sequence", "asset", dialogContent.tooltip, newSequencePath);
                if (!string.IsNullOrEmpty(newPath))
                {
                    AssetDatabase.CreateAsset(CreateInstance <Sequence>(), newPath);
                    Sequence newSequence = AssetDatabase.LoadAssetAtPath <Sequence>(newPath);
                    Selection.activeInstanceID = newSequence.GetInstanceID();
                }
            }
            Rect buttonRect = GUILayoutUtility.GetLastRect();

            if (Event.current.type == EventType.DragUpdated && buttonRect.Contains(Event.current.mousePosition))
            {
                for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                {
                    if (DragAndDrop.objectReferences[o] is AudioClip)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                        Event.current.Use();
                        break;
                    }
                }
            }
            else if (Event.current.type == EventType.DragPerform && buttonRect.Contains(Event.current.mousePosition))
            {
                List <Sequence.ClipData> clips = new List <Sequence.ClipData>();
                for (int o = 0; o < DragAndDrop.objectReferences.Length; ++o)
                {
                    if (DragAndDrop.objectReferences[o] is AudioClip)
                    {
                        clips.Add(DragAndDrop.objectReferences[o] as AudioClip);
                    }
                }
                if (clips.Count > 0)
                {
                    if (Event.current.control)   //create one for each
                    {
                        GUIContent dialogContent = m_editorUtils.GetContent("SequenceMultiCreateDialog");
                        string     saveFolder    = EditorUtility.SaveFolderPanel(dialogContent.text, "Assets", "Assets");
                        if (!string.IsNullOrEmpty(saveFolder))
                        {
                            if (saveFolder.StartsWith(Application.dataPath))
                            {
                                saveFolder = saveFolder.Substring(Application.dataPath.Length - 6);
                                if (!saveFolder.EndsWith("/"))
                                {
                                    saveFolder += "/";
                                }
                                foreach (Sequence.ClipData clip in clips)
                                {
                                    Sequence newSequence = CreateInstance <Sequence>();
                                    newSequence.m_clipData = new Sequence.ClipData[] { clip };
                                    AssetDatabase.CreateAsset(newSequence, saveFolder + clip.m_clip.name + ".asset");
                                }
                            }
                            else
                            {
                                GUIContent errorContent = m_editorUtils.GetContent("CreateWrongFolderError");
                                EditorUtility.DisplayDialog(errorContent.text, errorContent.tooltip, "Ok");
                            }
                        }
                    }
                    else     //stack all into one sequence
                    {
                        GUIContent dialogContent = m_editorUtils.GetContent("SequenceCreateDialog");
                        string     savePath      = EditorUtility.SaveFilePanelInProject(dialogContent.text, "Sequence", "asset", dialogContent.tooltip);
                        if (!string.IsNullOrEmpty(savePath))
                        {
                            Sequence newSequence = CreateInstance <Sequence>();
                            newSequence.m_clipData = clips.ToArray();
                            AssetDatabase.CreateAsset(newSequence, savePath);
                        }
                    }
                }
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            m_editorUtils.InlineHelp("SequenceCreateButton", inlineHelp);
            --EditorGUI.indentLevel;
        }