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

@@ -18,22 +18,38 @@ namespace Pathfinding {
public Transform target;
IAstarAI ai;
void OnEnable () {
public Vector3 pos;
void OnEnable ()
{
this.pos = this.transform.position;
ai = GetComponent<IAstarAI>();
// Update the destination right before searching for a path as well.
// This is enough in theory, but this script will also update the destination every
// frame as the destination is used for debugging and may be used for other things by other
// scripts as well. So it makes sense that it is up to date every frame.
if (ai != null) ai.onSearchPath += Update;
if (ai != null) ai.onSearchPath += OnUpdate;
}
void OnDisable () {
if (ai != null) ai.onSearchPath -= Update;
if (ai != null) ai.onSearchPath -= OnUpdate;
}
/// <summary>Updates the AI's destination every frame</summary>
void Update () {
if (target != null && ai != null) ai.destination = target.position;
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
this.OnUpdate();
}
public void SetTarget(Vector3 pos)
{
this.pos = pos;
}
public void OnUpdate()
{
if (ai != null) ai.destination = pos;
}
}
}

View File

@@ -115,7 +115,7 @@ namespace Pathfinding {
public bool alwaysDrawGizmos;
/// <summary>
/// Slow down when not facing the target direction.
/// Slow down when not facing the target direction.
/// Incurs at a small performance overhead.
/// </summary>
public bool slowWhenNotFacingTarget = true;

View File

@@ -1,3 +1,4 @@
using Game.Plugins.App.Util;
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEngine;
@@ -110,7 +111,7 @@ namespace Pathfinding {
// Randomize the repath time slightly so that all agents don't request a path at the same time
// in the future. This is useful when there are a lot of agents instantiated at exactly the same time.
const float JITTER_AMOUNT = 0.3f;
lastRepathTime -= (UnityEngine.Random.value - 0.5f) * JITTER_AMOUNT * (mode == Mode.Dynamic ? maximumPeriod : period);
lastRepathTime -= (JNRandom.value - 0.5f) * JITTER_AMOUNT * (mode == Mode.Dynamic ? maximumPeriod : period);
}
public void DrawGizmos (Vector3 position, float radius) {

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using Game.Plugins.App.Util;
namespace Pathfinding {
/// <summary>
@@ -195,8 +196,8 @@ namespace Pathfinding {
protected override void Reset () {
base.Reset();
// Create a new random 64 bit value (62 bit actually because we skip negative numbers, but that's still enough by a huge margin)
var rnd1 = (ulong)Random.Range(0, int.MaxValue);
var rnd2 = ((ulong)Random.Range(0, int.MaxValue) << 32);
var rnd1 = (ulong)JNRandom.Range(0, int.MaxValue);
var rnd2 = ((ulong)JNRandom.Range(0, int.MaxValue) << 32);
uniqueID = rnd1 | rnd2;
usedIDs[uniqueID] = this;

View File

@@ -1,5 +1,7 @@
using UnityEngine;
using System.Collections.Generic;
using Game.Plugins.App.Sync;
using Game.Plugins.App.Util;
using Pathfinding.RVO;
namespace Pathfinding.Examples {
@@ -19,7 +21,7 @@ namespace Pathfinding.Examples {
/// [Open online documentation to see images]
/// </summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_lightweight_r_v_o.php")]
public class LightweightRVO : MonoBehaviour {
public class LightweightRVO : JNGSyncFrameDefault {
/// <summary>Number of agents created at start</summary>
public int agentCount = 100;
@@ -137,7 +139,7 @@ namespace Pathfinding.Examples {
}
private float uniformDistance (float radius) {
float v = Random.value + Random.value;
float v = JNRandom.value + JNRandom.value;
if (v > 1) return radius * (2-v);
else return radius * v;
@@ -157,7 +159,7 @@ namespace Pathfinding.Examples {
float circleRad = Mathf.Sqrt(agentCount * radius * radius * 4 / Mathf.PI) * exampleScale * 0.05f;
for (int i = 0; i < agentCount; i++) {
Vector3 pos = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / agentCount)) * circleRad * (1 + Random.value * 0.01f);
Vector3 pos = new Vector3(Mathf.Cos(i * Mathf.PI * 2.0f / agentCount), 0, Mathf.Sin(i * Mathf.PI * 2.0f / agentCount)) * circleRad * (1 + JNRandom.value * 0.01f);
IAgent agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
agents.Add(agent);
goals.Add(-pos);
@@ -183,8 +185,8 @@ namespace Pathfinding.Examples {
float circleRad = Mathf.Sqrt(agentCount * radius * radius * 4 / Mathf.PI) * exampleScale * 0.05f;
for (int i = 0; i < agentCount; i++) {
float angle = Random.value * Mathf.PI * 2.0f;
float targetAngle = Random.value * Mathf.PI * 2.0f;
float angle = JNRandom.value * Mathf.PI * 2.0f;
float targetAngle = JNRandom.value * Mathf.PI * 2.0f;
Vector3 pos = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * uniformDistance(circleRad);
IAgent agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
agents.Add(agent);
@@ -199,7 +201,7 @@ namespace Pathfinding.Examples {
const int AgentsPerDistance = 10;
for (int i = 0; i < agentCount; i++) {
float angle = ((i % directions)/(float)directions) * Mathf.PI * 2.0f;
var dist = distanceBetweenGroups * ((i/(directions*AgentsPerDistance) + 1) + 0.3f*Random.value);
var dist = distanceBetweenGroups * ((i/(directions*AgentsPerDistance) + 1) + 0.3f*JNRandom.value);
Vector3 pos = new Vector3(Mathf.Cos(angle), 0, Mathf.Sin(angle)) * dist;
IAgent agent = sim.AddAgent(new Vector2(pos.x, pos.z), pos.y);
agent.Priority = (i % directions) == 0 ? 1 : 0.01f;
@@ -255,7 +257,7 @@ namespace Pathfinding.Examples {
// Move agent
// This is the responsibility of this script, not the RVO system
Vector2 pos = agent.Position;
var deltaPosition = Vector2.ClampMagnitude(agent.CalculatedTargetPoint - pos, agent.CalculatedSpeed * Time.deltaTime);
var deltaPosition = Vector2.ClampMagnitude(agent.CalculatedTargetPoint - pos, agent.CalculatedSpeed * GetSync().Time.deltaTime);
pos += deltaPosition;
agent.Position = pos;
@@ -270,7 +272,7 @@ namespace Pathfinding.Examples {
interpolatedVelocities[i] += deltaPosition;
if (interpolatedVelocities[i].magnitude > maxSpeed*0.1f) {
interpolatedVelocities[i] = Vector2.ClampMagnitude(interpolatedVelocities[i], maxSpeed*0.1f);
interpolatedRotations[i] = Vector2.Lerp(interpolatedRotations[i], interpolatedVelocities[i], agent.CalculatedSpeed * Time.deltaTime*4f);
interpolatedRotations[i] = Vector2.Lerp(interpolatedRotations[i], interpolatedVelocities[i], agent.CalculatedSpeed * GetSync().Time.deltaTime*4f);
}
//Debug.DrawRay(new Vector3(pos.x, 0, pos.y), new Vector3(interpolatedVelocities[i].x, 0, interpolatedVelocities[i].y) * 10);

View File

@@ -1,5 +1,7 @@
using UnityEngine;
using System.Collections.Generic;
using Game.Plugins.App.Sync;
using Game.Plugins.App.Util;
using Pathfinding.RVO;
namespace Pathfinding.Examples {
@@ -16,7 +18,7 @@ namespace Pathfinding.Examples {
[RequireComponent(typeof(RVOController))]
[RequireComponent(typeof(Seeker))]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_r_v_o_example_agent.php")]
public class RVOExampleAgent : MonoBehaviour {
public class RVOExampleAgent : JNGSyncFrameDefault {
public float repathRate = 1;
private float nextRepath = 0;
@@ -81,7 +83,7 @@ namespace Pathfinding.Examples {
public void RecalculatePath () {
canSearchAgain = false;
nextRepath = Time.time+repathRate*(Random.value+0.5f);
nextRepath = GetSync().Time.time+repathRate*(JNRandom.value+0.5f);
seeker.StartPath(transform.position, target, OnPathComplete);
}
@@ -124,7 +126,7 @@ namespace Pathfinding.Examples {
}
public void Update () {
if (Time.time >= nextRepath && canSearchAgain) {
if (GetSync().Time.time >= nextRepath && canSearchAgain) {
RecalculatePath();
}
@@ -169,18 +171,18 @@ namespace Pathfinding.Examples {
// Get a processed movement delta from the rvo controller and move the character.
// This is based on information from earlier frames.
var movementDelta = controller.CalculateMovementDelta(Time.deltaTime);
var movementDelta = controller.CalculateMovementDelta(GetSync().Time.deltaTime);
pos += movementDelta;
// Rotate the character if the velocity is not extremely small
if (Time.deltaTime > 0 && movementDelta.magnitude / Time.deltaTime > 0.01f) {
if (GetSync().Time.deltaTime > 0 && movementDelta.magnitude / GetSync().Time.deltaTime > 0.01f) {
var rot = transform.rotation;
var targetRot = Quaternion.LookRotation(movementDelta, controller.To3D(Vector2.zero, 1));
const float RotationSpeed = 5;
if (controller.movementPlane == MovementPlane.XY) {
targetRot = targetRot * Quaternion.Euler(-90, 180, 0);
}
transform.rotation = Quaternion.Slerp(rot, targetRot, Time.deltaTime * RotationSpeed);
transform.rotation = Quaternion.Slerp(rot, targetRot, GetSync().Time.deltaTime * RotationSpeed);
}
if (controller.movementPlane == MovementPlane.XZ) {

View File

@@ -1,3 +1,4 @@
using Game.Plugins.App.Sync;
using UnityEngine;
namespace Pathfinding.Examples {
@@ -6,7 +7,7 @@ namespace Pathfinding.Examples {
/// Helper script in the example scene called 'Moving'.
/// </summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_bezier_mover.php")]
public class BezierMover : MonoBehaviour {
public class BezierMover : JNGSyncFrameDefault {
public Transform[] points;
public float speed = 1;
@@ -57,7 +58,7 @@ namespace Pathfinding.Examples {
float mid = (mn+mx)/2;
Vector3 p = Evaluate(mid, out var dummy1, out var dummy2, out var dummy3);
if ((p-transform.position).sqrMagnitude > (speed*Time.deltaTime)*(speed*Time.deltaTime)) {
if ((p-transform.position).sqrMagnitude > (speed*GetSync().Time.deltaTime)*(speed*GetSync().Time.deltaTime)) {
mx = mid;
} else {
mn = mid;
@@ -68,7 +69,7 @@ namespace Pathfinding.Examples {
transform.position = Evaluate(time, out var derivative, out var dummy, out var curvature);
averageCurvature = Vector3.Lerp(averageCurvature, curvature, Time.deltaTime);
averageCurvature = Vector3.Lerp(averageCurvature, curvature, GetSync().Time.deltaTime);
// Estimate the acceleration at the current point and use it to tilt the object inwards on the curve
var centripetalAcceleration = -Vector3.Cross(derivative.normalized, averageCurvature);

View File

@@ -1,13 +1,15 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Game.Plugins.App.Sync;
using Pathfinding;
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEngine.EventSystems;
namespace Pathfinding.Examples {
/// <summary>Helper script in the example scene 'Turn Based'</summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_examples_1_1_turn_based_manager.php")]
public class TurnBasedManager : MonoBehaviour {
public class TurnBasedManager : JNGSyncFrameDefault {
TurnBasedAI selected;
public float movementSpeed;
@@ -136,7 +138,7 @@ namespace Pathfinding.Examples {
var interpolatedPoint = AstarSplines.CatmullRom(p0, p1, p2, p3, distanceAlongSegment / segmentLength);
unit.transform.position = interpolatedPoint;
yield return null;
distanceAlongSegment += Time.deltaTime * speed;
distanceAlongSegment += JNTime.Time.deltaTime * speed;
}
distanceAlongSegment -= segmentLength;

View File

@@ -53,14 +53,16 @@ namespace Pathfinding.Examples {
}
/// <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);
var aiBase = ai as AIBase;
aiBase.canMove = false;
// aiBase.updatePosition = false;
// aiBase.updateRotation = false;
}
/// <summary>Calculate position of the currently grounded foot</summary>
Vector3 CalculateBlendPoint () {
// Fall back to rotating around the transform position if no feet could be found
@@ -72,8 +74,8 @@ namespace Pathfinding.Examples {
// This is the same calculation that Unity uses for
// Animator.pivotWeight and Animator.pivotPosition
// but those properties do not work for all animations apparently.
var footVelocity1 = (leftFootPos - prevFootPos[0]) / Time.deltaTime;
var footVelocity2 = (rightFootPos - prevFootPos[1]) / Time.deltaTime;
var footVelocity1 = (leftFootPos - prevFootPos[0]) / GetSync().Time.deltaTime;
var footVelocity2 = (rightFootPos - prevFootPos[1]) / GetSync().Time.deltaTime;
float denominator = footVelocity1.magnitude + footVelocity2.magnitude;
var pivotWeight = denominator > 0 ? footVelocity1.magnitude / denominator : 0.5f;
prevFootPos[0] = leftFootPos;
@@ -86,7 +88,7 @@ namespace Pathfinding.Examples {
Vector3 nextPosition;
Quaternion nextRotation;
ai.MovementUpdate(Time.deltaTime, out nextPosition, out nextRotation);
ai.MovementUpdate(GetSync().Time.deltaTime, out nextPosition, out nextRotation);
//var desiredVelocity = (ai.steeringTarget - tr.position).normalized * 2;//ai.desiredVelocity;
var desiredVelocity = ai.desiredVelocity;
@@ -98,7 +100,7 @@ namespace Pathfinding.Examples {
// Calculate the desired velocity relative to the character (+Z = forward, +X = right)
var localDesiredVelocity = tr.InverseTransformDirection(desiredVelocityWithoutGrav);
smoothedVelocity = Vector3.Lerp(smoothedVelocity, localDesiredVelocity, velocitySmoothing > 0 ? Time.deltaTime / velocitySmoothing : 1);
smoothedVelocity = Vector3.Lerp(smoothedVelocity, localDesiredVelocity, velocitySmoothing > 0 ? GetSync().Time.deltaTime / velocitySmoothing : 1);
if (smoothedVelocity.magnitude < 0.4f) {
smoothedVelocity = smoothedVelocity.normalized * 0.4f;
}
@@ -116,7 +118,7 @@ namespace Pathfinding.Examples {
}
// Calculate how much the agent should rotate during this frame
var newRot = RotateTowards(desiredVelocityWithoutGrav, Time.deltaTime * rotationSpeed);
var newRot = RotateTowards(desiredVelocityWithoutGrav, GetSync().Time.deltaTime * rotationSpeed);
// Rotate the character around the currently grounded foot to prevent foot sliding
nextPosition = ai.position;
nextRotation = ai.rotation;
@@ -129,7 +131,7 @@ namespace Pathfinding.Examples {
// Use gravity from the movement script, not from animation
var deltaPos = anim.deltaPosition;
deltaPos.y = desiredVelocity.y * Time.deltaTime;
deltaPos.y = desiredVelocity.y * GetSync().Time.deltaTime;
nextPosition += deltaPos;
// Call the movement script to perform the final movement

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;

View File

@@ -1,4 +1,5 @@
using Game.Plugins.App.Util;
using UnityEngine;
using Pathfinding.Serialization;
@@ -189,7 +190,7 @@ namespace Pathfinding {
var graphSpacePosition = gg.transform.InverseTransform((Vector3)position);
return gg.transform.Transform(graphSpacePosition + new Vector3(Random.value - 0.5f, 0, Random.value - 0.5f));
return gg.transform.Transform(graphSpacePosition + new Vector3(JNRandom.value - 0.5f, 0, JNRandom.value - 0.5f));
}
/// <summary>

View File

@@ -1,3 +1,4 @@
using Game.Plugins.App.Util;
using UnityEngine;
using Pathfinding.Serialization;
@@ -451,8 +452,8 @@ namespace Pathfinding {
float r2;
do {
r1 = Random.value;
r2 = Random.value;
r1 = JNRandom.value;
r2 = JNRandom.value;
} while (r1+r2 > 1);
var holder = GetNavmeshHolder(GraphIndex);

View File

@@ -1,5 +1,7 @@
using UnityEngine;
using System.Collections.Generic;
using Game.Plugins.App.Sync;
using Plugins.JNGame.Sync.Frame.Entity;
namespace Pathfinding {
/// <summary>
@@ -24,7 +26,7 @@ namespace Pathfinding {
/// </summary>
[AddComponentMenu("Pathfinding/Navmesh/RecastMeshObj")]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_recast_mesh_obj.php")]
public class RecastMeshObj : VersionedMonoBehaviour {
public class RecastMeshObj : JNGSyncFrameDefault {
/// <summary>Static objects are stored in a tree for fast bounds lookups</summary>
protected static RecastBBTree tree = new RecastBBTree();
@@ -42,7 +44,7 @@ namespace Pathfinding {
}
}
return;
} else if (Time.timeSinceLevelLoad == 0) {
} else if (JNTime.Time.timeSinceLevelLoad == 0) {
// Is is not guaranteed that all RecastMeshObj OnEnable functions have been called, so if it is the first frame since loading a new level
// try to initialize all RecastMeshObj objects.
var objs = FindObjectsOfType(typeof(RecastMeshObj)) as RecastMeshObj[];

View File

@@ -721,7 +721,7 @@ namespace Pathfinding.Voxels {
}
#if ASTARDEBUG
Color col = new Color(Random.value, Random.value, Random.value);
Color col = new Color(JNRandom.value, JNRandom.value, JNRandom.value);
for (int q = 0, j = (verts.Count/4)-1; q < (verts.Count/4); j = q, q++) {
int i4 = q*4;

View File

@@ -118,7 +118,7 @@ namespace Pathfinding.Legacy {
// gets confused because the first point in the path is far away
// from the current position (possibly behind it which could cause
// the agent to turn around, and that looks pretty bad).
Vector3 p1 = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint;
Vector3 p1 = GetSync().Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint;
Vector3 p2 = GetFeetPosition();
Vector3 dir = p2-p1;
float magn = dir.magnitude;
@@ -154,7 +154,7 @@ namespace Pathfinding.Legacy {
} else if (rigid != null) {
rigid.AddForce(dir);
} else {
tr.Translate(dir*Time.deltaTime, Space.World);
tr.Translate(dir*GetSync().Time.deltaTime, Space.World);
}
}
@@ -204,7 +204,7 @@ namespace Pathfinding.Legacy {
//Mathfx.DistancePointSegmentStrict (vPath[currentWaypointIndex+1],vPath[currentWaypointIndex+2],currentPosition);
if (dist < pickNextWaypointDist*pickNextWaypointDist) {
lastFoundWaypointPosition = currentPosition;
lastFoundWaypointTime = Time.time;
lastFoundWaypointTime = GetSync().Time.time;
currentWaypointIndex++;
} else {
break;
@@ -245,8 +245,8 @@ namespace Pathfinding.Legacy {
Debug.DrawRay(GetFeetPosition(), forward*sp, Color.cyan);
#endif
if (Time.deltaTime > 0) {
sp = Mathf.Clamp(sp, 0, targetDist/(Time.deltaTime*2));
if (GetSync().Time.deltaTime > 0) {
sp = Mathf.Clamp(sp, 0, targetDist/(GetSync().Time.deltaTime*2));
}
return forward*sp;
@@ -263,7 +263,7 @@ namespace Pathfinding.Legacy {
Quaternion rot = tr.rotation;
Quaternion toTarget = Quaternion.LookRotation(dir);
rot = Quaternion.Slerp(rot, toTarget, turningSpeed*Time.deltaTime);
rot = Quaternion.Slerp(rot, toTarget, turningSpeed*GetSync().Time.deltaTime);
Vector3 euler = rot.eulerAngles;
euler.z = 0;
euler.x = 0;

View File

@@ -34,12 +34,14 @@ namespace Pathfinding.Legacy {
public new bool enableRotation = true;
public new float rotationSpeed = 30;
public void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (rvoAgent == null) return;
RaycastHit hit;
Vector3 pos = tr.position + CalculateMovementDelta(Time.deltaTime);
Vector3 pos = tr.position + CalculateMovementDelta(GetSync().Time.deltaTime);
if (mask != 0 && Physics.Raycast(pos + Vector3.up*height*0.5f, Vector3.down, out hit, float.PositiveInfinity, mask)) {
pos.y = hit.point.y;
@@ -49,7 +51,9 @@ namespace Pathfinding.Legacy {
tr.position = pos + Vector3.up*(height*0.5f - center);
if (enableRotation && velocity != Vector3.zero) transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(velocity), Time.deltaTime * rotationSpeed * Mathf.Min(velocity.magnitude, 0.2f));
if (enableRotation && velocity != Vector3.zero) transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(velocity), GetSync().Time.deltaTime * rotationSpeed * Mathf.Min(velocity.magnitude, 0.2f));
}
}
}

View File

@@ -47,7 +47,7 @@ namespace Pathfinding.Legacy {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
deltaTime = Mathf.Min(Time.smoothDeltaTime*2, Time.deltaTime);
deltaTime = Mathf.Min(GetSync().Time.smoothDeltaTime*2, GetSync().Time.deltaTime);
if (richPath != null) {
//System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
@@ -61,7 +61,7 @@ namespace Pathfinding.Legacy {
//tr.position = ps;
//Only get walls every 5th frame to save on performance
if (Time.frameCount % 5 == 0 && wallForce > 0 && wallDist > 0) {
if (GetSync().Time.frameCount % 5 == 0 && wallForce > 0 && wallDist > 0) {
wallBuffer.Clear();
fn.FindWalls(wallBuffer, wallDist);
}
@@ -255,7 +255,7 @@ namespace Pathfinding.Legacy {
}
UpdateVelocity();
lastDeltaTime = Time.deltaTime;
lastDeltaTime = GetSync().Time.deltaTime;
}
/// <summary>Update is called once per frame</summary>

View File

@@ -2,6 +2,7 @@ using UnityEngine;
using System.Collections.Generic;
using Pathfinding.Util;
using Pathfinding.Serialization;
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEngine.Profiling;
namespace Pathfinding {
@@ -176,7 +177,7 @@ namespace Pathfinding {
}
}
if ((updateInterval >= 0 && Time.realtimeSinceStartup - lastUpdateTime > updateInterval) || anyInvalidHandlers) {
if ((updateInterval >= 0 && JNTime.Time.realtimeSinceStartup - lastUpdateTime > updateInterval) || anyInvalidHandlers) {
ForceUpdate();
}
Profiler.EndSample();
@@ -200,7 +201,7 @@ namespace Pathfinding {
/// </code>
/// </summary>
public void ForceUpdate () {
lastUpdateTime = Time.realtimeSinceStartup;
lastUpdateTime = JNTime.Time.realtimeSinceStartup;
List<NavmeshClipper> hasBeenUpdated = null;

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using Plugins.JNGame.Sync.Frame.Entity;
using UnityEditor;
namespace Pathfinding {
@@ -55,7 +56,7 @@ namespace Pathfinding {
void Tick () {
if (Event.current.type == EventType.Repaint) {
float deltaTime = Time.realtimeSinceStartup-lastUpdate;
float deltaTime = JNTime.Time.realtimeSinceStartup-lastUpdate;
// Right at the start of a transition the deltaTime will
// not be reliable, so use a very small value instead
@@ -66,7 +67,7 @@ namespace Pathfinding {
// Larger regions fade slightly slower
deltaTime /= Mathf.Sqrt(Mathf.Max(lastRect.height, 100));
lastUpdate = Time.realtimeSinceStartup;
lastUpdate = JNTime.Time.realtimeSinceStartup;
float targetValue = open ? 1F : 0F;

View File

@@ -23,7 +23,7 @@ namespace Pathfinding.RVO {
/// // Calculate how much to move during this frame
/// // This information is based on movement commands from earlier frames
/// // as local avoidance is calculated globally at regular intervals by the RVOSimulator component
/// var delta = controller.CalculateMovementDelta(transform.position, Time.deltaTime);
/// var delta = controller.CalculateMovementDelta(transform.position, GetSync().Time.deltaTime);
/// transform.position = transform.position + delta;
/// }
/// </code>
@@ -264,10 +264,10 @@ namespace Pathfinding.RVO {
/// </summary>
public Vector3 velocity {
get {
// For best accuracy and to allow other code to do things like Move(agent.velocity * Time.deltaTime)
// For best accuracy and to allow other code to do things like Move(agent.velocity * GetSync().Time.deltaTime)
// the code bases the velocity on how far the agent should move during this frame.
// Unless the game is paused (timescale is zero) then just use a very small dt.
var dt = Time.deltaTime > 0.0001f ? Time.deltaTime : 0.02f;
var dt = GetSync().Time.deltaTime > 0.0001f ? GetSync().Time.deltaTime : 0.02f;
return CalculateMovementDelta(dt) / dt;
}
set {
@@ -281,7 +281,7 @@ namespace Pathfinding.RVO {
/// The position of the agent is taken from the attached movement script's position (see <see cref="Pathfinding.IAstarAI.position)"/> or if none is attached then transform.position.
/// </summary>
/// <param name="deltaTime">How far to move [seconds].
/// Usually set to Time.deltaTime.</param>
/// Usually set to GetSync().Time.deltaTime.</param>
public Vector3 CalculateMovementDelta (float deltaTime) {
if (rvoAgent == null) return Vector3.zero;
return To3D(Vector2.ClampMagnitude(rvoAgent.CalculatedTargetPoint - To2D(ai != null ? ai.position : tr.position), rvoAgent.CalculatedSpeed * deltaTime), 0);
@@ -308,7 +308,7 @@ namespace Pathfinding.RVO {
/// </summary>
/// <param name="position">Position of the agent.</param>
/// <param name="deltaTime">How far to move [seconds].
/// Usually set to Time.deltaTime.</param>
/// Usually set to GetSync().Time.deltaTime.</param>
public Vector3 CalculateMovementDelta (Vector3 position, float deltaTime) {
return To3D(Vector2.ClampMagnitude(rvoAgent.CalculatedTargetPoint - To2D(position), rvoAgent.CalculatedSpeed * deltaTime), 0);
}

View File

@@ -38,7 +38,7 @@ namespace Pathfinding.Examples {
// Rotate character to face the correct direction
while (true) {
var origRotation = ai.rotation;
var finalRotation = ai.SimulateRotationTowards(rs.first.forward, ai.rotationSpeed * Time.deltaTime);
var finalRotation = ai.SimulateRotationTowards(rs.first.forward, ai.rotationSpeed * GetSync().Time.deltaTime);
// Rotate until the rotation does not change anymore
if (origRotation == finalRotation) break;
ai.FinalizeMovement(ai.position, finalRotation);

View File

@@ -42,7 +42,7 @@ namespace Pathfinding {
/// If AstarPath.batchGraphUpdates is enabled, it is not beneficial to have a checkTime much lower
/// than AstarPath.graphUpdateBatchingInterval because that will just add extra unnecessary graph updates.
///
/// In real time seconds (based on Time.realtimeSinceStartup).
/// In real time seconds (based on GetSync().Time.realtimeSinceStartup).
/// </summary>
public float checkTime = 0.2F;
@@ -105,7 +105,9 @@ namespace Pathfinding {
if (coll != null) prevEnabled = colliderEnabled;
}
void Update () {
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (!Application.isPlaying) return;
if (coll == null && coll2D == null) {
@@ -121,11 +123,11 @@ namespace Pathfinding {
pendingGraphUpdates.Dequeue();
}
if (AstarPath.active == null || AstarPath.active.isScanning || Time.realtimeSinceStartup - lastCheckTime < checkTime || !Application.isPlaying || pendingGraphUpdates.Count > 0) {
if (AstarPath.active == null || AstarPath.active.isScanning || GetSync().Time.realtimeSinceStartup - lastCheckTime < checkTime || !Application.isPlaying || pendingGraphUpdates.Count > 0) {
return;
}
lastCheckTime = Time.realtimeSinceStartup;
lastCheckTime = GetSync().Time.realtimeSinceStartup;
if (colliderEnabled) {
// The current bounds of the collider
Bounds newBounds = bounds;
@@ -141,7 +143,7 @@ namespace Pathfinding {
// If the difference between the previous bounds and the new bounds is greater than some value, update the graphs
if (minDiff.sqrMagnitude > updateError*updateError || maxDiff.sqrMagnitude > updateError*updateError ||
errorFromRotation > updateError || !prevEnabled) {
errorFromRotation > updateError || !prevEnabled) {
// Update the graphs as soon as possible
DoUpdateGraphs();
}
@@ -225,7 +227,7 @@ namespace Pathfinding {
prevRotation = tr.rotation;
// Set this here as well since the DoUpdateGraphs method can be called from other scripts
lastCheckTime = Time.realtimeSinceStartup;
lastCheckTime = GetSync().Time.realtimeSinceStartup;
}
/// <summary>Volume of a Bounds object. X*Y*Z</summary>

View File

@@ -1,5 +1,6 @@
using Pathfinding.Util;
using System.Collections.Generic;
using Game.Plugins.App.Util;
using UnityEngine;
namespace Pathfinding {
@@ -434,7 +435,7 @@ namespace Pathfinding {
// the chances next time
clearanceRadius *= 0.9f;
// This will pick points in 2D closer to the edge of the circle with a higher probability
dir = Random.onUnitSphere * Mathf.Lerp(newMagn, radius, tests / 5);
dir = JNRandom.onUnitSphere * Mathf.Lerp(newMagn, radius, tests / 5);
dir.y = 0;
tests++;
}
@@ -500,7 +501,7 @@ namespace Pathfinding {
}
// Pick a random node among the ones in the list weighted by their area
float tg = Random.value*tot;
float tg = JNRandom.value*tot;
int v = accs.BinarySearch(tg);
if (v < 0) v = ~v;

View File

@@ -1,5 +1,6 @@
using UnityEngine;
using System.Collections.Generic;
using Plugins.JNGame.Sync.Frame.Entity;
#if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling;
#endif
@@ -244,7 +245,7 @@ namespace Pathfinding.Util {
public GraphGizmoHelper GetSingleFrameGizmoHelper (AstarPath active) {
var uniqHash = new RetainedGizmos.Hasher();
uniqHash.AddHash(Time.realtimeSinceStartup.GetHashCode());
uniqHash.AddHash(JNTime.Time.realtimeSinceStartup.GetHashCode());
Draw(uniqHash);
return GetGizmoHelper(active, uniqHash);
}