unity3d - 如何修复 ARCore 可以同时显示的预制件数量?(带图像识别)
问题描述
当前的应用程序允许您检测海报并以海报的大小显示启动视频的平面。
我的问题是视频中有声音,例如,如果你同时看 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);
}
我的结果很奇怪,要么视频不再出现但有视频的声音,要么什么都不显示。
你能帮我吗?
解决方案
我不完全了解您的代码和设置,但我会简单地检查用户正在查看的方向与用户和图像之间的矢量之间的角度。像这样的东西
[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);
}
推荐阅读
- haskell - 如何在 Raspbian 中升级 Raspberry Pi (4) 上的堆栈?
- spring-boot - H2数据库无法转换日期
- django - Django:从重置密码页面重定向登录用户
- c - CS50 Caesar 程序 (pset2) 运行但在 check50 中输出错误(“预期退出代码 1,而不是 0”)
- python - 当我在 sklearn 中为我的目标变量使用 LabelEncoder 时,如何解码多类?
- here-api - 是否有功能请求或注意地理编码搜索结果中的差异的地方?
- reactjs - 消息输入 React 组件禁用文件上传
- c# - 平台相关执行
- php - 将计数从一个表插入到另一个表
- java - 添加新值后,ArrayList 中的所有元素都更改为最后一个值