mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-06-26 11:24:46 +00:00
107 lines
3.2 KiB
C#
107 lines
3.2 KiB
C#
|
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
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 地图
|
|||
|
/// </summary>
|
|||
|
public class DMapSystem : DGBasisSystem
|
|||
|
{
|
|||
|
|
|||
|
public DotRecastRoot Root;
|
|||
|
|
|||
|
public override void OnSyncStart()
|
|||
|
{
|
|||
|
base.OnSyncStart();
|
|||
|
Root = new DotRecastRoot(GetSystem<DDataSystem>().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;
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 返回最近点
|
|||
|
/// </summary>
|
|||
|
/// <param name="pos"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public LVector3 GetNearbyPoints(LVector3 pos)
|
|||
|
{
|
|||
|
return Root.GetNearbyPoints(pos);
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 查询导航
|
|||
|
/// </summary>
|
|||
|
/// <param name="pos"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public List<DtStraightPath> FindPath(LVector3 start,LVector3 end)
|
|||
|
{
|
|||
|
return Root.FindPath(start,end);
|
|||
|
}
|
|||
|
|
|||
|
//添加避障
|
|||
|
public void AddAgent(long id,LVector3 start)
|
|||
|
{
|
|||
|
Root.AddAgent(id,new RcVec3f(start.x,start.y,start.z));
|
|||
|
}
|
|||
|
public void AddAgent(long id,LVector3 start,DtCrowdAgentParams agentParams)
|
|||
|
{
|
|||
|
Root.AddAgent(id,new RcVec3f(start.x,start.y,start.z),agentParams);
|
|||
|
}
|
|||
|
|
|||
|
//删除避障
|
|||
|
public void DelAgent(long id)
|
|||
|
{
|
|||
|
Root.DelAgent(id);
|
|||
|
}
|
|||
|
|
|||
|
//移动避障
|
|||
|
public void MoveAgent(long id,LVector3 move)
|
|||
|
{
|
|||
|
Root.MoveAgent(id,new RcVec3f(move.x,move.y,move.z));
|
|||
|
}
|
|||
|
|
|||
|
//向量移动避障
|
|||
|
public void VectorMoveAgent(long id,LVector2 vector)
|
|||
|
{
|
|||
|
Root.VectorMoveAgent(id,new RcVec3f(vector.x,0,vector.y));
|
|||
|
}
|
|||
|
|
|||
|
//获取避障
|
|||
|
public DtCrowdAgent GetAgent(long id)
|
|||
|
{
|
|||
|
return Root.GetAgent(id);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|