Archived
Emergency backup
This commit is contained in:
@@ -1,20 +1,19 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR;
|
||||
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
namespace XericLibrary.Runtime.CollisionLOD
|
||||
{
|
||||
/// <summary>
|
||||
/// 盒体的AABB碰撞器
|
||||
/// </summary>
|
||||
public class LodBoxCollider : LodColliderBase
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 启用轴向
|
||||
/// </summary>
|
||||
public Bool3 EnableCollisionAxis = new Bool3(1,0,1);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生命周期
|
||||
@@ -25,9 +24,38 @@ namespace XericLibrary.Runtime.CollisionLOD
|
||||
|
||||
#region 碰撞检测
|
||||
|
||||
private bool CheckCollision()
|
||||
private static bool CheckCollision(LodBoxCollider box1, LodBoxCollider box2)
|
||||
{
|
||||
return false;
|
||||
var box1max = box1.BoundSize.max;
|
||||
var box1min = box1.BoundSize.min;
|
||||
var box2max = box2.BoundSize.max;
|
||||
var box2min = box2.BoundSize.min;
|
||||
|
||||
bool collidX = box1max.x >= box2min.x
|
||||
&& box2max.x >= box1min.x;
|
||||
bool collidY = box1max.y >= box2min.y
|
||||
&& box2max.y >= box1min.y;
|
||||
bool collidZ = box1max.z >= box2min.z
|
||||
&& box2max.z >= box1min.z;
|
||||
|
||||
bool enableCollidX = box1.EnableCollisionAxis.x
|
||||
&& box2.EnableCollisionAxis.x;
|
||||
bool enableCollidY = box1.EnableCollisionAxis.y
|
||||
&& box2.EnableCollisionAxis.y;
|
||||
bool enableCollidZ = box1.EnableCollisionAxis.z
|
||||
&& box2.EnableCollisionAxis.z;
|
||||
|
||||
if(!(enableCollidX && enableCollidY && enableCollidZ))
|
||||
return false;
|
||||
|
||||
bool rescollidX = enableCollidX && collidX
|
||||
|| (!enableCollidX && (collidY || collidZ));
|
||||
bool rescollidY = enableCollidY && collidY
|
||||
|| (!enableCollidY && (collidX || collidZ));
|
||||
bool rescollidZ = enableCollidZ && collidZ
|
||||
|| (!enableCollidZ && (collidX || collidY));
|
||||
|
||||
return rescollidX && rescollidY && rescollidZ;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -2,11 +2,44 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.MacroLibrary;
|
||||
|
||||
namespace XericLibrary.Runtime.CollisionLOD
|
||||
{
|
||||
public class LodSphereCollider : LodColliderBase
|
||||
{
|
||||
|
||||
}
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 半径
|
||||
/// </summary>
|
||||
private float radius;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 碰撞检测
|
||||
|
||||
private static bool CheckCollision(LodSphereCollider sphere1, LodSphereCollider sphere2)
|
||||
{
|
||||
return Vector3.Distance(sphere1.BoundSize.center, sphere2.BoundSize.center)
|
||||
< sphere1.radius + sphere2.radius;
|
||||
|
||||
}
|
||||
|
||||
private static bool CheckCollision(LodSphereCollider sphere, LodBoxCollider box)
|
||||
{
|
||||
/*
|
||||
* 对于任意AABB和圆的最近点的计算:
|
||||
* 获取圆心C与AABB中心B的偏移量D
|
||||
* 用AABB的范围去限制这个偏移量
|
||||
* 此时矢量总是位于AABB的边缘处
|
||||
*/
|
||||
return (sphere.BoundSize.center - box.BoundSize.center)
|
||||
.Clamp(box.BoundSize.min, box.BoundSize.max)
|
||||
.Add(box.BoundSize.center)
|
||||
.Distance(sphere.BoundSize.center) <= sphere.radius;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,6 +57,11 @@ namespace XericLibrary.Runtime.CollisionLOD
|
||||
/// </summary>
|
||||
public Bounds BoundSize;
|
||||
|
||||
/// <summary>
|
||||
/// 启用轴向
|
||||
/// </summary>
|
||||
public Bool3 EnableCollisionAxis = new Bool3(1,0,1);
|
||||
|
||||
/// <summary>
|
||||
/// 碰撞器集合
|
||||
/// </summary>
|
||||
@@ -98,7 +103,7 @@ namespace XericLibrary.Runtime.CollisionLOD
|
||||
private void MakeLevelLinearArray(List<LodColliderBase> genList)
|
||||
{
|
||||
genList.Sort();
|
||||
int seqIndex = 0;
|
||||
int seqIndex = 1;
|
||||
foreach(var item in genList)
|
||||
item.SeqLevels = seqIndex++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user