You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.0 KiB
C#
37 lines
1.0 KiB
C#
using UnityEngine;
|
|
|
|
namespace Game
|
|
{
|
|
public abstract partial class Util
|
|
{
|
|
//返回角度值(-180,180],(1,0,0)为0
|
|
//只关注y=0平面的向量
|
|
public static float Vec3ToRot(Vector3 vector)
|
|
{
|
|
var rot = Quaternion.FromToRotation(vector, Vector3.right);
|
|
return rot.eulerAngles.y;
|
|
}
|
|
public static Quaternion Rot2Quaternion(float rot)
|
|
{
|
|
return Quaternion.AngleAxis(rot, Vector3.forward);
|
|
}
|
|
/// <summary>
|
|
/// 角度转弧度
|
|
/// </summary>
|
|
/// <param name="rot"></param>
|
|
/// <returns></returns>
|
|
public static float ToRadian(float rot)
|
|
{
|
|
return rot * Mathf.PI / 180f;
|
|
}
|
|
/// <summary>
|
|
/// 弧度转角度
|
|
/// </summary>
|
|
/// <param name="rot"></param>
|
|
/// <returns></returns>
|
|
public static float ToAngle(float rot)
|
|
{
|
|
return rot * 180f / Mathf.PI;
|
|
}
|
|
}
|
|
} |