当前位置: 首页>>代码示例>>C#>>正文


C# tk2dCamera.GetSizeAtDistance方法代码示例

本文整理汇总了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;
			}
		}
	}
开发者ID:rlugojr,项目名称:Chromacore,代码行数:59,代码来源:tk2dCameraAnchor.cs


注:本文中的tk2dCamera.GetSizeAtDistance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。