mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提取RVO 寻路
This commit is contained in:
@@ -24,7 +24,9 @@ namespace Pathfinding.Examples {
|
||||
|
||||
Camera cam;
|
||||
|
||||
public void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
cam = Camera.main;
|
||||
var simu = RVOSimulator.active;
|
||||
if (simu == null) {
|
||||
|
@@ -89,7 +89,10 @@ namespace Pathfinding.Examples {
|
||||
Vector2[] interpolatedVelocities;
|
||||
Vector2[] interpolatedRotations;
|
||||
|
||||
public void Start () {
|
||||
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
mesh = new Mesh();
|
||||
RVOSimulator rvoSim = FindObjectOfType(typeof(RVOSimulator)) as RVOSimulator;
|
||||
if (rvoSim == null) {
|
||||
@@ -230,7 +233,9 @@ namespace Pathfinding.Examples {
|
||||
}
|
||||
}
|
||||
|
||||
public void Update () {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
if (agents == null || mesh == null) return;
|
||||
|
||||
if (agents.Count != goals.Count) {
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Game.Plugins.App.Sync;
|
||||
|
||||
namespace Pathfinding.Examples {
|
||||
/// <summary>
|
||||
@@ -7,7 +8,7 @@ namespace Pathfinding.Examples {
|
||||
/// Used in a example scene
|
||||
/// </summary>
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_r_v_o_agent_placer.php")]
|
||||
public class RVOAgentPlacer : MonoBehaviour {
|
||||
public class RVOAgentPlacer : JNGSyncFrameDefault {
|
||||
public int agents = 100;
|
||||
|
||||
public float ringSize = 100;
|
||||
@@ -19,9 +20,9 @@ namespace Pathfinding.Examples {
|
||||
|
||||
public float repathRate = 1;
|
||||
|
||||
// Use this for initialization
|
||||
IEnumerator Start () {
|
||||
yield return null;
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
|
||||
for (int i = 0; i < agents; i++) {
|
||||
float angle = ((float)i / agents)*(float)System.Math.PI*2;
|
||||
@@ -34,7 +35,7 @@ namespace Pathfinding.Examples {
|
||||
|
||||
if (ag == null) {
|
||||
Debug.LogError("Prefab does not have an RVOExampleAgent component attached");
|
||||
yield break;
|
||||
return;
|
||||
}
|
||||
|
||||
//ag.radius = radius;
|
||||
|
@@ -125,7 +125,9 @@ namespace Pathfinding.Examples {
|
||||
}
|
||||
}
|
||||
|
||||
public void Update () {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
if (GetSync().Time.time >= nextRepath && canSearchAgain) {
|
||||
RecalculatePath();
|
||||
}
|
||||
|
@@ -1,11 +1,12 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Game.Plugins.App.Sync;
|
||||
|
||||
namespace Pathfinding.Examples {
|
||||
/// <summary>Example script for generating an infinite procedural world</summary>
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_procedural_world.php")]
|
||||
public class ProceduralWorld : MonoBehaviour {
|
||||
public class ProceduralWorld : JNGSyncFrameDefault {
|
||||
public Transform target;
|
||||
|
||||
public ProceduralPrefab[] prefabs;
|
||||
@@ -78,17 +79,20 @@ namespace Pathfinding.Examples {
|
||||
Dictionary<Int2, ProceduralTile> tiles = new Dictionary<Int2, ProceduralTile>();
|
||||
|
||||
// Use this for initialization
|
||||
void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
// Calculate the closest tiles
|
||||
// and then recalculate the graph
|
||||
Update();
|
||||
// UnityEngine.PlayerLoop.Update();
|
||||
AstarPath.active.Scan();
|
||||
|
||||
StartCoroutine(GenerateTiles());
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
// Calculate the tile the target is standing on
|
||||
Int2 p = new Int2(Mathf.RoundToInt((target.position.x - tileSize*0.5f) / tileSize), Mathf.RoundToInt((target.position.z - tileSize*0.5f) / tileSize));
|
||||
|
||||
|
@@ -48,8 +48,9 @@ namespace Pathfinding.Examples {
|
||||
return Vector3.Cross(derivate, secondDerivative) / (dx*dx*dx);
|
||||
}
|
||||
|
||||
/// <summary>Update is called once per frame</summary>
|
||||
void Update () {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
// Move the agent a small distance along the path, according to its speed
|
||||
float mn = time;
|
||||
float mx = time+1;
|
||||
|
@@ -8,7 +8,9 @@ namespace Pathfinding {
|
||||
Matrix4x4 originalMatrix;
|
||||
public GraphTransform transformation { get; private set; }
|
||||
|
||||
void Start () {
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
originalMatrix = transform.worldToLocalMatrix;
|
||||
transform.hasChanged = true;
|
||||
Refresh();
|
||||
|
@@ -41,9 +41,10 @@ namespace Pathfinding.Examples {
|
||||
movementPlane = graph.transformation;
|
||||
}
|
||||
|
||||
protected override void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
RefreshTransform();
|
||||
base.Start();
|
||||
base.OnSyncStart();
|
||||
}
|
||||
|
||||
protected override void CalculatePathRequestEndpoints (out Vector3 start, out Vector3 end) {
|
||||
|
@@ -1,31 +1,37 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Game.Plugins.App.Sync;
|
||||
|
||||
namespace Pathfinding.Examples {
|
||||
/// <summary>Helper script in the example scene 'Turn Based'</summary>
|
||||
[RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(SingleNodeBlocker))]
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_turn_based_door.php")]
|
||||
public class TurnBasedDoor : MonoBehaviour {
|
||||
public class TurnBasedDoor : JNGSyncFrameDefault {
|
||||
Animator animator;
|
||||
SingleNodeBlocker blocker;
|
||||
|
||||
bool open;
|
||||
|
||||
void Awake () {
|
||||
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
animator = GetComponent<Animator>();
|
||||
blocker = GetComponent<SingleNodeBlocker>();
|
||||
}
|
||||
|
||||
void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
// Make sure the door starts out blocked
|
||||
blocker.BlockAtCurrentPosition();
|
||||
animator.CrossFade("close", 0.2f);
|
||||
}
|
||||
|
||||
public void Close () {
|
||||
StartCoroutine(WaitAndClose());
|
||||
// StartCoroutine(WaitAndClose());
|
||||
}
|
||||
|
||||
IEnumerator WaitAndClose () {
|
||||
|
@@ -31,7 +31,9 @@ namespace Pathfinding.Examples {
|
||||
eventSystem = FindObjectOfType<EventSystem>();
|
||||
}
|
||||
|
||||
void Update () {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
// Ignore any input while the mouse is over a UI element
|
||||
|
@@ -1,22 +1,29 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Game.Plugins.App.Sync;
|
||||
|
||||
namespace Pathfinding.Examples {
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_example_mover.php")]
|
||||
public class ExampleMover : MonoBehaviour {
|
||||
public class ExampleMover : JNGSyncFrameDefault {
|
||||
RVOExampleAgent agent;
|
||||
public Transform target;
|
||||
|
||||
// Use this for initialization
|
||||
void Awake () {
|
||||
public override void OnSyncLoad()
|
||||
{
|
||||
base.OnSyncLoad();
|
||||
agent = GetComponent<RVOExampleAgent>();
|
||||
}
|
||||
|
||||
void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
agent.SetTarget(target.position);
|
||||
}
|
||||
|
||||
void LateUpdate () {
|
||||
public override void OnLateSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnLateSyncUpdate(dt, frame, input);
|
||||
if (Input.GetKeyDown(KeyCode.Mouse0)) {
|
||||
agent.SetTarget(target.position);
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Game.Plugins.App.Sync;
|
||||
using Pathfinding.Util;
|
||||
namespace Pathfinding.Examples {
|
||||
/// <summary>
|
||||
@@ -17,7 +18,7 @@ namespace Pathfinding.Examples {
|
||||
/// See: Pathfinding.FloodPathTracer
|
||||
/// </summary>
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_path_types_demo.php")]
|
||||
public class PathTypesDemo : MonoBehaviour {
|
||||
public class PathTypesDemo : JNGSyncFrameDefault {
|
||||
public DemoMode activeDemo = DemoMode.ABPath;
|
||||
|
||||
public enum DemoMode {
|
||||
@@ -64,7 +65,9 @@ namespace Pathfinding.Examples {
|
||||
List<Vector3> multipoints = new List<Vector3>();
|
||||
|
||||
// Update is called once per frame
|
||||
void Update () {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
|
||||
|
||||
// Find the intersection with the y=0 plane
|
||||
|
@@ -1,9 +1,10 @@
|
||||
using Game.Plugins.App.Sync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pathfinding.Examples {
|
||||
/// <summary>Example script used in the example scenes</summary>
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_door_controller.php")]
|
||||
public class DoorController : MonoBehaviour {
|
||||
public class DoorController : JNGSyncFrameDefault {
|
||||
private bool open = false;
|
||||
|
||||
public int opentag = 1;
|
||||
@@ -13,7 +14,9 @@ namespace Pathfinding.Examples {
|
||||
|
||||
Bounds bounds;
|
||||
|
||||
public void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
// Capture the bounds of the collider while it is closed
|
||||
bounds = GetComponent<Collider>().bounds;
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
using Game.Plugins.App.Sync;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Pathfinding {
|
||||
@@ -19,10 +20,12 @@ namespace Pathfinding {
|
||||
/// </summary>
|
||||
[AddComponentMenu("Pathfinding/Navmesh/RecastTileUpdate")]
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_recast_tile_update.php")]
|
||||
public class RecastTileUpdate : MonoBehaviour {
|
||||
public class RecastTileUpdate : JNGSyncFrameDefault {
|
||||
public static event System.Action<Bounds> OnNeedUpdates;
|
||||
|
||||
void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
ScheduleUpdate();
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Game.Plugins.App.Sync;
|
||||
using Pathfinding;
|
||||
|
||||
namespace Pathfinding.Examples {
|
||||
@@ -9,8 +10,10 @@ namespace Pathfinding.Examples {
|
||||
/// </summary>
|
||||
[ExecuteInEditMode]
|
||||
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_snap_to_node.php")]
|
||||
public class SnapToNode : MonoBehaviour {
|
||||
void Update () {
|
||||
public class SnapToNode : JNGSyncFrameDefault {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
if (transform.hasChanged && AstarPath.active != null) {
|
||||
var node = AstarPath.active.GetNearest(transform.position, NNConstraint.None).node;
|
||||
if (node != null) {
|
||||
|
@@ -25,7 +25,9 @@ namespace Pathfinding {
|
||||
|
||||
Camera cam;
|
||||
|
||||
public void Start () {
|
||||
public override void OnSyncStart()
|
||||
{
|
||||
base.OnSyncStart();
|
||||
//Cache the Main Camera
|
||||
cam = Camera.main;
|
||||
// Slightly inefficient way of finding all AIs, but this is just an example script, so it doesn't matter much.
|
||||
@@ -41,12 +43,14 @@ namespace Pathfinding {
|
||||
}
|
||||
|
||||
/// <summary>Update is called once per frame</summary>
|
||||
void Update () {
|
||||
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
|
||||
{
|
||||
base.OnSyncUpdate(dt, frame, input);
|
||||
if (!onlyOnDoubleClick && cam != null) {
|
||||
UpdateTargetPosition();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void UpdateTargetPosition () {
|
||||
Vector3 newPosition = Vector3.zero;
|
||||
bool positionFound = false;
|
||||
|
Reference in New Issue
Block a user