mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交Unity 联机Pro
This commit is contained in:
26
JNFrame2/Assets/Scripts/Game/Logic/System/DDataSystem.cs
Normal file
26
JNFrame2/Assets/Scripts/Game/Logic/System/DDataSystem.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using AppGame;
|
||||
using Game.Logic.System;
|
||||
using JNGame.Map;
|
||||
using JNGame.Map.DotRecast.Util;
|
||||
using JNGame.Sync.System;
|
||||
using Service;
|
||||
|
||||
namespace Game.JNGFrame.Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// 游戏数据
|
||||
/// </summary>
|
||||
public class DDataSystem : DGBasisSystem
|
||||
{
|
||||
|
||||
public StaticMapData MapData;
|
||||
public MeshData MapData2;
|
||||
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
MapData = App.Resource.MapData;
|
||||
MapData2 = App.Resource.MapData2;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c9d6660f75144ce84276d8536a9ffc2
|
||||
timeCreated: 1715158899
|
34
JNFrame2/Assets/Scripts/Game/Logic/System/DGBasisSystem.cs
Normal file
34
JNFrame2/Assets/Scripts/Game/Logic/System/DGBasisSystem.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.State.Tile;
|
||||
using JNGame.Sync.System;
|
||||
|
||||
namespace Game.Logic.System
|
||||
{
|
||||
public class DGBasisSystem : SLogicSystem
|
||||
{
|
||||
|
||||
public JNRandomSystem Random => GetSystem<JNRandomSystem>();
|
||||
|
||||
//判断是否是Tile模式
|
||||
public bool IsTile()
|
||||
{
|
||||
return Sync is JNSSTileServerService;
|
||||
}
|
||||
|
||||
//获取当前权限瓦块随机点
|
||||
public LVector3 GetTileRandom()
|
||||
{
|
||||
if (Sync is JNSSTileServerService tileServer)
|
||||
{
|
||||
return new LVector3(
|
||||
Random.Float(tileServer.MinContains.x,tileServer.MaxContains.x),
|
||||
LFloat.Zero,
|
||||
Random.Float(tileServer.MinContains.y,tileServer.MaxContains.y)
|
||||
);
|
||||
}
|
||||
return LVector3.Down;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c42fd1121fb849b38dc7f94db9c3f3df
|
||||
timeCreated: 1722861514
|
107
JNFrame2/Assets/Scripts/Game/Logic/System/DMapSystem.cs
Normal file
107
JNFrame2/Assets/Scripts/Game/Logic/System/DMapSystem.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f6e62838e334b6e983b238063cc2479
|
||||
timeCreated: 1715157690
|
46
JNFrame2/Assets/Scripts/Game/Logic/System/DPlayerSystem.cs
Normal file
46
JNFrame2/Assets/Scripts/Game/Logic/System/DPlayerSystem.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using DotRecast.Core.Collections;
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Logic.System
|
||||
{
|
||||
/// <summary>
|
||||
/// 玩家逻辑
|
||||
/// </summary>
|
||||
public class DPlayerSystem : DGBasisSystem
|
||||
{
|
||||
|
||||
//Node 节点
|
||||
public EDPlayer[] Nodes => NodeContext.GetHostEntities();
|
||||
public EDPlayerContext NodeContext => Contexts.GetContext<EDPlayerContext>();
|
||||
|
||||
public DInputSystem Input => GetSystem<DInputSystem>();
|
||||
|
||||
public override void OnSyncUpdate()
|
||||
{
|
||||
base.OnSyncUpdate();
|
||||
|
||||
//创建角色
|
||||
GetSystem<DInputSystem>().SInput<IDWorld>().ForEach(child =>
|
||||
{
|
||||
var key = child.Key;
|
||||
var idWorld = (IDWorld)child.Value;
|
||||
|
||||
if (idWorld != null && idWorld.IsPlayerCreate)
|
||||
{
|
||||
var entity = NodeContext.CreateEntity();
|
||||
entity.Controller.AuthBind(key);
|
||||
var spawn = new LVector3(Random.Float(0, 0),Random.Float(0, 0),Random.Float(0, 0));
|
||||
entity.Move.SetPosition(spawn);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b59673517e1408295737003f44b2690
|
||||
timeCreated: 1722224946
|
54
JNFrame2/Assets/Scripts/Game/Logic/System/DWorldSystem.cs
Normal file
54
JNFrame2/Assets/Scripts/Game/Logic/System/DWorldSystem.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Linq;
|
||||
using Game.Input;
|
||||
using Game.JNGFrame.Logic.Entity;
|
||||
using Game.JNGFrame.Logic.Entity.Contexts;
|
||||
using Game.Logic.System;
|
||||
using JNGame.Math;
|
||||
using JNGame.Sync.Frame.Service;
|
||||
using JNGame.Sync.System;
|
||||
|
||||
namespace Game.JNGFrame.Logic.System
|
||||
{
|
||||
public class DWorldSystem : DGBasisSystem
|
||||
{
|
||||
|
||||
//Node 节点
|
||||
public EDNode[] Nodes => NodeContext.GetHostEntities();
|
||||
public EDNodeContext NodeContext => Contexts.GetContext<EDNodeContext>();
|
||||
|
||||
public override void OnSyncUpdate()
|
||||
{
|
||||
|
||||
base.OnSyncUpdate();
|
||||
if (GetSystem<DInputSystem>().SInputOne<IDWorld>() is not IDWorld { IsAdd: true }) return;
|
||||
|
||||
//超过500 则 销毁第一个实体
|
||||
if (Nodes.Length >= 100)
|
||||
{
|
||||
var node = Nodes[0];
|
||||
node.Destroy();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var max = 100;
|
||||
if (IsTile())
|
||||
{
|
||||
var entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
|
||||
entity.Move.SetPosition(GetTileRandom());
|
||||
entity.Move.Go(GetTileRandom());
|
||||
}
|
||||
else
|
||||
{
|
||||
var entity = Contexts.GetContext<EDNodeContext>().CreateEntity();
|
||||
var spawn = new LVector3(Random.Float(0, max),Random.Float(0, 100),Random.Float(0, max));
|
||||
entity.Move.SetPosition(spawn);
|
||||
spawn = new LVector3(Random.Float(0, max),Random.Float(0, 100),Random.Float(0, max));
|
||||
entity.Move.Go(spawn);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 00e91648e3cd42a8ae1399000b88fdd6
|
||||
timeCreated: 1712720318
|
Reference in New Issue
Block a user