在HoloWorld中调整Canvas菜单的大小和比例 [英] Adjust Canvas Menu Size and Scale in a HoloWorld

查看:121
本文介绍了在HoloWorld中调整Canvas菜单的大小和比例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下脚本应该在世界空间中放大UI Canvas菜单,因此,随着用户走得更远,菜单的大小和比例会增大,而随着用户的接近,菜单会按比例缩小.

The following script is supposed to enlarge a UI Canvas menu in the world space, so as the user gets far, the menu grows in size and scale, and as the user approaches it, it shrinks proportionately.

实际上,我们正在尝试将菜单的高度更新为相机的平截头体高度,以便菜单始终占据相机视图的垂直高度.

We are actually trying to update the height of the menu to the camera's frustum height, so that the menu always takes up exactly the vertical height of the camera's view.

这是解决方案的方法吗?新尺寸与凸轮的截头圆锥体高度不匹配,我们在做什么呢?我们已将此脚本放在应用程序场景中的HoloLensCamera上...

Is this the way towards a solution? What are we doing wrong that the new size does not match the cam' frustum height? We have put this script on the HoloLensCamera in out app's scene...

public class Adjuster : MonoBehaviour
{
    public RectTransform _rectTransform;
    private float _ratio;
    private float _pixPerUnit = 100f;
    private Vector3 _gazeOrigin;
    private Vector3 _uiOrigin;
    private float _frustumHeight;
    private float _distance;
    public bool _reSizeCanvas;
    private Camera _camera;
    private float _canvasWidth;
    private float _canvasHeight;

    private void Start()
    {
        if (_reSizeCanvas)
        {          
            Vector2 initialSize = _rectTransform.sizeDelta;
            _ratio = _rectTransform.rect.width / _rectTransform.rect.height;
        }
    }    

    private void LateUpdate()
    {
        _gazeOrigin = transform.position;
        _uiOrigin = _rectTransform.position;
        _distance = Vector3.Distance(_gazeOrigin, _uiOrigin);
        _frustumHeight = 2.0f * _distance * Mathf.Tan( this.GetComponent<Camera>().fieldOfView * 0.5f * Mathf.Deg2Rad );    
        _rectTransform.sizeDelta = new Vector2(_ratio * _frustumHeight * _pixPerUnit, _frustumHeight * _pixPerUnit);
    }   
}

推荐答案

对某对象应用比率时.该比率是根据两件事的比较计算得出的.在这种情况下,u会将u和菜单之间的距离与u和菜单之间的基线距离进行比较.因此,您需要固定距离才能与您的实际距离进行比较.

When applying a ratio to something. That ratio is calculated based on the comparison of two things. In this case u are comparing the distance between u and the menu to a baseline distance between u and the menu. So u need fixed distance to compare your actual distance to.

截头锥体实际上是摄像头产生的圆锥形形状(尖端从摄像头开始),它将渲染此圆锥体内的任何内容.如果您不弄乱相机,它的尺寸将始终相同.如果您想获得平截头体的高度,则需要找出对象在该圆锥体中的位置.然后找出圆锥体切片的尺寸.

A frustum is literally A cone like shape that the camera spawns (with the tip starting at the camera) and it will render anything that is inside this cone. Its dimensions will always be the same if u don't mess with the camera. If u want to get frustum height involved u need to find out where the object is in that cone. Then find out the dimensions of that slice of the cone.

最简单的解决方案; 将截锥体的高度排除在外,您的解决方案就很容易了.玩家越来越接近增加规模.副版本Versa

The easiest solution; Leave the frustum height out of this and your solution is very easy; Player gets closer increase scale. Vice Versa

这篇关于在HoloWorld中调整Canvas菜单的大小和比例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆