提交Unity 联机Pro

This commit is contained in:
PC-20230316NUNE\Administrator
2024-08-17 14:27:18 +08:00
parent f00193b000
commit 894100ae37
7448 changed files with 854473 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4f606ce125c442629b63f210beeabaa2
timeCreated: 1712734968

View File

@@ -0,0 +1,15 @@
using Entitas;
using Game.JNGFrame.Logic.Entity.Contexts;
using JNGame.Sync.Entity;
using JNGame.Sync.Frame.Entity;
using JNGame.Sync.State.Tile.Entity;
namespace Game.JNGFrame.Logic.Entity
{
public class EDContexts : JNTileContexts
{
public override IContext[] allContexts { get; } = { new EDNodeContext(),new EDPlayerContext() };
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dfdb770e32914215b20ea0b4722157cf
timeCreated: 1712736751

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f3cfa4711bbd4f9792fbc3070838c8f5
timeCreated: 1720855417

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ce99e4925cfe4cf6a4551f4bc4e07fdc
timeCreated: 1720749441

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a0bc49819e5242139ad5104c369b8c82
timeCreated: 1720864794

View File

@@ -0,0 +1,114 @@
using DotRecast.Detour.Crowd;
using Game.JNGFrame.Logic.System;
using JNGame.Math;
using JNGame.Sync.Entity.Component;
using JNGame.Sync.State.Tile.Entity.Component;
namespace Game.JNGFrame.Logic.Entity.Components
{
/// <summary>
/// 移动组件
/// </summary>
public class EDMoveComponent : JNTileComponent
{
public DMapSystem Map => GetSystem<DMapSystem>();
/// <summary>
/// 避障配置
/// </summary>
private DtCrowdAgentParams _info;
/// <summary>
/// 移动速度
/// </summary>
private LFloat _speed = LFloat.One;
public LFloat Speed
{
get => _speed;
set
{
_speed = value;
_info.maxSpeed = _speed;
_info.maxAcceleration = _info.maxSpeed * 4;
}
}
public override void OnSyncStart()
{
base.OnSyncStart();
_info = Map.GetAgentParams();
Speed = Speed;
AddAgent();
}
public override void OnTileEnter()
{
base.OnTileEnter();
AddAgent();
}
public override void OnTileExit()
{
base.OnTileExit();
DelAgent();
}
/// <summary>
/// 添加避障
/// </summary>
public void AddAgent()
{
if(IsHost) Map.AddAgent(Entity.Id,Entity.Position,_info);
}
/// <summary>
/// 删除避障
/// </summary>
public void DelAgent()
{
Map.DelAgent(Entity.Id);
}
/// <summary>
/// 设置位置
/// </summary>
/// <param name="spawn"></param>
public void SetPosition(LVector3 spawn)
{
Entity.Transform.Position = Map.GetNearbyPoints(spawn);
DelAgent();
AddAgent();
}
/// <summary>
/// 设置移动目标
/// </summary>
public void Go(LVector3 spawn)
{
Map.MoveAgent(Entity.Id, Map.GetNearbyPoints(spawn));
}
/// <summary>
/// 向量移动
/// </summary>
public void Vector(LVector2 vector)
{
Map.VectorMoveAgent(Entity.Id, vector * Speed);
}
public override void OnSyncUpdate()
{
base.OnSyncUpdate();
var npos = Map.GetAgent(Entity.Id).npos;
Entity.Transform.Position = new LVector3((LFloat)npos.X, (LFloat)npos.Y, (LFloat)npos.Z);
}
public override void OnSyncDestroy()
{
base.OnSyncDestroy();
DelAgent();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d0346ed1171e4add9c2dd1f43d7d13d7
timeCreated: 1720864691

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7a0c80afea4d4209bb59b4725c030013
timeCreated: 1723013031

View File

@@ -0,0 +1,58 @@
using Game.Input;
using Game.JNGFrame.Logic.Entity.Components;
using JNGame.Math;
using JNGame.Sync.State.Tile.Entity.Component;
namespace Game.JNGFrame.Logic.Entity.Controller
{
/// <summary>
/// 角色控制器
/// </summary>
public class EDPlayerController : JNTileComponent
{
/// <summary>
/// 权限Id
/// </summary>
private int _auth;
public int Auth => _auth;
public DInputSystem Input => GetSystem<DInputSystem>();
public EDMoveComponent Move => Entity.GetComponent<EDMoveComponent>();
/// <summary>
/// 绑定权限
/// </summary>
/// <param name="id"></param>
public void AuthBind(int id)
{
_auth = id;
}
public override void OnSyncStart()
{
base.OnSyncStart();
Move.Speed = LFloat.L10;
}
public override void OnSyncUpdate()
{
base.OnSyncUpdate();
OnMoveUpdate();
}
/// <summary>
/// 移动更新
/// </summary>
private void OnMoveUpdate()
{
if (Input.SInput<IDPlayer>(Auth) is not IDPlayer input || input.MoveVector is null) return;
Move.Vector(input.MoveVector.ToLVector2());
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2d63a18dd1f04046ac493221c82130e8
timeCreated: 1723013044

View File

@@ -0,0 +1,25 @@
using System;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Util.Types;
namespace Game.JNGFrame.Logic.Entity.Components
{
public class EDNodeLookup : JNEntityLookup
{
//移动组件
public int Movement { get; set; }
protected override void BindIndex()
{
base.BindIndex();
Movement = Next();
}
protected override void BindType(KeyValue<int, Type> types)
{
base.BindType(types);
types.Add(Movement,typeof(EDMoveComponent));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: aeea4b9b15934aba9d557d99f16c4d3f
timeCreated: 1720749462

View File

@@ -0,0 +1,31 @@
using System;
using Game.JNGFrame.Logic.Entity.Controller;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Util.Types;
using UnityEngine;
namespace Game.JNGFrame.Logic.Entity.Components
{
public class EDPlayerLookup : JNEntityLookup
{
//移动组件
public int Movement { get; set; }
public int Controller { get; set; }
protected override void BindIndex()
{
base.BindIndex();
Movement = Next();
Controller = Next();
}
protected override void BindType(KeyValue<int, Type> types)
{
base.BindType(types);
types.Add(Movement,typeof(EDMoveComponent));
types.Add(Controller,typeof(EDPlayerController));
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df072d4041fb497cb8122a7449c04455
timeCreated: 1722225086

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ab58dfb4e61e45d587eb9695240e9cbc
timeCreated: 1712737231

View File

@@ -0,0 +1,16 @@
using Game.JNGFrame.Logic.Entity.Components;
using JNGame.Sync.Frame.Entity;
using JNGame.Sync.State.Tile.Entity;
namespace Game.JNGFrame.Logic.Entity.Contexts
{
public sealed partial class EDNodeContext : JNTileContext<EDNode>
{
protected override EDNode BindComponent(EDNode entity)
{
base.BindComponent(entity);
entity.AddComponent<EDMoveComponent>();
return entity;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 71e757d251804ce4b37ba605cbf54016
timeCreated: 1712737245

View File

@@ -0,0 +1,17 @@
using Game.JNGFrame.Logic.Entity.Components;
using Game.JNGFrame.Logic.Entity.Controller;
using JNGame.Sync.State.Tile.Entity;
namespace Game.JNGFrame.Logic.Entity.Contexts
{
public sealed partial class EDPlayerContext : JNTileContext<EDPlayer>
{
protected override EDPlayer BindComponent(EDPlayer entity)
{
base.BindComponent(entity);
entity.AddComponent<EDMoveComponent>();
entity.AddComponent<EDPlayerController>();
return entity;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2358fccfc7ee4ab6b0ccdabc5e75060b
timeCreated: 1722225016

View File

@@ -0,0 +1,27 @@
using Game.JNGFrame.Logic.Entity.Components;
using Game.JNGState.Logic.Data;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Sync.State.Tile.Entity;
using JNGame.Sync.System.Data;
using NotImplementedException = System.NotImplementedException;
namespace Game.JNGFrame.Logic.Entity
{
public class EDNode : JNTileEntity
{
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
public override void TileSyncData(ISTileData data)
{
var nodeData = data as EDNodeData;
Transform.Position = nodeData.Value.Position.ToLVector3();
}
public override JNEntityLookup NewCLookup()
{
return new EDNodeLookup();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4c4bcab5b4174eda9afc6b994666a72f
timeCreated: 1712736545

View File

@@ -0,0 +1,31 @@
using Game.JNGFrame.Logic.Entity.Components;
using Game.JNGFrame.Logic.Entity.Controller;
using Game.JNGState.Logic.Data;
using JNGame.Math;
using JNGame.Sync.Frame.Entity.Components;
using JNGame.Sync.State.Tile.Entity;
using JNGame.Sync.System.Data;
using NotImplementedException = System.NotImplementedException;
namespace Game.JNGFrame.Logic.Entity
{
public class EDPlayer : JNTileEntity
{
public EDMoveComponent Move => CLookup.Query<EDMoveComponent>(this);
public EDPlayerController Controller => CLookup.Query<EDPlayerController>(this);
public override void TileSyncData(ISTileData data)
{
var nodeData = data as EDPlayerData;
Controller.AuthBind(nodeData.Value.Auth.Value);
Transform.Position = nodeData.Value.Position.ToLVector3();
}
public override JNEntityLookup NewCLookup()
{
return new EDPlayerLookup();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 020606cd1a564efeb88ce4df7c6fce56
timeCreated: 1722225061

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 66f9154d1a7c41e88a3c95d0408dc2cf
timeCreated: 1720863460

View 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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5c9d6660f75144ce84276d8536a9ffc2
timeCreated: 1715158899

View 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;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c42fd1121fb849b38dc7f94db9c3f3df
timeCreated: 1722861514

View 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);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9f6e62838e334b6e983b238063cc2479
timeCreated: 1715157690

View 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);
}
});
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7b59673517e1408295737003f44b2690
timeCreated: 1722224946

View 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);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 00e91648e3cd42a8ae1399000b88fdd6
timeCreated: 1712720318