Example #1
0
            public void Play(String bgm, float fadeTime, float delayedIn, float delayedOut, bool isLoop, OnPlayEnd _onPlayEnd)
            {
                sound = new BGMSound(bgm);

                sound.Play(playable, fadeTime, delayedIn, delayedOut, isLoop);

                onPlayEnd = _onPlayEnd;
            }
Example #2
0
 private void PlayerPlayStateChange(int newState)
 {
     _playState = _player.playState == WMPPlayState.wmppsPlaying ? PlayState.Playing : PlayState.Paused;
     if (_player.playState == WMPPlayState.wmppsStopped)
     {
         OnPlayEnd?.Invoke();
     }
     else if (_player.playState == WMPPlayState.wmppsPaused)
     {
         OnPlayEnd?.Invoke();
     }
     else if (_player.playState == WMPPlayState.wmppsPlaying)
     {
         OnPlayStart?.Invoke();
     }
 }
Example #3
0
        public void Update()
        {
            // If the deltaTime was not set, update it when playing
            if (!m_DeltaTimeSet)
            {
                if (playing)
                {
                    double timeSinceStartup = EditorApplication.timeSinceStartup;
                    deltaTime             = (float)(timeSinceStartup - m_LastFrameEditorTime) * playbackSpeed;
                    m_LastFrameEditorTime = timeSinceStartup;
                }
                else
                {
                    deltaTime = 0;
                }
            }


            currentTime += deltaTime;

            // If the nextCurrentTime was set explicitly, we don't want to loop
            bool wrap = loop && playing && !m_NextCurrentTimeSet;

            if (wrap)
            {
                if (normalizedTime >= 1f)
                {
                    OnPlayEnd?.Invoke();
                }
                normalizedTime = Mathf.Repeat(normalizedTime, 1.0f);
            }
            else
            {
                if (normalizedTime > 1)
                {
                    OnPlayEnd?.Invoke();
                    playing       = false;
                    m_ResetOnPlay = true;
                }
                normalizedTime = Mathf.Clamp01(normalizedTime);
            }

            m_DeltaTimeSet       = false;
            m_NextCurrentTimeSet = false;
        }
Example #4
0
        public void Play(String bgm, float fadeInTime, float fadeOutTime, float delayedIn, float delayedOut, bool isLoop, OnPlayEnd onPlayEnd)
        {
            front.Stop(fadeOutTime, delayedIn);

            //  frontとbackいれかえ
            var tmp = back;

            back  = front;
            front = tmp;

            front.Play(bgm, fadeInTime, delayedIn, delayedOut, isLoop, onPlayEnd);
        }
Example #5
0
        public void DoTimeControl(Rect rect)
        {
            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            var evt = Event.current;
            int id  = EditorGUIUtility.GetControlID(kScrubberIDHash, FocusType.Keyboard);

            // Play/Pause Button + Scrubber
            Rect timelineRect = rect;

            timelineRect.height = kScrubberHeight;
            // Only Scrubber
            Rect scrubberRect = timelineRect;

            scrubberRect.xMin += kPlayButtonWidth;

            // Handle Input
            switch (evt.GetTypeForControl(id))
            {
            case EventType.MouseDown:
                if (rect.Contains(evt.mousePosition))
                {
                    EditorGUIUtility.keyboardControl = id;
                }
                if (scrubberRect.Contains(evt.mousePosition))
                {
                    EditorGUIUtility.SetWantsMouseJumping(1);
                    EditorGUIUtility.hotControl = id;
                    m_MouseDrag       = evt.mousePosition.x - scrubberRect.xMin;
                    nextCurrentTime   = (m_MouseDrag * (stopTime - startTime) / scrubberRect.width + startTime);
                    m_WrapForwardDrag = false;
                    evt.Use();
                }
                break;

            case EventType.MouseDrag:
                if (EditorGUIUtility.hotControl == id)
                {
                    m_MouseDrag += evt.delta.x * playbackSpeed;
                    // We want to not wrap if we immediately drag to the beginning, but we do want to wrap if we drag past the end.
                    if (loop && ((m_MouseDrag < 0.0f && m_WrapForwardDrag) || (m_MouseDrag > scrubberRect.width)))
                    {
                        // scrubing out of range was generating a big deltaTime in wrong time direction
                        // this new code prevent this and it is compliant with new and more robust v5.0 root motion looping of animation clip
                        if (m_MouseDrag > scrubberRect.width)
                        {
                            currentTime -= (stopTime - startTime);
                            OnPlayEnd?.Invoke();
                        }
                        else if (m_MouseDrag < 0)
                        {
                            currentTime += (stopTime - startTime);
                        }

                        m_WrapForwardDrag = true;
                        m_MouseDrag       = Mathf.Repeat(m_MouseDrag, scrubberRect.width);
                    }
                    nextCurrentTime = (Mathf.Clamp(m_MouseDrag, 0.0f, scrubberRect.width) * (stopTime - startTime) / scrubberRect.width + startTime);
                    evt.Use();
                }
                break;

            case EventType.MouseUp:
                if (EditorGUIUtility.hotControl == id)
                {
                    EditorGUIUtility.SetWantsMouseJumping(0);
                    EditorGUIUtility.hotControl = 0;
                    evt.Use();
                }
                break;

            case EventType.KeyDown:
                if (EditorGUIUtility.keyboardControl == id)
                {
                    // TODO: loop?
                    if (evt.keyCode == KeyCode.LeftArrow)
                    {
                        if (currentTime - startTime > kStepTime)
                        {
                            deltaTime = -kStepTime;
                        }
                        evt.Use();
                    }
                    if (evt.keyCode == KeyCode.RightArrow)
                    {
                        if (stopTime - currentTime > kStepTime)
                        {
                            deltaTime = kStepTime;
                        }
                        evt.Use();
                    }
                }
                break;
            }

            // background
            GUI.Box(timelineRect, GUIContent.none, s_Styles.timeScrubber);

            // Play/Pause Button
            playing = GUI.Toggle(timelineRect, playing, playing ? s_Styles.pauseIcon : s_Styles.playIcon, s_Styles.playButton);

            // Current time indicator
            float normalizedPosition = Mathf.Lerp(scrubberRect.x, scrubberRect.xMax, normalizedTime);

            DrawPlayhead(normalizedPosition, scrubberRect.yMin, scrubberRect.yMax, 2f, (EditorGUIUtility.keyboardControl == id) ? 1f : 0.5f);
        }