根据以下脚本,我想要更改本地比例的简单多维数据集。
我不希望尺寸小于一定数量,所以我放入if
循环以确保这一点。
如果用户未指定最小刻度值,则起始刻度值将被视为红线。有一个选项(复选框)来决定这一点。
但是,我想知道是否有一种更简洁的方法来解决这个问题,而不是通过3个值这么笨重的循环呢?
这当然是有效的。当我运行场景并继续前后移动相机时,立方体会相应地增大/缩小,并且永远不会小于起始尺寸(如果未勾选方框)或指定的最小刻度(如果方框被勾选)我想知道这是否可以简明扼要地完成?
/// <summary>
/// Updates the size/scale of an object as the user
/// (i.e. the hololens camera) moves back and forth.
/// This script should be attached to the game object.
/// </summary>
public class ObjectScaler : MonoBehaviour
{
/// <summary>
/// In the Inspector panel, drag and drop the
/// intended object that needs to be re-sized.
/// </summary>
public GameObject _renderCamera;
/// <summary>
/// This is the minimum size that specifies
/// the object should not get smaller than this.
/// When you put this script on an object, it takes
/// the actual starting size of the object, but this way,
/// you can even specify a different size as a minimum.
/// </summary>
public float _minXScale;
public float _minYScale;
public float _minZScale;
/// <summary>
/// Should I use the defined minimm size, or should I assume
/// the actual starting object size is the minimm size?
/// If you check it, you have to provide a float for size.
/// If you leave it unchecked, the real size of the object
/// at start-up is taken as the minimum size.
/// </summary>
public bool _useTheseMinScales;
/// <summary>
/// The starting scale of the object at start-up;
/// whether it is the actual object's scale or whether
/// it is formed by _minXScale,_minYScale,_minZScale values.
/// </summary>
private Vector3 _startingScale;
/// <summary>
/// The distance between the object and holocam at start-up.
/// </summary>
private float _startingDistance;
/// <summary>
/// Current constantly-updated distance between
/// the object and holocam at any given moment.
/// </summary>
private float _currentDistance;
void Start()
{
var objectTransformPos = this.transform.position;
var cameraTransformPos = _renderCamera.transform.position;
_startingDistance = Vector3.Distance(cameraTransformPos, objectTransformPos);
_startingScale = this.transform.localScale;
}
void LateUpdate()
{
_currentDistance = Vector3.Distance(_renderCamera.transform.position, this.transform.position);
if (_useTheseMinScales)
{
if ( (_startingScale.x * (_currentDistance / _startingDistance) >= _minXScale) &&
(_startingScale.y * (_currentDistance / _startingDistance) >= _minYScale) &&
(_startingScale.z * (_currentDistance / _startingDistance) >= _minZScale) )
{
this.transform.localScale = _startingScale * (_currentDistance / _startingDistance);
}
}
else
{
if ( (_startingScale.x * (_currentDistance / _startingDistance) >= _startingScale.x) &&
(_startingScale.y * (_currentDistance / _startingDistance) >= _startingScale.y) &&
(_startingScale.z * (_currentDistance / _startingDistance) >= _startingScale.z) )
{
this.transform.localScale = _startingScale * (_currentDistance / _startingDistance);
}
}
}
}
答案 0 :(得分:1)
请勿检查尺寸,但请检查距离:
x/y/zSize
只有_startingScale
时的_startingDistance > _currentDistance
小void LateUpdate()
{
_currentDistance = Vector3.Distance(_renderCamera.transform.position, this.transform.position);
float scaleFactor = _currentDistance / _startingDistance;
if (_useTheseMinScales)
{
if ( (_startingScale.x * scaleFactor >= _minXScale) &&
(_startingScale.y * scaleFactor >= _minYScale) &&
(_startingScale.z * scaleFactor >= _minZScale) )
{
this.transform.localScale = _startingScale * scaleFactor;
}
}
else
{
if (_startingDistance > _currentDistance)
{
this.transform.localScale = _startingScale * scaleFactor;
}
}
}
。
所以解决方案如下所示:
<plugin>
<groupId>com.mysema.querydsl</groupId>
<artifactId>querydsl-maven-plugin</artifactId>
<version>${querydsl.version}</version>
<executions>
<execution>
<goals>
<goal>jpa-export</goal>
</goals>
<configuration>
<targetFolder>target/generated-sources/java</targetFolder>
<packages>
<package>com.example.domain</package>
</packages>
</configuration>
</execution>
</executions>
</plugin>