TransformExtend——Transform扩展

主要为设置单个值

/*******************************************************************************
* 版本声明: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
    }
}

返回目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

末零

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值