Archived
126 lines
2.1 KiB
C#
126 lines
2.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
using UnityEditor;
|
|
|
|
using UnityEngine;
|
|
|
|
using XericLibrary.Runtime.Type;
|
|
|
|
namespace XericLibrary.Runtime.CollisionLOD
|
|
{
|
|
/// <summary>
|
|
/// 具有基本缩放的碰撞器基类
|
|
/// </summary>
|
|
public abstract class LodColliderBase : WeaklyMonoBase , IComparable
|
|
{
|
|
/*
|
|
* 碰撞体需要及时性,不建议使用协程,异步等方法处理事件
|
|
*/
|
|
|
|
#region 静态成员
|
|
|
|
#region 字段属性
|
|
|
|
/// <summary>
|
|
/// 碰撞处理流程
|
|
/// </summary>
|
|
protected static ProgramFlowLinear ProgramFlow;
|
|
|
|
#endregion
|
|
|
|
#region 静态方法
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
#endregion
|
|
|
|
#region 字段属性
|
|
|
|
/// <summary>
|
|
/// 处理等级
|
|
/// </summary>
|
|
public int SeqLevels = -1;
|
|
|
|
/// <summary>
|
|
/// 表示序列等级是否不需要处理
|
|
/// </summary>
|
|
[SerializeField]
|
|
private bool noInitializationRequired = false;
|
|
|
|
/// <summary>
|
|
/// 盒体尺寸信息
|
|
/// </summary>
|
|
public Bounds BoundSize;
|
|
|
|
/// <summary>
|
|
/// 启用轴向
|
|
/// </summary>
|
|
public Bool3 EnableCollisionAxis = new Bool3(1,0,1);
|
|
|
|
/// <summary>
|
|
/// 碰撞器集合
|
|
/// </summary>
|
|
private List<LodColliderBase> allLodColliderList = null;
|
|
|
|
#endregion
|
|
|
|
#region 生命周期
|
|
|
|
private void OnValidate()
|
|
{
|
|
noInitializationRequired = true;
|
|
|
|
var allColliders = transform.GetComponents<LodColliderBase>();
|
|
if(SeqLevels < 0)
|
|
SeqLevels = allColliders.Length;
|
|
|
|
var genList = allColliders.ToList();
|
|
MakeLevelLinearArray(genList);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
if(noInitializationRequired)
|
|
return;
|
|
// 动态添加的处理
|
|
//allLodColliderList = transform.GetComponents<LodColliderBase>()
|
|
//.ToList();
|
|
//MakeLevelLinearArray(allLodColliderList);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 方法
|
|
|
|
/// <summary>
|
|
/// 使列表等级完全不重复
|
|
/// </summary>
|
|
private void MakeLevelLinearArray(List<LodColliderBase> genList)
|
|
{
|
|
genList.Sort();
|
|
int seqIndex = 1;
|
|
foreach(var item in genList)
|
|
item.SeqLevels = seqIndex++;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region 接口
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if(obj is LodColliderBase lod)
|
|
return SeqLevels.CompareTo(lod.SeqLevels);
|
|
else
|
|
return this.CompareTo(obj);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|