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


C# UIRect.Set方法代码示例

本文整理汇总了C#中UIRect.Set方法的典型用法代码示例。如果您正苦于以下问题:C# UIRect.Set方法的具体用法?C# UIRect.Set怎么用?C# UIRect.Set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UIRect的用法示例。


在下文中一共展示了UIRect.Set方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateVerticalAnchor

	/// <summary>
	/// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
	/// </summary>

	static public void UpdateVerticalAnchor (UIRect r, UIRect.AnchorPoint anchor, bool resetRelative)
	{
		// Update the target
		if (anchor.target == null) return;

		// Update the rect
		anchor.rect = anchor.target.GetComponent<UIRect>();

		// Continue only if we have a parent to work with
		Transform parent = r.cachedTransform.parent;
		if (parent == null) return;

		bool inverted = (anchor == r.topAnchor);
		int i0 = inverted ? 1 : 0;
		int i1 = inverted ? 2 : 3;

		// Calculate the bottom side
		Vector3[] myCorners = r.worldCorners;
		Vector3 localPos = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f));

		if (anchor.rect != null)
		{
			// Anchored to a rectangle -- must anchor to the same side
			Vector3[] targetCorners = anchor.rect.worldCorners;

			// We want to choose the side with the shortest offset
			Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[3], 0.5f));
			Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[1], targetCorners[2], 0.5f));

			float val0 = localPos.y - side0.y;
			float val2 = localPos.y - side1.y;

			if (resetRelative)
			{
				float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y;
				anchor.SetToNearest(val0, val1, val2);
			}
			else
			{
				float val = localPos.y - Vector3.Lerp(side0, side1, anchor.relative).y;
				anchor.Set(anchor.relative, val);
			}
		}
		else if (anchor.target.camera != null)
		{
			Vector3[] sides = anchor.target.camera.GetSides(parent);
			Vector3 side0 = sides[3];
			Vector3 side1 = sides[1];

			float val0 = localPos.y - side0.y;
			float val2 = localPos.y - side1.y;

			if (resetRelative)
			{
				float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y;
				anchor.SetToNearest(val0, val1, val2);
			}
			else
			{
				float val = localPos.y - Vector3.Lerp(side0, side1, anchor.relative).y;
				anchor.Set(anchor.relative, val);
			}
		}
		else
		{
			// Anchored to a simple transform
			Vector3 remotePos = anchor.target.position;
			if (anchor.targetCam != null) remotePos = anchor.targetCam.WorldToViewportPoint(remotePos);
			if (r.anchorCamera != null) remotePos = r.anchorCamera.ViewportToWorldPoint(remotePos);
			remotePos = parent.InverseTransformPoint(remotePos);
			anchor.absolute = Mathf.FloorToInt(localPos.y - remotePos.y + 0.5f);
			anchor.relative = inverted ? 1f : 0f;
		}
	}
开发者ID:onelei,项目名称:ChatBubbleOfUnity,代码行数:78,代码来源:UIRectEditor.cs

示例2: UpdateVerticalAnchor

	/// <summary>
	/// Convenience function that switches the anchor mode and ensures that dimensions are kept intact.
	/// </summary>

	static void UpdateVerticalAnchor (UIRect r, UIRect.AnchorPoint anchor, bool relative, bool chooseClosest)
	{
		// Update the target
		if (anchor.target == null) return;

		// Update the rect
		anchor.rect = anchor.target.GetComponent<UIRect>();

		// Continue only if we have a parent to work with
		Transform parent = r.cachedTransform.parent;
		if (parent == null) return;

		bool inverted = (anchor == r.topAnchor);
		int i0 = inverted ? 1 : 0;
		int i1 = inverted ? 2 : 3;

		// Calculate the bottom side
		Vector3[] myCorners = r.worldCorners;
		Vector3 localPos = parent.InverseTransformPoint(Vector3.Lerp(myCorners[i0], myCorners[i1], 0.5f));

		if (anchor.rect == null)
		{
			// Anchored to a simple transform
			Vector3 remotePos = parent.InverseTransformPoint(anchor.target.position);
			anchor.absolute = Mathf.FloorToInt(localPos.y - remotePos.y + 0.5f);
			anchor.relative = inverted ? 1f : 0f;
		}
		else
		{
			// Anchored to a rectangle -- must anchor to the same side
			Vector3[] targetCorners = anchor.rect.worldCorners;

			if (relative)
			{
				Vector3 remotePos = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[i0], targetCorners[i1], 0.5f));
				float offset = localPos.y - remotePos.y;
				targetCorners = anchor.rect.localCorners;
				float remoteSize = targetCorners[1].y - targetCorners[0].y;

				anchor.absolute = 0;
				anchor.relative = offset / remoteSize;
				if (inverted) anchor.relative += 1f;
			}
			else
			{
				// We want to choose the side with the shortest offset
				Vector3 side0 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[0], targetCorners[3], 0.5f));
				Vector3 side1 = parent.InverseTransformPoint(Vector3.Lerp(targetCorners[1], targetCorners[2], 0.5f));

				float val0 = localPos.y - side0.y;
				float val2 = localPos.y - side1.y;
				float val1 = localPos.y - Vector3.Lerp(side0, side1, 0.5f).y;

				if (chooseClosest) anchor.SetToNearest(val0, val1, val2);
				else if (inverted) anchor.Set(1f, val2);
				else anchor.Set(0f, val0);
			}
		}
	}
开发者ID:Henry-T,项目名称:UnityPG,代码行数:63,代码来源:UIRectEditor.cs


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