1
This commit is contained in:
@@ -11,6 +11,8 @@ using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text;
|
||||
using UnityEngine.UIElements;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
public static partial class MathQ
|
||||
@@ -34,6 +36,22 @@ namespace BITKit
|
||||
}
|
||||
public static partial class MathV
|
||||
{
|
||||
public static Matrix4x4 Rotate(Transform self, Vector3 center, Vector3 euler)
|
||||
{
|
||||
// 计算物体与中心点的相对位置
|
||||
Vector3 relativePosition = self.position - center;
|
||||
|
||||
// 使用欧拉角来计算旋转矩阵
|
||||
Quaternion rotation = Quaternion.Euler(euler);
|
||||
|
||||
// 计算旋转后的相对位置
|
||||
Vector3 rotatedPosition = rotation * relativePosition;
|
||||
|
||||
var newPosition = center + rotatedPosition;
|
||||
var newRotation = rotation * self.rotation;
|
||||
|
||||
return Matrix4x4.TRS(newPosition, newRotation, Vector3.one);
|
||||
}
|
||||
public static Vector3 CalculateTorque(Transform transform,Quaternion targetRotation)
|
||||
{
|
||||
var deltaRot = targetRotation * Quaternion.Inverse(transform.rotation);
|
||||
@@ -157,6 +175,12 @@ namespace BITKit
|
||||
return direction.sqrMagnitude < factor; */
|
||||
return Vector3.Angle(vectorX, vectorY) < 8;
|
||||
}
|
||||
public static Vector2 TransientRotationAxis(Vector2 transientAxis)
|
||||
{
|
||||
transientAxis.x = TransientRotationAxis(transientAxis.x);
|
||||
transientAxis.y = TransientRotationAxis(transientAxis.y);
|
||||
return transientAxis;
|
||||
}
|
||||
public static Vector3 TransientRotationAxis(Vector3 transientAxis)
|
||||
{
|
||||
transientAxis.x = TransientRotationAxis(transientAxis.x);
|
||||
@@ -218,18 +242,18 @@ namespace BITKit
|
||||
}
|
||||
public static float TransientRotationAxis(this float transientAxis)
|
||||
{
|
||||
return (transientAxis %= 360) switch
|
||||
return (transientAxis %= 360f) switch
|
||||
{
|
||||
> 180 => transientAxis - 360,
|
||||
< -180 => transientAxis + 360,
|
||||
> 180f => transientAxis - 360f,
|
||||
< -180f => transientAxis + 360f,
|
||||
_ => transientAxis,
|
||||
};
|
||||
}
|
||||
public static float WrapAngle(float angle)
|
||||
{
|
||||
angle %= 360;
|
||||
if (angle > 180)
|
||||
return angle - 360;
|
||||
angle %= 360f;
|
||||
if (angle > 180f)
|
||||
return angle - 360f;
|
||||
|
||||
return angle;
|
||||
}
|
||||
@@ -455,16 +479,23 @@ namespace BITKit
|
||||
self.TryGetValue(key, out value);
|
||||
return value; ;
|
||||
}
|
||||
public static void DestoryChilds(this GameObject self)
|
||||
public static void DestoryChilds(this GameObject self,bool immediately=false)
|
||||
{
|
||||
if (self)
|
||||
if (!self) return;
|
||||
|
||||
var list = self.GetComponentsInChildren<Transform>().ToList();
|
||||
list.TryRemove(self.transform);
|
||||
foreach (var x in list)
|
||||
{
|
||||
var list = self.GetComponentsInChildren<Transform>().ToList();
|
||||
list.TryRemove(self.transform);
|
||||
list.ForEach(x =>
|
||||
if (immediately)
|
||||
{
|
||||
GameObject.Destroy(x.gameObject);
|
||||
});
|
||||
Object.DestroyImmediate(x.gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Object.Destroy(x.gameObject);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
public static bool Contains(this string self, IEnumerable<string> strs, out string key)
|
||||
|
Reference in New Issue
Block a user