mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
no message
This commit is contained in:
@@ -8,7 +8,7 @@ namespace Game.Plugins.App
|
||||
|
||||
public static readonly JNGSocket Socket = new JNGSocket();
|
||||
public static readonly JNGSyncFrame Sync = new JNGSyncFrame();
|
||||
public static readonly JAPI Api = new(new JAPIConfig(){BaseURL = "http://192.168.0.116:8080"});
|
||||
public static readonly JAPI Api = new(new JAPIConfig(){BaseURL = "http://192.168.0.126:8080"});
|
||||
public static readonly EventDispatcher Event = EventDispatcher.Event;
|
||||
|
||||
public static SystemBase[] System()
|
||||
|
57
JNFrame/Assets/Game/Plugins/App/Game/RVO/JNGRVOAgent.cs
Normal file
57
JNFrame/Assets/Game/Plugins/App/Game/RVO/JNGRVOAgent.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Threading.Tasks;
|
||||
using Game.Plugins.App.Sync;
|
||||
using Game.Plugins.JNGame.Sync.Frame.AstarPath.RVO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Plugins.App.Game.RVO
|
||||
{
|
||||
public class JNGRVOAgent : JNGSyncFrameDefault
|
||||
{
|
||||
|
||||
private JNRVOSimulator Simulator => GetComponentInParent<JNGRVOManager>().Simulator;
|
||||
|
||||
private JNIAgent _agent;
|
||||
|
||||
public float maxSpeed = 5;
|
||||
public float radius = 0.5f;
|
||||
|
||||
private Vector2 target;
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
var position = this.transform.position;
|
||||
_agent = Simulator.AddAgent(new JNRVOAgent(
|
||||
new Vector2(position.x, position.z), 0
|
||||
));
|
||||
SetTarget(position);
|
||||
_agent.Radius = radius;
|
||||
}
|
||||
|
||||
//设置目标点
|
||||
public void SetTarget(Vector2 targetPoint)
|
||||
{
|
||||
this.target = targetPoint;
|
||||
}
|
||||
public void SetTarget(Vector3 targetPoint)
|
||||
{
|
||||
this.target = new Vector2(targetPoint.x,targetPoint.z);
|
||||
}
|
||||
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
var pos = _agent.Position;
|
||||
var deltaPosition = Vector2.ClampMagnitude(_agent.CalculatedTargetPoint - pos,
|
||||
_agent.CalculatedSpeed * GetSync().Time.deltaTime);
|
||||
pos += deltaPosition;
|
||||
_agent.Position = pos;
|
||||
|
||||
var dist = (target - pos).magnitude;
|
||||
_agent.SetTarget(target, Mathf.Min(dist, maxSpeed), maxSpeed * 1.1f);
|
||||
this.transform.position = new Vector3(_agent.Position.x, _agent.ElevationCoordinate, _agent.Position.y);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a53ee56903f64f8c845d8eb0274f6b07
|
||||
timeCreated: 1708324888
|
@@ -1,4 +1,5 @@
|
||||
using Game.Plugins.App.Sync;
|
||||
using System.Threading.Tasks;
|
||||
using Game.Plugins.App.Sync;
|
||||
using Game.Plugins.JNGame.Sync.Frame.AstarPath.RVO;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -8,21 +9,37 @@ namespace Game.Plugins.App.Game.RVO
|
||||
public class JNGRVOManager : JNGSyncFrameDefault
|
||||
{
|
||||
|
||||
private JNRVOSimulator _simulator = new JNRVOSimulator(MovementPlane.XY);
|
||||
private JNRVOSimulator _simulator = new JNRVOSimulator(MovementPlane.XZ);
|
||||
public JNRVOSimulator Simulator => _simulator;
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
}
|
||||
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
Simulator.DesiredDeltaTime = 1.0f / (1000f / dt);
|
||||
Simulator.symmetryBreakingBias = 0.1f;
|
||||
//更新寻路
|
||||
Simulator.Update();
|
||||
// Simulator.DesiredDeltaTime = 1.0f / 30;
|
||||
// Simulator.symmetryBreakingBias = 0.1f;
|
||||
// //更新避障
|
||||
// Simulator.Update();
|
||||
if (frame.Index > 0)
|
||||
{
|
||||
Simulator.DesiredDeltaTime = 1.0f / 15;
|
||||
Simulator.symmetryBreakingBias = 0.1f;
|
||||
//更新避障
|
||||
Simulator.Update();
|
||||
}
|
||||
}
|
||||
|
||||
// public override Task OnSyncUpdateThread(int dt, JNFrameInfo frame)
|
||||
// {
|
||||
// return Task.Run(() =>
|
||||
// {
|
||||
// if (frame.Index > 0)
|
||||
// {
|
||||
// Simulator.DesiredDeltaTime = 1.0f / 15;
|
||||
// Simulator.symmetryBreakingBias = 0.1f;
|
||||
// //更新避障
|
||||
// Simulator.Update();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
}
|
||||
}
|
94
JNFrame/Assets/Game/Plugins/App/Game/RVO/JNGRVOObstacle.cs
Normal file
94
JNFrame/Assets/Game/Plugins/App/Game/RVO/JNGRVOObstacle.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using Game.Plugins.App.Sync;
|
||||
using Game.Plugins.JNGame.Sync.Frame.AstarPath.RVO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Game.Plugins.App.Game.RVO
|
||||
{
|
||||
public class JNGRVOObstacle : JNGSyncFrameDefault
|
||||
{
|
||||
|
||||
private JNRVOSimulator Simulator => GetComponentInParent<JNGRVOManager>().Simulator;
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
CreateObstacles();
|
||||
}
|
||||
|
||||
public void CreateObstacles()
|
||||
{
|
||||
var boxCollider = this.GetComponent<BoxCollider>();
|
||||
Vector3 center = transform.position;
|
||||
Vector3 size = boxCollider.size;
|
||||
//
|
||||
// var verts = new [] { new Vector3(1, 0, -1), new Vector3(1, 0, 1), new Vector3(-1, 0, 1), new Vector3(-1, 0, -1) };
|
||||
// for (int i = 0; i < verts.Length; i++) {
|
||||
// verts[i].Scale(new Vector3(size.x * 0.5f, 0, size.y * 0.5f));
|
||||
// verts[i] += new Vector3(center.x, 0, center.y);
|
||||
// }
|
||||
//
|
||||
var verts = new Vector3[4];
|
||||
verts[0] = (new Vector3(size.x, -size.y, size.z) * 0.5f);
|
||||
verts[1] = (new Vector3(-size.x, -size.y, size.z) * 0.5f);
|
||||
verts[2] = (new Vector3(-size.x, -size.y, -size.z) * 0.5f);
|
||||
verts[3] = (new Vector3(size.x, -size.y, -size.z) * 0.5f);
|
||||
verts[0].y = 0;
|
||||
verts[1].y = 0;
|
||||
verts[2].y = 0;
|
||||
verts[3].y = 0;
|
||||
Simulator.AddObstacle(verts, 1, transform.localToWorldMatrix);
|
||||
}
|
||||
|
||||
|
||||
// private void OnDrawGizmos()
|
||||
// {
|
||||
//
|
||||
// Gizmos.color = new Color(0.615f, 1, 0.06f, false ? 1.0f : 0.7f);
|
||||
// var movementPlane = MovementPlane.XY;
|
||||
// var up = Vector3.up;
|
||||
//
|
||||
// if (gizmoVerts == null || AreGizmosDirty() || _obstacleMode != obstacleMode) {
|
||||
// _obstacleMode = obstacleMode;
|
||||
//
|
||||
// if (gizmoVerts == null) gizmoVerts = new List<Vector3[]>();
|
||||
// else gizmoVerts.Clear();
|
||||
//
|
||||
// CreateObstacles();
|
||||
// }
|
||||
//
|
||||
// Matrix4x4 m = GetMatrix();
|
||||
//
|
||||
// for (int i = 0; i < gizmoVerts.Count; i++) {
|
||||
// Vector3[] verts = gizmoVerts[i];
|
||||
// for (int j = 0, q = verts.Length-1; j < verts.Length; q = j++) {
|
||||
// Gizmos.DrawLine(m.MultiplyPoint3x4(verts[j]), m.MultiplyPoint3x4(verts[q]));
|
||||
// }
|
||||
//
|
||||
// if (selected) {
|
||||
// for (int j = 0, q = verts.Length-1; j < verts.Length; q = j++) {
|
||||
// Vector3 a = m.MultiplyPoint3x4(verts[q]);
|
||||
// Vector3 b = m.MultiplyPoint3x4(verts[j]);
|
||||
//
|
||||
// if (movementPlane != MovementPlane.XY) {
|
||||
// Gizmos.DrawLine(a + up*Height, b + up*Height);
|
||||
// Gizmos.DrawLine(a, a + up*Height);
|
||||
// }
|
||||
//
|
||||
// Vector3 avg = (a + b) * 0.5f;
|
||||
// Vector3 tang = (b - a).normalized;
|
||||
// if (tang == Vector3.zero) continue;
|
||||
//
|
||||
// Vector3 normal = Vector3.Cross(up, tang);
|
||||
//
|
||||
// Gizmos.DrawLine(avg, avg+normal);
|
||||
// Gizmos.DrawLine(avg+normal, avg+normal*0.5f+tang*0.5f);
|
||||
// Gizmos.DrawLine(avg+normal, avg+normal*0.5f-tang*0.5f);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// gizmoDrawing = false;
|
||||
// }
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a7e67272f48415bb20f684dfd242240
|
||||
timeCreated: 1708324868
|
@@ -8,7 +8,7 @@ namespace Game.Plugins.App
|
||||
protected override async UniTask<string> GetUrl()
|
||||
{
|
||||
await UniTask.NextFrame();
|
||||
return "ws://192.168.0.116:8080/websocket";
|
||||
return "ws://192.168.0.126:8080/websocket";
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user