* 作者:闪电Y黑客
* 日期: 2019.7.23
* 功能:平滑和限制数值
* 注:可以自己写一个自己适用的,只要接上 I_TouchMotor 接口就能赋值给 TouchTransform
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using SDHK_Tool.Component;
using SDHK_Tool.Dynamic;
/*
* 作者:闪电Y黑客
*
* 日期: 2019.7.23
*
* 功能:平滑和限制数值
*
* 注:可以自己写一个自己适用的,只要接上 I_TouchMotor 接口就能赋值给 TouchTransform
*
*/
namespace SDHK_Tool.Component
{
/// <summary>
/// 触摸电机
/// </summary>
public class SC_TouchMotor : MonoBehaviour, SI_TouchMotor
{
[Tooltip("要服务的触摸计算器")]
public SC_TouchTransform TouchTransform;
[Space()]
[Space()]
/// <summary>
/// 缩放限制激活
/// </summary>
[Tooltip("缩放限制激活")]
public bool LimitZoom = false;
/// <summary>
/// 缩放平滑速度
/// </summary>
[Tooltip("缩放平滑速度:越小越快")]
public float MotorSpeed_Zoom = 0.05f;
/// <summary>
/// 缩放尺寸限制
/// </summary>
[Tooltip("缩放尺寸限制值")]
public Vector2 Limit_Size_Zoom;
[Space()]
[Space()]
/// <summary>
/// 旋转限制激活
/// </summary>
[Tooltip("旋转限制激活")]
public bool LimitRotation = false;
/// <summary>
/// 旋转平滑速度
/// </summary>
[Tooltip("旋转平滑速度:越小越快")]
public float MotorSpeed_Rotation = 0.05f;
/// <summary>
/// 旋转角度限制
/// </summary>
[Tooltip("旋转角度限制值")]
public Vector2 Limit_Size_Rotation;
[Space()]
[Space()]
/// <summary>
/// 移动限制激活
/// </summary>
[Tooltip("移动限制激活")]
public bool LimitMobile = false;
/// <summary>
/// 移动平滑速度
/// </summary>
[Tooltip("移动平滑速度:越小越快")]
public float MotorSpeed_Mobile = 0.05f;
/// <summary>
/// 移动限制最小值
/// </summary>
[Tooltip("移动位置限制最小值")]
public Vector2 Limit_Size_MobileMin;
/// <summary>
/// 移动限制最大值
/// </summary>
[Tooltip("移动位置限制最大值")]
public Vector2 Limit_Size_MobileMax;
private Vector3 SaveScale;//保存初始化尺寸
private SD_Motor_Vector3 MotorZoom;
private SD_Motor_Vector2 MotorMobile;
private SD_Motor_Angle MotorRotation;
private void Awake()
{
TouchTransform.Set_TouchMotor(this); //初始化设置 触摸计算器的电机为自己 (应该为状态设计模式)
SaveScale = transform.lossyScale; //保存物体初始尺寸
MotorZoom = new SD_Motor_Vector3() //初始化缩放电机值
.Set_MotorValue(transform.lossyScale);
MotorMobile = new SD_Motor_Vector2() //初始化移动电机值
.Set_MotorValue(transform.position);
MotorRotation = new SD_Motor_Angle() //初始化旋转电机值
.Set_MotorValue(transform.eulerAngles.z);
}
public float TouchMortor_Rotation(float TargetAngle)
{
return MotorRotation
.SetTarget_Angle(TargetAngle) //电机目标设置
.Set_MotorConstraint(LimitRotation) //电机限制器激活
.Set_MotorConstraint_Limit(Limit_Size_Rotation.x, Limit_Size_Rotation.y)//电机限制范围设置
.Set_MotorSpeed(MotorSpeed_Rotation) //电机速度设置
.Run_SmoothDampAngle() //电机运行平滑移动
.Constraint_Angle_Complete_Local() //电机进行本地全面角度限制
.Get_MotorSave() //获取电机的角度
;
}
public Vector2 TouchMortor_Mobile(Vector2 TargetPosition)
{
return MotorMobile
.SetTarget_Vector(TargetPosition)
.Set_MotorConstraint(LimitMobile)
.Set_MotorConstraint_Limit(Limit_Size_MobileMin, Limit_Size_MobileMax)
.Set_MotorSpeed(MotorSpeed_Mobile)
.Run_SmoothDamp()
.Constraint_Vector_Local()
.Get_MotorSave()
;
}
public Vector3 TouchMortor_Zoom(Vector3 TargetScale)
{
return MotorZoom
.SetTarget_Vector(TargetScale)
.Set_MotorConstraint(LimitZoom)
.Set_MotorConstraint_Limit(Limit_Size_Zoom.x * SaveScale, Limit_Size_Zoom.y * SaveScale)
.Set_MotorSpeed(MotorSpeed_Zoom)
.Run_SmoothDamp()
.Constraint_Vector_Local()
.Get_MotorSave()
;
}
}
}