主要为设置单个值
/*******************************************************************************
* 版本声明:v1.0.0
* 类 名 称:TransformExtend
* 创建日期:2019-11-29 09:59:39
* 作者名称:末零
* 功能描述:Transform扩展,主要为单项设置某个值
******************************************************************************/
using UnityEngine;
namespace LastZero
{
/// <summary>
/// Transform扩展
/// </summary>
public static class TransformExtend
{
#region Position
/// <summary>
/// 设置PositionX
/// </summary>
/// <param name="tra">物体</param>
/// <param name="x">x值</param>
public static void SetPositionX(this Transform tra, float x)
{
tra.position = new Vector3(x, tra.position.y, tra.position.z);
}
/// <summary>
/// 设置PositionY
/// </summary>
/// <param name="tra">物体</param>
/// <param name="y">y值</param>
public static void SetPositionY(this Transform tra, float y)
{
tra.position = new Vector3(tra.position.x, y, tra.position.z);
}
/// <summary>
/// 设置PositionZ
/// </summary>
/// <param name="tra">物体</param>
/// <param name="z">z值</param>
public static void SetPositionZ(this Transform tra, float z)
{
tra.position = new Vector3(tra.position.x, tra.position.y, z);
}
#endregion
#region LocalPosition
/// <summary>
/// 设置LocalPositionX
/// </summary>
/// <param name="tra">物体</param>
/// <param name="x">x值</param>
public static void SetLocalPositionX(this Transform tra, float x)
{
tra.localPosition = new Vector3(x, tra.localPosition.y, tra.localPosition.z);
}
/// <summary>
/// 设置LocalPositionY
/// </summary>
/// <param name="tra">物体</param>
/// <param name="y">y值</param>
public static void SetLocalPositionY(this Transform tra, float y)
{
tra.localPosition = new Vector3(tra.localPosition.x, y, tra.localPosition.z);
}
/// <summary>
/// 设置LocalPositionZ
/// </summary>
/// <param name="tra">物体</param>
/// <param name="z">z值</param>
public static void SetLocalPositionZ(this Transform tra, float z)
{
tra.localPosition = new Vector3(tra.localPosition.x, tra.localPosition.y, z);
}
#endregion
#region EulerAngles
/// <summary>
/// 设置EulerAnglesX
/// </summary>
/// <param name="tra">物体</param>
/// <param name="x">x值</param>
public static void SetEulerAnglesX(this Transform tra, float x)
{
tra.eulerAngles = new Vector3(x, tra.eulerAngles.y, tra.eulerAngles.z);
}
/// <summary>
/// 设置EulerAnglesY
/// </summary>
/// <param name="tra">物体</param>
/// <param name="y">y值</param>
public static void SeEulerAnglesY(this Transform tra, float y)
{
tra.eulerAngles = new Vector3(tra.eulerAngles.x, y, tra.eulerAngles.z);
}
/// <summary>
/// 设置EulerAnglesZ
/// </summary>
/// <param name="tra">物体</param>
/// <param name="z">z值</param>
public static void SetEulerAnglesZ(this Transform tra, float z)
{
tra.eulerAngles = new Vector3(tra.eulerAngles.x, tra.eulerAngles.y, z);
}
#endregion
#region LocalEulerAngles
/// <summary>
/// 设置LocalEulerAnglesX
/// </summary>
/// <param name="tra">物体</param>
/// <param name="x">x值</param>
public static void SetLocalEulerAnglesX(this Transform tra, float x)
{
tra.localEulerAngles = new Vector3(x, tra.localEulerAngles.y, tra.localEulerAngles.z);
}
/// <summary>
/// 设置LocalEulerAnglesY
/// </summary>
/// <param name="tra">物体</param>
/// <param name="y">y值</param>
public static void SetLocalEulerAnglesY(this Transform tra, float y)
{
tra.localEulerAngles = new Vector3(tra.localEulerAngles.x, y, tra.localEulerAngles.z);
}
/// <summary>
/// 设置LocalEulerAnglesZ
/// </summary>
/// <param name="tra">物体</param>
/// <param name="z">z值</param>
public static void SetLocalEulerAnglesZ(this Transform tra, float z)
{
tra.localEulerAngles = new Vector3(tra.localEulerAngles.x, tra.localEulerAngles.y, z);
}
#endregion
#region LocalScale
/// <summary>
/// 设置LocalScaleX
/// </summary>
/// <param name="tra">物体</param>
/// <param name="x">x值</param>
public static void SetLocalScaleX(this Transform tra, float x)
{
tra.localScale = new Vector3(x, tra.localScale.y, tra.localScale.z);
}
/// <summary>
/// 设置LocalScaleY
/// </summary>
/// <param name="tra">物体</param>
/// <param name="y">y值</param>
public static void SetLocalScaleY(this Transform tra, float y)
{
tra.localScale = new Vector3(tra.localScale.x, y, tra.localScale.z);
}
/// <summary>
/// 设置LocalScaleZ
/// </summary>
/// <param name="tra">物体</param>
/// <param name="z">z值</param>
public static void SetLocalScaleZ(this Transform tra, float z)
{
tra.localScale = new Vector3(tra.localScale.x, tra.localScale.y, z);
}
#endregion
}
}