This commit is contained in:
PC-20230316NUNE\Administrator
2024-02-02 15:38:13 +08:00
parent 877dca3b43
commit 00f56e11c7
228 changed files with 36944 additions and 20084 deletions

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections;
using Game.Plugins.App.Sync;
namespace Pathfinding.Examples {
using Pathfinding.RVO;
@@ -13,7 +14,7 @@ namespace Pathfinding.Examples {
/// </summary>
[RequireComponent(typeof(RVOController))]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_manual_r_v_o_agent.php")]
public class ManualRVOAgent : MonoBehaviour {
public class ManualRVOAgent : JNGSyncFrameDefault {
RVOController rvo;
public float speed = 1;
@@ -22,7 +23,9 @@ namespace Pathfinding.Examples {
rvo = GetComponent<RVOController>();
}
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
var x = Input.GetAxis("Horizontal");
var y = Input.GetAxis("Vertical");
@@ -30,7 +33,7 @@ namespace Pathfinding.Examples {
// Override the RVOController's velocity. This will disable local avoidance calculations for one simulation step.
rvo.velocity = v;
transform.position += v * Time.deltaTime;
transform.position += v * GetSync().Time.deltaTime;
}
}
}

View File

@@ -57,7 +57,9 @@ namespace Pathfinding.Examples {
}
}
protected void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (ai.reachedEndOfPath) {
if (!isAtDestination) OnTargetReached();
isAtDestination = true;

View File

@@ -1,10 +1,11 @@
using UnityEngine;
using System.Collections;
using Game.Plugins.App.Sync;
namespace Pathfinding.Examples {
/// <summary>Small sample script for placing obstacles</summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_object_placer.php")]
public class ObjectPlacer : MonoBehaviour {
public class ObjectPlacer : JNGSyncFrameDefault {
/// <summary>
/// GameObject to place.
/// When using a Grid Graph you need to make sure the object's layer is included in the collision mask in the GridGraph settings.
@@ -19,11 +20,12 @@ namespace Pathfinding.Examples {
float lastPlacedTime;
/// <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);
// Check if P is being pressed.
// Don't place objects if ctrl is pressed to avoid conflicts with the pause shortcut (ctrl+shift+P)
if (!Input.GetKey(KeyCode.LeftControl) && (Input.GetKeyDown("p") || (Input.GetKey("p") && Time.time - lastPlacedTime > 0.3f))) {
if (!Input.GetKey(KeyCode.LeftControl) && (Input.GetKeyDown("p") || (Input.GetKey("p") && GetSync().Time.time - lastPlacedTime > 0.3f))) {
PlaceObject();
}
@@ -31,9 +33,9 @@ namespace Pathfinding.Examples {
StartCoroutine(RemoveObject());
}
}
public void PlaceObject () {
lastPlacedTime = Time.time;
lastPlacedTime = GetSync().Time.time;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;

View File

@@ -1,3 +1,4 @@
using Game.Plugins.App.Sync;
using UnityEngine;
namespace Pathfinding {
@@ -43,7 +44,7 @@ namespace Pathfinding {
/// </summary>
[AddComponentMenu("Pathfinding/Navmesh/RecastTileUpdateHandler")]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_recast_tile_update_handler.php")]
public class RecastTileUpdateHandler : MonoBehaviour {
public class RecastTileUpdateHandler : JNGSyncFrameDefault {
/// <summary>Graph that handles the updates</summary>
RecastGraph graph;
@@ -96,7 +97,7 @@ namespace Pathfinding {
if (touching.Width * touching.Height > 0) {
if (!anyDirtyTiles) {
earliestDirty = Time.time;
earliestDirty = GetSync().Time.time;
anyDirtyTiles = true;
}
@@ -116,8 +117,10 @@ namespace Pathfinding {
RecastTileUpdate.OnNeedUpdates -= ScheduleUpdate;
}
void Update () {
if (anyDirtyTiles && Time.time - earliestDirty >= maxThrottlingDelay && graph != null) {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (anyDirtyTiles && GetSync().Time.time - earliestDirty >= maxThrottlingDelay && graph != null) {
UpdateDirtyTiles();
}
}

View File

@@ -15,7 +15,9 @@ namespace Pathfinding.Examples {
public float rotationDamping = 10.0f;
public bool staticOffset = false;
void LateUpdate () {
public override void OnLateSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnLateSyncUpdate(dt, frame, input);
Vector3 wantedPosition;
if (staticOffset) {
@@ -23,12 +25,12 @@ namespace Pathfinding.Examples {
} else {
wantedPosition = target.TransformPoint(0, height, -distance);
}
transform.position = Vector3.Lerp(transform.position, wantedPosition, Time.deltaTime * damping);
transform.position = Vector3.Lerp(transform.position, wantedPosition, GetSync().Time.deltaTime * damping);
if (enableRotation) {
if (smoothRotation) {
Quaternion wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
transform.rotation = Quaternion.Slerp(transform.rotation, wantedRotation, GetSync().Time.deltaTime * rotationDamping);
} else transform.LookAt(target, target.up);
}
}

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Linq;
using Game.Plugins.App.Sync;
namespace Pathfinding {
/// <summary>
@@ -11,7 +12,7 @@ namespace Pathfinding {
/// It is not meant to be pretty, but it does the job.
/// </summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_target_mover.php")]
public class TargetMover : MonoBehaviour {
public class TargetMover : JNGSyncFrameDefault {
/// <summary>Mask for the raycast placement</summary>
public LayerMask mask;