コード例 #1
0
    void OnRenderObject()
    {
        if (mAppPaused)
        {
            return;
        }

        CheckIconPlaneVisibility();

        if (!mIsInited)
        {
            if (!mInitInProgess)
            {
                mInitInProgess = true;
                StartCoroutine(InitVideoPlayer());
            }

            return;
        }

        if (isPlayableOnTexture)
        {
            // Update the video texture with the latest video frame
            VideoPlayerHelper.MediaState state = mVideoPlayer.UpdateVideoData();
            if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
            {
#if UNITY_WSA_10_0 && !UNITY_EDITOR
                // For Direct3D video texture update, we need to be on the rendering thread
                GL.IssuePluginEvent(VideoPlayerHelper.GetNativeRenderEventFunc(), 0);
#else
                GL.InvalidateState();
#endif
            }

            // Check for playback state change
            if (state != mCurrentState)
            {
                HandleStateChange(state);
                mCurrentState = state;
            }
        }
        else
        {
            // Get the current status
            VideoPlayerHelper.MediaState state = mVideoPlayer.GetStatus();
            if ((state == VideoPlayerHelper.MediaState.PLAYING) ||
                (state == VideoPlayerHelper.MediaState.PLAYING_FULLSCREEN))
            {
                GL.InvalidateState();
            }

            // Check for playback state change
            if (state != mCurrentState)
            {
                HandleStateChange(state);
                mCurrentState = state;
            }
        }
    }