本文整理汇总了C#中UnityEngine.Transform.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Transform.ToString方法的具体用法?C# Transform.ToString怎么用?C# Transform.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Transform
的用法示例。
在下文中一共展示了Transform.ToString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindTo
/// <summary>
/// Parents (target) to this camera, and offsets the camera a size-dependent distance from the target.
/// </summary>
public void BindTo(Transform target)
{
Debug.Log("CameraController: binding to target " + target.ToString());
Renderer targetMesh = target.GetComponentInChildren<Renderer>();
//make the target our parent
transform.parent = target;
//if the target has a mesh, we can setup a displacement vector
if (targetMesh != null)
{
Debug.Log("CameraController.BindTo: found mesh " + targetMesh.name);
//since we want the target on the bottom left side of the screen,
//we want a displacement vector with positive x, positive y, and negative z
//Debug.Log ("CameraController.BindTo: mesh bounds = " + targetMesh.bounds.size);
//calculate a number representing the horiz to vert proportions
Vector3 boundsSize = targetMesh.bounds.size;
float meshAspectRatio = boundsSize.x / boundsSize.y;
Vector3 scaledMeshSize = boundsSize * DisplaceFactor;
DisplaceVec = Vector3.zero;//targetMesh.bounds.extents * displaceFactor;
//bounds should always be positive, so we only need to negate the z component
DisplaceVec.x = scaledMeshSize.x * DisplaceHorizFactor;
//DisplaceVec.z = scaledMeshSize.z * -DisplaceDepthFactor;//scaledMeshSize.z * -DisplaceDepthFactor;
//DisplaceVec.z = scaledMeshSize.z * -DisplaceDepthFactor;//scaledMeshSize.z * -DisplaceDepthFactor;
//the x displacement of the camera should put the camera at a 33 degree angle to give a nice offset to the 3rd person view
DisplaceVec.z = -Mathf.Abs(DisplaceVec.x / (Mathf.Tan(DisplaceAngle * Mathf.Deg2Rad))) * DisplaceDepthFactor;
DisplaceVec.y = scaledMeshSize.y * DisplaceVertFactor;//(DisplaceVertFactor / Mathf.Pow(scaledMeshSize.y, 2)); /// 2.0f;// * meshAspectRatio * DisplaceVertFactor;
//Debug.Log ("CameraController.BindTo: displacement vec = " + DisplaceVec.ToString());
}
//otherwise, just place the camera at the target's center
else
{
DisplaceVec = Vector3.zero;
}
//setup our new positions - first reset the camera's local position so rotations don't distort the new displacement,
cam.transform.localPosition = Vector3.zero;
transform.localPosition = Vector3.zero;
//then set our rotation and displace the camera by the vector we calculated
transform.rotation = target.rotation;
cam.transform.localPosition = DisplaceVec;
}