本文整理汇总了C#中tk2dCamera.GetSizeAtDistance方法的典型用法代码示例。如果您正苦于以下问题:C# tk2dCamera.GetSizeAtDistance方法的具体用法?C# tk2dCamera.GetSizeAtDistance怎么用?C# tk2dCamera.GetSizeAtDistance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tk2dCamera
的用法示例。
在下文中一共展示了tk2dCamera.GetSizeAtDistance方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateTransform
void UpdateTransform()
{
// Break out if anchor camera is not bound
if (AnchorCamera == null) {
return;
}
float pixelScale = 1; // size of one pixel
Vector3 position = myTransform.localPosition;
// we're ignoring perspective tk2dCameras for now
tk2dCamera = (AnchorTk2dCamera != null && AnchorTk2dCamera.CameraSettings.projection != tk2dCameraSettings.ProjectionType.Perspective) ? AnchorTk2dCamera : null;
Rect rect = new Rect();
if (tk2dCamera != null) {
rect = anchorToNativeBounds ? tk2dCamera.NativeScreenExtents : tk2dCamera.ScreenExtents;
pixelScale = tk2dCamera.GetSizeAtDistance( 1 );
}
else {
rect.Set(0, 0, AnchorCamera.pixelWidth, AnchorCamera.pixelHeight);
}
float y_bot = rect.yMin;
float y_top = rect.yMax;
float y_ctr = (y_bot + y_top) * 0.5f;
float x_lhs = rect.xMin;
float x_rhs = rect.xMax;
float x_ctr = (x_lhs + x_rhs) * 0.5f;
Vector3 anchoredPosition = Vector3.zero;
switch (AnchorPoint)
{
case tk2dBaseSprite.Anchor.UpperLeft: anchoredPosition = new Vector3(x_lhs, y_top, position.z); break;
case tk2dBaseSprite.Anchor.UpperCenter: anchoredPosition = new Vector3(x_ctr, y_top, position.z); break;
case tk2dBaseSprite.Anchor.UpperRight: anchoredPosition = new Vector3(x_rhs, y_top, position.z); break;
case tk2dBaseSprite.Anchor.MiddleLeft: anchoredPosition = new Vector3(x_lhs, y_ctr, position.z); break;
case tk2dBaseSprite.Anchor.MiddleCenter: anchoredPosition = new Vector3(x_ctr, y_ctr, position.z); break;
case tk2dBaseSprite.Anchor.MiddleRight: anchoredPosition = new Vector3(x_rhs, y_ctr, position.z); break;
case tk2dBaseSprite.Anchor.LowerLeft: anchoredPosition = new Vector3(x_lhs, y_bot, position.z); break;
case tk2dBaseSprite.Anchor.LowerCenter: anchoredPosition = new Vector3(x_ctr, y_bot, position.z); break;
case tk2dBaseSprite.Anchor.LowerRight: anchoredPosition = new Vector3(x_rhs, y_bot, position.z); break;
}
Vector3 screenAnchoredPosition = anchoredPosition + new Vector3(pixelScale * offset.x, pixelScale * offset.y, 0);
if (tk2dCamera == null) { // not a tk2dCamera, we need to transform
Vector3 worldAnchoredPosition = AnchorCamera.ScreenToWorldPoint( screenAnchoredPosition );
if (myTransform.position != worldAnchoredPosition) {
myTransform.position = worldAnchoredPosition;
}
}
else {
Vector3 oldPosition = myTransform.localPosition;
if (oldPosition != screenAnchoredPosition) {
myTransform.localPosition = screenAnchoredPosition;
}
}
}