Esempio n. 1
0
        private void DrawPreviewGUI()
        {
            GUILayout.FlexibleSpace();

            if (_wavClipEditor == null)
            {
                _wavClipEditor = UnityEditor.Editor.CreateEditor(_wavClip);
            }

            if (_clipEditorBg == null)
            {
                _clipEditorBg = new GUIStyle();
                _clipEditorBg.normal.background = Texture2D.blackTexture;
            }

            int currentSample = GetSamplePosition();

            if (currentSample > 0)
            {
                // Playback position gets reset to zero after pausing. Save the last one to make
                // finding the desired loops easier.
                _lastPreviewSample = currentSample;
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("Preview");
                using (new EditorGUI.DisabledScope(_zoomLevel / 1.5f < 1.0f))
                {
                    if (GUILayout.Button("-"))
                    {
                        _zoomLevel /= 1.5f;
                    }
                }

                using (new EditorGUI.DisabledScope(_zoomLevel * 1.5f > 20.0f))
                {
                    if (GUILayout.Button("+"))
                    {
                        _zoomLevel *= 1.5f;
                    }
                }

                GUILayout.FlexibleSpace();
                _wavClipEditor.OnPreviewSettings();
            }

            using (var scrollView = new EditorGUILayout.ScrollViewScope(_previewScrollPos))
            {
                _previewScrollPos = scrollView.scrollPosition;
                _wavClipEditor.OnPreviewGUI(
                    GUILayoutUtility.GetRect(position.width * _zoomLevel, 100, GUILayout.ExpandWidth(false)),
                    _clipEditorBg);
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                GUILayout.Label("Set Loop Point to Current Preview Position: ", GUILayout.ExpandWidth(false));
                GUILayout.Label(_useSeconds
                    ? SecondsToDurationString(SamplesToSeconds(_lastPreviewSample))
                    : _lastPreviewSample.ToString(),
                                GUILayout.Width(80));

                if (GUILayout.Button("Start", GUILayout.Width(80)))
                {
                    _wavData.GetOrAddFirstLoop().StartSample = _lastPreviewSample;
                }

                if (GUILayout.Button("End", GUILayout.Width(80)))
                {
                    _wavData.GetOrAddFirstLoop().EndSample = _lastPreviewSample;
                }
            }

            // Enable looping by default
            _wavClipEditor.GetType()
            .GetField("s_Loop", BindingFlags.Static | BindingFlags.NonPublic)?
            .SetValue(null, true);
        }