本文整理汇总了C#中Bounds.Transform方法的典型用法代码示例。如果您正苦于以下问题:C# Bounds.Transform方法的具体用法?C# Bounds.Transform怎么用?C# Bounds.Transform使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bounds
的用法示例。
在下文中一共展示了Bounds.Transform方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FitToDisplay
/// <summary>
/// Scales the camera or the given "change objects" so that the given "check objects" fit into the display's comfort zone.
/// Returns the factor of scaling that was applied.
/// </summary>
/// <remarks>
/// Camera scaling can only be used if the comfort zone is None.
/// </remarks>
public float FitToDisplay(IEnumerable<GameObject> changeObjects, IEnumerable<GameObject> checkObjects, bool useCameraScaling)
{
//Make a world-space bounding box containing all of the check objects.
Bounds sceneBounds = new Bounds();
foreach (GameObject checkObject in checkObjects)
{
if (sceneBounds.extents == Vector3.zero)
sceneBounds = checkObject.transform.ComputeBounds();
else
sceneBounds.Encapsulate(checkObject.transform.ComputeBounds());
}
Bounds localDisplayBounds = _meshFilter.mesh.bounds;
if (sceneBounds.extents == Vector3.zero || localDisplayBounds.extents == Vector3.zero)
return 0.0f;
Bounds localSceneBounds = sceneBounds.Transform(transform.worldToLocalMatrix);
//Figure out the scaling required to make it fit inside the "comfort zone".
//TODO: Need to account for the fact that comfort zone will change in Static mode. Dynamic mode probably can't use this.
Vector3 localRelativeSize = new Vector3();
for (int i = 0; i < 3; ++i)
localRelativeSize[i] = localSceneBounds.size[i] / localDisplayBounds.size[i];
float scaleFactor = 1.0f / Mathf.Max(new float[] {localRelativeSize.x, localRelativeSize.y, localRelativeSize.z});
//Scale the camera or scene to apply the fit.
if (_comfortZoneMode == ComfortZoneMode.None && useCameraScaling)
{
// Scale the camera so the scene fills the comfort zone.
Physics.gravity *= scaleFactor;
float worldScale = _core.GetWorldScale() / scaleFactor;
_core.SetWorldScale(worldScale);
// Translate the camera so the scene is at the center of the comfort zone.
Vector3 cameraOffset = _camera.transform.position - transform.position;
Vector3 cameraTranslation = sceneBounds.center + 1.0f / scaleFactor * cameraOffset - _camera.transform.position;
_camera.transform.Translate(cameraTranslation, Space.World);
}
else
{
Bounds newSceneBounds = new Bounds();
foreach (GameObject changeObject in changeObjects)
{
// Scale each object so the scene will fill the comfort zone.
Utility.RecursivelyScale(changeObject, scaleFactor * Vector3.one);
changeObject.transform.localPosition *= scaleFactor;
if (newSceneBounds.extents == Vector3.zero)
newSceneBounds = changeObject.transform.ComputeBounds(true);
else
newSceneBounds.Encapsulate(changeObject.transform.ComputeBounds(true));
}
// Move the scene to the center of the comfort zone.
Vector3 offset = transform.position - newSceneBounds.center;
foreach (GameObject changeObject in changeObjects)
changeObject.transform.Translate(offset, Space.World);
}
Debug.Log("Auto-fit complete.");
return scaleFactor;
}