1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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<MeshRenderer>();
- 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));
- }
- }
|