using System.Collections.Generic;
using DotRecast.Core.Numerics;
using DotRecast.Detour;
using DotRecast.Detour.Crowd;
using Game.Logic.System;
using JNGame.Map.DotRecast;
using JNGame.Math;
using JNGame.Sync.System;
using UnityEngine;
namespace Game.JNGFrame.Logic.System
{
///
/// 地图
///
public class DMapSystem : DGBasisSystem
{
public DotRecastRoot Root;
public override void OnSyncStart()
{
base.OnSyncStart();
Root = new DotRecastRoot(GetSystem().MapData2);
Debug.Log($"DemoMapService - 加载完成地图");
}
public override void OnSyncUpdate()
{
base.OnSyncUpdate();
Root.Update(new LFloat(null,Sync.DeltaTime));
}
public DtCrowdAgentParams GetAgentParams()
{
int updateFlags = DtCrowdAgentUpdateFlags.DT_CROWD_ANTICIPATE_TURNS |
DtCrowdAgentUpdateFlags.DT_CROWD_OPTIMIZE_VIS |
DtCrowdAgentUpdateFlags.DT_CROWD_OPTIMIZE_TOPO |
DtCrowdAgentUpdateFlags.DT_CROWD_OBSTACLE_AVOIDANCE;
DtCrowdAgentParams ap = new DtCrowdAgentParams();
ap.radius = (LFloat)0.6f;
ap.height = (LFloat)2f;
ap.maxAcceleration = (LFloat)8.0f;
ap.maxSpeed = (LFloat)6f;
ap.collisionQueryRange = ap.radius * (LFloat)12f;
ap.pathOptimizationRange = ap.radius * (LFloat)30f;
ap.updateFlags = updateFlags;
ap.obstacleAvoidanceType = 0;
ap.separationWeight = (LFloat)2f;
return ap;
}
///
/// 返回最近点
///
///
///
public LVector3 GetNearbyPoints(LVector3 pos)
{
return Root.GetNearbyPoints(pos);
}
///
/// 查询导航
///
///
///
public List FindPath(LVector3 start,LVector3 end)
{
return Root.FindPath(start,end);
}
//添加避障
public void AddAgent(ulong id,LVector3 start)
{
Root.AddAgent(id,new RcVec3f(start.x,start.y,start.z));
}
public void AddAgent(ulong id,LVector3 start,DtCrowdAgentParams agentParams)
{
Root.AddAgent(id,new RcVec3f(start.x,start.y,start.z),agentParams);
}
//删除避障
public void DelAgent(ulong id)
{
Root.DelAgent(id);
}
//移动避障
public void MoveAgent(ulong id,LVector3 move)
{
Root.MoveAgent(id,new RcVec3f(move.x,move.y,move.z));
}
//向量移动避障
public void VectorMoveAgent(ulong id,LVector2 vector)
{
Root.VectorMoveAgent(id,new RcVec3f(vector.x,0,vector.y));
}
//获取避障
public DtCrowdAgent GetAgent(ulong id)
{
return Root.GetAgent(id);
}
}
}