using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; public class EffectScreen : MonoBehaviour { [SerializeField] private UnityEngine.Video.VideoPlayer mPlayer; private MeshRenderer mRender; private Color DefaultColor; private Color HideColor = new Color(0,0,0,1); void Awake() { mRender = this.gameObject.GetComponent(); DefaultColor = mRender.material.GetColor("_TintColor"); this.mRender.material.SetColor("_TintColor", HideColor); } private void OnEnable() { } private UnityEngine.Video.VideoClip clip; private float duration = 0.3f; private float startTime; public void ChangeMoive(UnityEngine.Video.VideoClip clip) { this.mRender.enabled = true; startTime = Time.realtimeSinceStartup; this.clip = clip;//先拿到要换的片 //渐进式的影藏掉原来的片 StartCoroutine(CheckHide()); } IEnumerator CheckHide() { yield return null; if (!mPlayer.isPlaying) { ClickFinish(); } else { float per = 0; while (mRender.material.GetColor("_TintColor") != HideColor) { per += Time.deltaTime / duration; this.mRender.material.SetColor("_TintColor", Color.Lerp(DefaultColor, HideColor, per)); //CDebug.Log("WaitForEndOfFrame " + (Time.realtimeSinceStartup - startTime)); yield return new WaitForEndOfFrame(); } //LeanTween.color(this.gameObject, DefaultColor, duration).setEase(LeanTweenType.animationCurve); ClickFinish(); } } private void ClickFinish() { //CDebug.Log("ClickFinish " + (Time.realtimeSinceStartup - startTime)); mPlayer.Stop(); if (this.clip == null) { return; } mPlayer.clip = this.clip; mPlayer.Play(); StartCoroutine(CheckMovie()); } IEnumerator CheckMovie() { yield return null; while(!mPlayer.isPlaying) { yield return new WaitForEndOfFrame(); } float per = 0; while (mRender.material.GetColor("_TintColor") != DefaultColor) { per += Time.deltaTime / duration; this.mRender.material.SetColor("_TintColor", Color.Lerp(HideColor, DefaultColor, per)); yield return new WaitForEndOfFrame(); } //CDebug.Log("CheckMovie End " + (Time.realtimeSinceStartup - startTime)); } }