c# - 缩小模型后 Bounds.Encapsulate 的问题
问题描述
我有 3 个滑块,它们显示了 X、Y、Z 轴的 bounds.encapsulated 值。您可以按比例缩小或放大模型,并与游戏对象的 Unity 3D 局部比例 1 成比例。
注意:GetScale()
方法获取 bounds.size 并显示到滑块。
注意: SetScale()
每次更改滑块的值时都会调用该方法并保存游戏对象 localScale。
public Vector3 GetScale()
{
combineBounds = _obj.transform.GetComponent<Renderer>().bounds;
Renderer[] renderers = _obj.transform.GetComponentsInChildren<Renderer>();
foreach (Renderer render in renderers)
{
combineBounds.Encapsulate(render.bounds);
}
Debug.Log(combineBounds.size.x);
return combineBounds.size;
}
public void SetScale()
{
float xAxis = 0.0f;
float yAxis = 0.0f;
float zAxis = 0.0f;
if (sca.x != combineBounds.size.x )
{
xAxis = 1 - (sca.x / combineBounds.size.x);
xAxis *= -1;
}
if (sca.y != combineBounds.size.y)
{
zAxis = 1 - (sca.y / combineBounds.size.y);
zAxis *= -1;
}
if (sca.z != combineBounds.size.z)
{
yAxis = 1 - (sca.z / combineBounds.size.z);
yAxis *= -1;
}
_obj.transform.localScale = new Vector3(_obj.transform.localScale.x + xAxis,
_obj.transform.localScale.y + zAxis,
_obj.transform.localScale.z + yAxis);
}
放大效果非常好。但是按比例缩小效果并不好。
解决方案
推荐阅读
- php - 显示/隐藏自定义 WordPress 菜单
- visual-studio-app-center - 微软应用中心支持百度推送吗?
- reactjs - 如何为 react-select Async 设置 defaultValue 并且在 v2.0.0 的 onBlur 时不重置?
- azure - 创建加入域的 hdinsight 集群时的问题
- excel - 如何生成具有二项分布的随机数?
- jquery - Highchart Json 与传统的 JSON 数据不同
- vb.net - call function in vb.net vs 2015
- rest - 如何使用 SharePoint 2013 REST API 从当前主要版本(非草稿)获取页面标题
- python - 如何在 numpy 中制作带有孔的网格?
- mysql - 使用 mongoDB 的最佳实践是什么?何时使用