朋友请我帮忙写一个Unity播放完视屏后执行回调的工具脚本,这个脚本可以像UnityUGUI一样在编辑器里注册事件,像Button一样拖拽注册时间。 因为里边使用了Unity的UnityEvent,话不多说,上代码! - using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
- using UnityEngine.Video;
- using UnityEngine.Events;
- public class test : MonoBehaviour
- {
- VideoPlayer video;
- /// <summary>
- /// 已经播放了
- /// </summary>
- private bool IsPlayed;
- /// <summary>
- /// 视频播放完毕后的回调事件
- /// </summary>
- [Header("在这里添加你的回调,像button一样")]
- public UnityEvent PlayOverEvent;
- private void Start()
- {
- video = GetComponent<VideoPlayer>();
- PlayOverEvent = new UnityEvent();
- PlayOverEvent.AddListener(() =>print("播放完毕回调执行!!!"));
- }
- private void Update()
- {
- if (video!=null)
- {
- if (video.isPlaying)
- {
- IsPlayed = true;
- }
- if (IsPlayed)
- {
- if (!video.isPlaying)
- {
- PlayOverEvent.Invoke();
- IsPlayed = false;
- }
- }
- }
- }
- }
复制代码 |