12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Video;
- public class VideoPlayerPlane : MonoBehaviour {
- [SerializeField]private Transform m_TransCamera = null;
- [SerializeField] float m_ActiveDistance = 10.0f;
- private VideoPlayer m_VideoPlayer = null;
- private MeshRenderer m_MeshRenderer = null;
- private float m_Distance = 0;
- private Transform m_Trans = null;
- private void Awake() {
- m_VideoPlayer = this.GetComponent<VideoPlayer>();
- m_MeshRenderer = this.GetComponent<MeshRenderer>();
- m_Trans = transform;
- if (m_MeshRenderer != null)
- m_MeshRenderer.enabled = false;
- if (m_VideoPlayer != null)
- m_VideoPlayer.Stop();
- }
- private void OnEnable() {
- StartCoroutine(EnumCheckDistance());
- }
- private void OnDisable() {
- StopAllCoroutines();
- }
- IEnumerator EnumCheckDistance() {
- while (true) {
- yield return new WaitForSeconds(1.0f);
- m_Distance = Vector3.Distance(m_Trans.position, m_TransCamera.position);
- Debug.LogFormat("\"{0}\" 距离:{1}", name, m_Distance);
- if (m_Distance <= m_ActiveDistance) {
- ActiveVideoPlayer();
- } else {
- DeactiveVideoPlayer();
- }
- }
- }
- void ActiveVideoPlayer() {
- if (m_MeshRenderer != null)
- m_MeshRenderer.enabled = true;
- if (m_VideoPlayer != null)
- m_VideoPlayer.Play();
- }
- void DeactiveVideoPlayer() {
- if (m_MeshRenderer != null)
- m_MeshRenderer.enabled = false;
- if (m_VideoPlayer != null)
- m_VideoPlayer.Stop();
- }
- }
|