Пример #1
0
	/// <summary>
	/// Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).
	/// </summary>

	static public Bounds CalculateRelativeWidgetBounds (Transform relativeTo, Transform content, ConsiderActiveType considerActiveType)
	{
		if (content != null && relativeTo != null)
		{
			bool isSet = false;
			Matrix4x4 toLocal = relativeTo.worldToLocalMatrix;
			Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
			Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);
			CalculateRelativeWidgetBounds(content, considerActiveType, true, ref toLocal, ref min, ref max, ref isSet);

			if (isSet)
			{
				Bounds b = new Bounds(min, Vector3.zero);
				b.Encapsulate(max);
				return b;
			}
		}
		return new Bounds(Vector3.zero, Vector3.zero);
	}
Пример #2
0
	static void CalculateRelativeWidgetBounds (Transform content, ConsiderActiveType considerActiveType, bool isRoot,
		ref Matrix4x4 toLocal, ref Vector3 vMin, ref Vector3 vMax, ref bool isSet)
	{
		if (content == null) return;
		if (considerActiveType == ConsiderActiveType.activeInHierarchy)
		{
			if (!NGUITools.GetActive(content.gameObject))
				return;
		}
		else if (considerActiveType == ConsiderActiveType.activeSelf)
		{
			if (!NGUITools.GetActiveSelf(content.gameObject))
				return;
		}
		if (content.GetComponent<UINoBounds>() != null) return;

		// If this isn't a root node, check to see if there is a panel present
		UIPanel p = isRoot ? null : content.GetComponent<UIPanel>();

		// Ignore disabled panels as a disabled panel means invisible children
		if (p != null && !p.enabled) return;

		// If there is a clipped panel present simply include its dimensions
		if (p != null && p.clipping != UIDrawCall.Clipping.None)
		{
			Vector3[] corners = p.worldCorners;

			for (int j = 0; j < 4; ++j)
			{
				Vector3 v = toLocal.MultiplyPoint3x4(corners[j]);

				if (v.x > vMax.x) vMax.x = v.x;
 				if (v.y > vMax.y) vMax.y = v.y;
 				if (v.z > vMax.z) vMax.z = v.z;
 
 				if (v.x < vMin.x) vMin.x = v.x;
 				if (v.y < vMin.y) vMin.y = v.y;
 				if (v.z < vMin.z) vMin.z = v.z;

				isSet = true;
			}
		}
		else // No panel present
		{
			// If there is a widget present, include its bounds
			UIWidget w = content.GetComponent<UIWidget>();

			if (w != null && w.enabled)
			{
				Vector3[] corners = w.worldCorners;

				for (int j = 0; j < 4; ++j)
				{
					Vector3 v = toLocal.MultiplyPoint3x4(corners[j]);

					if (v.x > vMax.x) vMax.x = v.x;
					if (v.y > vMax.y) vMax.y = v.y;
					if (v.z > vMax.z) vMax.z = v.z;

					if (v.x < vMin.x) vMin.x = v.x;
					if (v.y < vMin.y) vMin.y = v.y;
					if (v.z < vMin.z) vMin.z = v.z;

					isSet = true;
				}
			}

			// Iterate through children including their bounds in turn
			for (int i = 0, imax = content.childCount; i < imax; ++i)
				CalculateRelativeWidgetBounds(content.GetChild(i), considerActiveType, false, ref toLocal, ref vMin, ref vMax, ref isSet);
		}
	}
Пример #3
0
	/// <summary>
	/// Calculate the combined bounds of all widgets attached to the specified game object or its children (in relative-to-object space).
	/// </summary>

	static public Bounds CalculateRelativeWidgetBounds (Transform trans, ConsiderActiveType considerActiveType)
	{
		return CalculateRelativeWidgetBounds(trans, trans, considerActiveType);
	}