示例#1
0
    /// <summary>
    /// Animating the changes of alpha value.
    /// The position and scale is changed by the parent object.
    /// </summary>
    /// <param name="videoPlayerObj"></param>
    /// <param name="status"></param>
    /// <param name="videoID"></param>
    /// <returns></returns>
    public IEnumerator VideoFade(GameObject videoPlayerObj, ChildObjFadeStatus status, string videoID = "")
    {
        HighQualityPlayback videoPlayer     = videoPlayerObj.GetComponent <HighQualityPlayback>();
        VideoController     videoController = videoPlayerObj.GetComponent <VideoController>();
        MeshRenderer        videoRenderer   = videoPlayerObj.GetComponent <MeshRenderer>();
        Material            videoMaterial   = videoRenderer.material;

        Debug.Log(string.Format("Video Event:{0}, {1}", videoPlayerObj.name, status));

        if (status == ChildObjFadeStatus.CLOSE)
        {
            videoController.Stop();

            for (float i = CANVAS_CLOSE_TIME; i >= 0; i -= Time.deltaTime)
            {
                float percentage = i / CANVAS_CLOSE_TIME;
                //videoPlayerObj.transform.localScale = VIDEO_SCALE * percentage;
                videoMaterial.color = new Color(videoMaterial.color.r, videoMaterial.color.g, videoMaterial.color.b, percentage);
                yield return(null);
            }
            videoPlayerObj.SetActive(false);
        }
        else if (status == ChildObjFadeStatus.OPEN && videoID.Length > 0)
        {
            videoPlayerObj.SetActive(true);

            for (float i = 0; i <= CANVAS_OPEN_TIME; i += Time.deltaTime)
            {
                float percentage = i / CANVAS_OPEN_TIME;
                //videoPlayerObj.transform.localScale = VIDEO_SCALE * percentage;
                videoMaterial.color = new Color(videoMaterial.color.r, videoMaterial.color.g, videoMaterial.color.b, percentage);
                yield return(null);
            }
            videoPlayer.PlayYoutubeVideo(videoID);
        }
        else if (status == ChildObjFadeStatus.CLOSE_AND_OPEN && videoID.Length > 0)
        {
            videoController.Stop();

            videoPlayer.PlayYoutubeVideo(videoID);
        }
    }
    /// <summary>
    /// Play a video on the screen
    /// </summary>
    /// <param name="url">the url of the video on youtube or the file path</param>
    /// <param name="frontscreen">true if the video should be played on the front screen (element 0 in camras array), false to show it on the floor screen (element 1 in camras array)</param>
    public void PlayFromInput(string url, bool frontscreen)
    {
        if (frontscreen)
        {
            player.targetCamera = cameras[0];
        }
        else
        {
            player.targetCamera = cameras[1];
        }

        if (url != null && url != "")
        {
            path = url;
        }
        else
        {
            return;
        }
        //search for the low quality if not find search for highquality
        if (playersimpleFront != null)
        {
            player.targetCameraAlpha = 1;
            playersimpleFront.PlayYoutubeVideo(path);
            playersimpleFront.unityVideoPlayer.loopPointReached += OnVideoFinished;
        }
        else if (playerhighquality != null)
        {
            player.targetCameraAlpha = 1;
            playerhighquality.PlayYoutubeVideo(path);
            playerhighquality.unityVideoPlayer.loopPointReached += OnVideoFinished;
        }


        if (frontscreen)
        {
            canvases[0].SetActive(false);
        }
        else
        {
            canvases[1].SetActive(false);
        }
    }