Exemplo n.º 1
0
    private void UpdateWaveformTimeline(Vector2 mousePosition)
    {
        if (audioClip != null)
        {
            Rect child = GetChildRect(_waveformRect, _audioEditArea, _scrollRect);
            if (child.Contains(mousePosition))
            {
                if (mousePosition.x - child.x > _toolBox.sliderValue)
                {
                    _currentSample = audioClip.samples;
                }
                else
                {
                    _currentSample = Mathf.CeilToInt((mousePosition.x - child.x) / _toolBox.sliderValue * audioClip.samples);

                    if (!AudioUtility.IsClipPlaying(audioClip))
                    {
                        PlayClip(_currentSample);
                        PauseClip();
                    }

                    AudioUtility.SetClipSamplePosition(audioClip, _currentSample);
                }

                GUI.changed = true;
            }
        }
    }
Exemplo n.º 2
0
    private void DrawButton(Rect position, SerializedProperty prop)
    {
        var obj = prop.objectReferenceValue;

        if (obj == null)
        {
            return;
        }

        position.x     += 4;
        position.width -= 5;

        AudioClip clip = obj as AudioClip;

        Rect buttonRect = new Rect(position);

        buttonRect.width = 20;

        Rect waveformRect = new Rect(position);

        waveformRect.x     += 22;
        waveformRect.width -= 22;
        GUI.DrawTexture(waveformRect, AssetPreview.GetAssetPreview(obj));

        bool   isPlaying  = AudioUtility.IsClipPlaying(clip) && (CurrentClip == prop.propertyPath);
        string buttonText = "";
        Action <SerializedProperty, AudioClip> buttonAction;

        if (isPlaying)
        {
            EditorUtility.SetDirty(prop.serializedObject.targetObject);
            //EditorApplication.QueuePlayerLoopUpdate();
            buttonAction = GetStateInfo(ButtonState.Stop, out buttonText);

            Rect  progressRect = new Rect(waveformRect);
            float time         = AudioUtility.GetClipPosition(clip);
            float length       = clip.length;
            float progress     = time / length;
            float width        = progressRect.width * progress;
            progressRect.width = Mathf.Clamp(width, 3, width);
            GUI.Box(progressRect, "", "SelectionRect");
            DrawLabelOutline(waveformRect, TimeSpan.FromSeconds(length - time).ToString(@"mm\:ss\:fff"));
        }
        else
        {
            buttonAction = GetStateInfo(ButtonState.Play, out buttonText);
            float length = clip.length;
            DrawLabelOutline(waveformRect, TimeSpan.FromSeconds(length).ToString(@"mm\:ss\:fff"));
        }

        if (GUI.Button(buttonRect, buttonText))
        {
            AudioUtility.StopAllClips();
            buttonAction(prop, clip);
        }
    }
Exemplo n.º 3
0
        public static void SwitchEditorSkin()
        {
            System.Reflection.Assembly.GetAssembly(typeof(UnityEditorInternal.AssetStore))
            .GetType("UnityEditorInternal.InternalEditorUtility", true).GetMethod("SwitchSkinAndRepaintAllViews")
            ?.Invoke(null, null);
            EditorPrefs.SetInt(Constant.Constant.EditorPrefsKey.EditorSkin,
                               EditorPrefs.GetInt(Constant.Constant.EditorPrefsKey.EditorSkin) == 0 ? 1 : 0);
            var switchSkinSound = AssetDatabase.LoadAssetAtPath <AudioClip>(CurrentSkinType == EditorSkinType.Dark
                ? Constant.Constant.AssetPath.NightOwlDarkAudio
                : Constant.Constant.AssetPath.NightOwlLightAudio);

            if (switchSkinSound && !AudioUtility.IsClipPlaying(switchSkinSound))
            {
                AudioUtility.PlayClip(switchSkinSound);
            }
        }
Exemplo n.º 4
0
    private void DrawButton(Rect position, SerializedProperty prop)
    {
        if (prop.objectReferenceValue != null)
        {
            position.x -= 4;
            AudioClip clip = prop.objectReferenceValue as AudioClip;

            Rect buttonRect = new Rect(position);
            buttonRect.width = 20;

            Rect waveformRect = new Rect(position);
            waveformRect.x     += 22;
            waveformRect.width -= 22;
            Texture2D waveformTexture = AssetPreview.GetAssetPreview(prop.objectReferenceValue);
            if (waveformTexture != null)
            {
                GUI.DrawTexture(waveformRect, waveformTexture);
            }

            bool   isPlaying  = AudioUtility.IsClipPlaying(clip) && (CurrentClip == prop.propertyPath);
            string buttonText = "";
            Action <SerializedProperty, AudioClip> buttonAction;
            if (isPlaying)
            {
                EditorUtility.SetDirty(prop.serializedObject.targetObject);
                buttonAction = GetStateInfo(ButtonState.Stop, out buttonText);

                Rect  progressRect = new Rect(waveformRect);
                float percentage   = (float)AudioUtility.GetClipSamplePosition(clip) / AudioUtility.GetSampleCount(clip);
                float width        = progressRect.width * percentage;
                progressRect.width = Mathf.Clamp(width, 6, width);
                GUI.Box(progressRect, "", "SelectionRect");
            }
            else
            {
                buttonAction = GetStateInfo(ButtonState.Play, out buttonText);
            }

            if (GUI.Button(buttonRect, buttonText))
            {
                AudioUtility.StopAllClips();
                buttonAction(prop, clip);
            }
        }
    }
Exemplo n.º 5
0
 private void Update()
 {
     if (_isPlaying)
     {
         if (AudioUtility.IsClipPlaying(audioClip))
         {
             if (_timeSinceRepaint > 1 / _timnelineRepaintFrequency)
             {
                 _currentSample = AudioUtility.GetClipSamplePosition(audioClip);
                 Repaint();
                 _timeSinceRepaint = 0;
             }
             else
             {
                 _timeSinceRepaint += Time.deltaTime;
             }
         }
         else
         {
             StopClip();
         }
     }
 }
Exemplo n.º 6
0
    void Update()
    {
        float deltaTime = Time.realtimeSinceStartup - prevTime;

        prevTime = Time.realtimeSinceStartup;

        if (seekPosition != oldSeekPosition)
        {
            oldSeekPosition = seekPosition;

            if (!isPlaying)
            {
                if (!previewing && lsdTarget.clip != null)
                {
                    AudioUtility.PlayClip(lsdTarget.clip);
                }

                previewing = true;
                stopTimer  = 0.1f;
                prevTime   = Time.realtimeSinceStartup;
                resetTime  = seekPosition;
            }

            if (lsdTarget.clip)
            {
                AudioUtility.SetClipSamplePosition(lsdTarget.clip, (int)(seekPosition * AudioUtility.GetSampleCount(lsdTarget.clip)));
            }
        }

        if (previewing)
        {
            stopTimer -= deltaTime;
            if (lsdTarget.clip)
            {
                seekPosition    = AudioUtility.GetClipPosition(lsdTarget.clip) / lsdTarget.length;
                oldSeekPosition = seekPosition;
            }

            if (stopTimer <= 0)
            {
                previewing      = false;
                seekPosition    = resetTime;
                oldSeekPosition = seekPosition;
                if (lsdTarget.clip != null)
                {
                    AudioUtility.PauseClip(lsdTarget.clip);
                    AudioUtility.SetClipSamplePosition(lsdTarget.clip, (int)(seekPosition * AudioUtility.GetSampleCount(lsdTarget.clip)));
                }
            }
        }

        if (isPlaying && lsdTarget.clip == null)
        {
            seekPosition   += deltaTime / lsdTarget.length;
            oldSeekPosition = seekPosition;
            if (seekPosition >= 1)
            {
                isPlaying    = false;
                seekPosition = 0;
            }
        }
        else if (isPlaying)
        {
            seekPosition    = AudioUtility.GetClipPosition(lsdTarget.clip) / lsdTarget.length;
            oldSeekPosition = seekPosition;

            isPlaying = AudioUtility.IsClipPlaying(lsdTarget.clip);
        }

        if (isPlaying && visualPreview || previewing && visualPreview)
        {
            UpdatePreview(seekPosition);
        }
    }