当前的应用程序允许您检测海报并以海报的大小显示视频在其上发射的平面。
我的问题是,视频中有声音,例如,如果你同时看3张海报,你什么都不懂。
我正在尝试启用用户正在观看的视频的声音,或者限制同时显示的视频的数量(比如等待第一个视频结束后再显示另一个视频)
我目前正在使用unity 2019.1.6和arcore版本1.10.0进行android构建
我试着通过触发器使用系统,然后通过Raycast,但没有做任何事情,我仍然有声音和视频都显示出来。
[SerializeField] private VideoClip[] videoClips;
public AugmentedImage Image;
private VideoPlayer video;
void Start()
{
video = GetComponent<VideoPlayer>();
video.loopPointReached += OnStop;
}
private void OnStop(VideoPlayer source)
{
gameObject.SetActive(false);
}
void Update()
{
if (Image == null || Image.TrackingState != TrackingState.Tracking)
{
return;
}
if (!video.isPlaying)
{
video.clip = videoClips[Image.DatabaseIndex];
video.Play();
}
transform.localScale = new Vector3(Image.ExtentX - 1, Image.ExtentZ, 1);
}我有相当奇怪的结果,要么视频不再出现,但有视频的声音,要么什么都没有显示。
你能帮帮我吗?
发布于 2019-08-01 14:29:13
我不完全了解您的代码和设置,但我会简单地检查用户正在查看的方向与用户和图像之间的矢量之间的角度。例如:
[Tooltip("Angle in degrees between view direction and positions vector has to be smaller than this to activate the video")]
[SerializeField] private float angleThreshold = 20f;
// if possible already reference this via the Inspector
[SerializeField] private Camera mainCamera;
void Start()
{
if(!mainCamera) mainCamera = Camera.main;
}
void Update()
{
// get positions vector
var direction = (Image.CenterPose.position - mainCamera.transform.position).normalized;
// get view direction
var viewDirection = mainCamera.transform.forward;
// get angle between them
var angle = Vector3.Angle(viewDirection, direction);
// optionally you could use only the X axis for the angle check
// by eliminating the Y value of both vectors
// allowing the user to still look up and down
//direction = (new Vector3(Image.CenterPose.position.x, 0, Image.CenterPose.position.z) - new Vector3(mainCamera.transform.position.x, 0 , mainCamera.transform.position.z)).normalized;
//viewDirection = new Vector3(viewDirection.x, 0, viewDirection.z);
// also check the angle
if (Image == null || Image.TrackingState != TrackingState.Tracking || angle > angleThreshold)
{
// optional: I would also stop the video if no longer in focus
if (video.isPlaying && video.clip == videoClips[Image.DatabaseIndex]) video.Stop();
return;
}
if (!video.isPlaying)
{
video.clip = videoClips[Image.DatabaseIndex];
video.Play();
}
transform.localScale = new Vector3(Image.ExtentX - 1, Image.ExtentZ, 1);
}https://stackoverflow.com/questions/57301310
复制相似问题