forked from AugmentedWorkplace/AugmentedWorkplace_VR
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExample.cs
79 lines (62 loc) · 2.51 KB
/
Example.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class Example : MonoBehaviour
{
VideoPlayer videoPlayer;
private float lastTime = 0f;
public float delayTime = 1.0f;
// Start is called before the first frame update
void Start()
{
// Will attach a VideoPlayer to the main camera.
GameObject camera = GameObject.FindWithTag("MainCamera");
// VideoPlayer automatically targets the camera backplane when it is added
// to a camera object, no need to change videoPlayer.targetCamera.
videoPlayer = camera.AddComponent<UnityEngine.Video.VideoPlayer>();
// Play on awake defaults to true. Set it to false to avoid the url set
// below to auto-start playback since we're in Start().
videoPlayer.playOnAwake = false;
// By default, VideoPlayers added to a camera will use the far plane.
// Let's target the near plane instead.
videoPlayer.renderMode = UnityEngine.Video.VideoRenderMode.CameraNearPlane;
// This will cause our Scene to be visible through the video being played.
videoPlayer.targetCameraAlpha = 0.5F;
// Set the video to play. URL supports local absolute or relative paths.
// Here, using absolute.
videoPlayer.url = "/Users/Zhu/Desktop/VideoSample1.mov";
// Skip the first 100 frames.
videoPlayer.frame = 100;
// Restart from beginning when done.
videoPlayer.isLooping = true;
// Each time we reach the end, we slow down the playback by a factor of 10.
videoPlayer.loopPointReached += EndReached;
// Start playback. This means the VideoPlayer may have to prepare (reserve
// resources, pre-load a few frames, etc.). To better control the delays
// associated with this preparation one can use videoPlayer.Prepare() along with
// its prepareCompleted event.
videoPlayer.Play();
}
void EndReached(UnityEngine.Video.VideoPlayer vp)
{
vp.playbackSpeed = vp.playbackSpeed / 10.0F;
}
public void TogglePlay()
{
if (Time.time - lastTime >= delayTime)
{
lastTime = Time.time;
if (videoPlayer.isPlaying)
{
videoPlayer.Pause();
ButtonTouch.ChangeColor(Color.yellow);
}
else
{
videoPlayer.Play();
ButtonTouch.ChangeColor(Color.green);
}
}
}
}