假设我的目标是使用Touch类获得swipe移动的长度。
使用以下命令有什么区别
if(touchPhase == touchPhase.Began)
{
touchStart = touch.Position;
}
else if(touchPhase == touchPhase.Ended) {
Vector2 length = touch.Position - touchStart;
}和
if(touchPhase == touchPhase.Ended) {
Vector2 length = touch.RawPosition - touch.Position;
}从文档中可以看出,当拖动触摸触点时,rawPosition不会改变,因此代码应该可以工作。
我需要一个小小的解释。
谢谢
发布于 2021-04-21 23:37:08
据我所知,行为应该是平等的。正如你所说的,Touch.RawPosition就是
触摸触点在屏幕空间像素坐标中的第一个位置。
原始位置返回触摸接触的原始位置,并且在拖动触摸时不会更改。如果您需要触摸的当前位置,请参阅Touch.position。
除了第二个代码片段中的之外,应该是
Vector2 length = touch.Position - touch.RawPosition;增量始终是当前位置减去之前的位置。
你可以简单地使用下面的命令来验证自己。
// In general rather use switch for enums
switch(touchPhase)
{
case TouchPhase.Began:
touchStart = touch.Position;
break;
case TouchPhase.Ended:
Debug.Assert(touchStart == touch.RawPosition, "Not equal :O", this);
Vector2 length = touch.Position - touchStart;
Vector2 length2 = touch.Position - touch.RawPosition;
// Obviously redundant - if the first assert already passed then this will as well
Debug.Assert(length == length2, "Not equal :O", this)
break;
}https://stackoverflow.com/questions/67193280
复制相似问题