This commit is contained in:
PC-20230316NUNE\Administrator
2024-02-01 19:06:51 +08:00
parent aa4d6c3ce2
commit 877dca3b43
7518 changed files with 653768 additions and 162059 deletions

View File

@@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 2d30537472b53490da7c32972120c523
folderAsset: yes
timeCreated: 1490877053
licenseType: Store
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
// This file has been removed from the project. Since UnityPackages cannot
// delete files, only replace them, this message is left here to prevent old
// files from causing compiler errors

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4075ffc0df8c943368fa824db55589b4
timeCreated: 1491232013
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
// This file has been removed from the project. Since UnityPackages cannot
// delete files, only replace them, this message is left here to prevent old
// files from causing compiler errors

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f97cec2d4f06c4d0eb0068c24cb47ca1
timeCreated: 1490879139
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
// This file has been removed from the project. Since UnityPackages cannot
// delete files, only replace them, this message is left here to prevent old
// files from causing compiler errors

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: de195cf1c91924838ac8f0fedf5fa216
timeCreated: 1490877060
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,4 @@
// This file has been removed from the project. Since UnityPackages cannot
// delete files, only replace them, this message is left here to prevent old
// files from causing compiler errors

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 60b238a5bdb294eb48cfc8aff10ac9b5
timeCreated: 1491232013
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,302 @@
#pragma warning disable 618
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
namespace Pathfinding.Legacy {
using Pathfinding;
using Pathfinding.RVO;
/// <summary>
/// AI for following paths.
/// This AI is the default movement script which comes with the A* Pathfinding Project.
/// It is in no way required by the rest of the system, so feel free to write your own. But I hope this script will make it easier
/// to set up movement for the characters in your game. This script is not written for high performance, so I do not recommend using it for large groups of units.
///
/// This script will try to follow a target transform, in regular intervals, the path to that target will be recalculated.
/// It will on FixedUpdate try to move towards the next point in the path.
/// However it will only move in the forward direction, but it will rotate around it's Y-axis
/// to make it reach the target.
///
/// \section variables Quick overview of the variables
/// In the inspector in Unity, you will see a bunch of variables. You can view detailed information further down, but here's a quick overview.
/// The <see cref="repathRate"/> determines how often it will search for new paths, if you have fast moving targets, you might want to set it to a lower value.
/// The <see cref="target"/> variable is where the AI will try to move, it can be a point on the ground where the player has clicked in an RTS for example.
/// Or it can be the player object in a zombie game.
/// The speed is self-explanatory, so is turningSpeed, however <see cref="slowdownDistance"/> might require some explanation.
/// It is the approximate distance from the target where the AI will start to slow down. Note that this doesn't only affect the end point of the path
/// but also any intermediate points, so be sure to set <see cref="forwardLook"/> and <see cref="pickNextWaypointDist"/> to a higher value than this.
/// <see cref="pickNextWaypointDist"/> is simply determines within what range it will switch to target the next waypoint in the path.
/// <see cref="forwardLook"/> will try to calculate an interpolated target point on the current segment in the path so that it has a distance of <see cref="forwardLook"/> from the AI
/// Below is an image illustrating several variables as well as some internal ones, but which are relevant for understanding how it works.
/// Note that the <see cref="forwardLook"/> range will not match up exactly with the target point practically, even though that's the goal.
/// [Open online documentation to see images]
/// This script has many movement fallbacks.
/// If it finds a NavmeshController, it will use that, otherwise it will look for a character controller, then for a rigidbody and if it hasn't been able to find any
/// it will use Transform.Translate which is guaranteed to always work.
///
/// Deprecated: Use the AIPath class instead. This class only exists for compatibility reasons.
/// </summary>
[RequireComponent(typeof(Seeker))]
[AddComponentMenu("Pathfinding/Legacy/AI/Legacy AIPath (3D)")]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_legacy_1_1_legacy_a_i_path.php")]
public class LegacyAIPath : AIPath {
/// <summary>
/// Target point is Interpolated on the current segment in the path so that it has a distance of <see cref="forwardLook"/> from the AI.
/// See the detailed description of AIPath for an illustrative image
/// </summary>
public float forwardLook = 1;
/// <summary>
/// Do a closest point on path check when receiving path callback.
/// Usually the AI has moved a bit between requesting the path, and getting it back, and there is usually a small gap between the AI
/// and the closest node.
/// If this option is enabled, it will simulate, when the path callback is received, movement between the closest node and the current
/// AI position. This helps to reduce the moments when the AI just get a new path back, and thinks it ought to move backwards to the start of the new path
/// even though it really should just proceed forward.
/// </summary>
public bool closestOnPathCheck = true;
protected float minMoveScale = 0.05F;
/// <summary>Current index in the path which is current target</summary>
protected int currentWaypointIndex = 0;
protected Vector3 lastFoundWaypointPosition;
protected float lastFoundWaypointTime = -9999;
public override void OnSyncLoad()
{
base.OnSyncLoad();
if (rvoController != null) {
if (rvoController is LegacyRVOController) (rvoController as LegacyRVOController).enableRotation = false;
else Debug.LogError("The LegacyAIPath component only works with the legacy RVOController, not the latest one. Please upgrade this component", this);
}
}
/// <summary>
/// Called when a requested path has finished calculation.
/// A path is first requested by <see cref="SearchPath"/>, it is then calculated, probably in the same or the next frame.
/// Finally it is returned to the seeker which forwards it to this function.
/// </summary>
protected override void OnPathComplete (Path _p) {
ABPath p = _p as ABPath;
if (p == null) throw new System.Exception("This function only handles ABPaths, do not use special path types");
waitingForPathCalculation = false;
//Claim the new path
p.Claim(this);
// Path couldn't be calculated of some reason.
// More info in p.errorLog (debug string)
if (p.error) {
p.Release(this);
return;
}
//Release the previous path
if (path != null) path.Release(this);
//Replace the old path
path = p;
//Reset some variables
currentWaypointIndex = 0;
reachedEndOfPath = false;
//The next row can be used to find out if the path could be found or not
//If it couldn't (error == true), then a message has probably been logged to the console
//however it can also be got using p.errorLog
//if (p.error)
if (closestOnPathCheck) {
// Simulate movement from the point where the path was requested
// to where we are right now. This reduces the risk that the agent
// 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 p2 = GetFeetPosition();
Vector3 dir = p2-p1;
float magn = dir.magnitude;
dir /= magn;
int steps = (int)(magn/pickNextWaypointDist);
#if ASTARDEBUG
Debug.DrawLine(p1, p2, Color.red, 1);
#endif
for (int i = 0; i <= steps; i++) {
CalculateVelocity(p1);
p1 += dir;
}
}
}
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
if (!canMove) { return; }
Vector3 dir = CalculateVelocity(GetFeetPosition());
//Rotate towards targetDirection (filled in by CalculateVelocity)
RotateTowards(targetDirection);
if (rvoController != null) {
rvoController.Move(dir);
} else
if (controller != null) {
controller.SimpleMove(dir);
} else if (rigid != null) {
rigid.AddForce(dir);
} else {
tr.Translate(dir*Time.deltaTime, Space.World);
}
}
/// <summary>
/// Relative direction to where the AI is heading.
/// Filled in by <see cref="CalculateVelocity"/>
/// </summary>
protected new Vector3 targetDirection;
protected float XZSqrMagnitude (Vector3 a, Vector3 b) {
float dx = b.x-a.x;
float dz = b.z-a.z;
return dx*dx + dz*dz;
}
/// <summary>
/// Calculates desired velocity.
/// Finds the target path segment and returns the forward direction, scaled with speed.
/// A whole bunch of restrictions on the velocity is applied to make sure it doesn't overshoot, does not look too far ahead,
/// and slows down when close to the target.
/// /see speed
/// /see endReachedDistance
/// /see slowdownDistance
/// /see CalculateTargetPoint
/// /see targetPoint
/// /see targetDirection
/// /see currentWaypointIndex
/// </summary>
protected new Vector3 CalculateVelocity (Vector3 currentPosition) {
if (path == null || path.vectorPath == null || path.vectorPath.Count == 0) return Vector3.zero;
List<Vector3> vPath = path.vectorPath;
if (vPath.Count == 1) {
vPath.Insert(0, currentPosition);
}
if (currentWaypointIndex >= vPath.Count) { currentWaypointIndex = vPath.Count-1; }
if (currentWaypointIndex <= 1) currentWaypointIndex = 1;
while (true) {
if (currentWaypointIndex < vPath.Count-1) {
//There is a "next path segment"
float dist = XZSqrMagnitude(vPath[currentWaypointIndex], currentPosition);
//Mathfx.DistancePointSegmentStrict (vPath[currentWaypointIndex+1],vPath[currentWaypointIndex+2],currentPosition);
if (dist < pickNextWaypointDist*pickNextWaypointDist) {
lastFoundWaypointPosition = currentPosition;
lastFoundWaypointTime = Time.time;
currentWaypointIndex++;
} else {
break;
}
} else {
break;
}
}
Vector3 dir = vPath[currentWaypointIndex] - vPath[currentWaypointIndex-1];
Vector3 targetPosition = CalculateTargetPoint(currentPosition, vPath[currentWaypointIndex-1], vPath[currentWaypointIndex]);
dir = targetPosition-currentPosition;
dir.y = 0;
float targetDist = dir.magnitude;
float slowdown = Mathf.Clamp01(targetDist / slowdownDistance);
this.targetDirection = dir;
if (currentWaypointIndex == vPath.Count-1 && targetDist <= endReachedDistance) {
if (!reachedEndOfPath) { reachedEndOfPath = true; OnTargetReached(); }
//Send a move request, this ensures gravity is applied
return Vector3.zero;
}
Vector3 forward = tr.forward;
float dot = Vector3.Dot(dir.normalized, forward);
float sp = maxSpeed * Mathf.Max(dot, minMoveScale) * slowdown;
#if ASTARDEBUG
Debug.DrawLine(vPath[currentWaypointIndex-1], vPath[currentWaypointIndex], Color.black);
Debug.DrawLine(GetFeetPosition(), targetPosition, Color.red);
Debug.DrawRay(targetPosition, Vector3.up, Color.red);
Debug.DrawRay(GetFeetPosition(), dir, Color.yellow);
Debug.DrawRay(GetFeetPosition(), forward*sp, Color.cyan);
#endif
if (Time.deltaTime > 0) {
sp = Mathf.Clamp(sp, 0, targetDist/(Time.deltaTime*2));
}
return forward*sp;
}
/// <summary>
/// Rotates in the specified direction.
/// Rotates around the Y-axis.
/// See: turningSpeed
/// </summary>
protected void RotateTowards (Vector3 dir) {
if (dir == Vector3.zero) return;
Quaternion rot = tr.rotation;
Quaternion toTarget = Quaternion.LookRotation(dir);
rot = Quaternion.Slerp(rot, toTarget, turningSpeed*Time.deltaTime);
Vector3 euler = rot.eulerAngles;
euler.z = 0;
euler.x = 0;
rot = Quaternion.Euler(euler);
tr.rotation = rot;
}
/// <summary>
/// Calculates target point from the current line segment.
/// See: <see cref="forwardLook"/>
/// TODO: This function uses .magnitude quite a lot, can it be optimized?
/// </summary>
/// <param name="p">Current position</param>
/// <param name="a">Line segment start</param>
/// <param name="b">Line segment end
/// The returned point will lie somewhere on the line segment.</param>
protected Vector3 CalculateTargetPoint (Vector3 p, Vector3 a, Vector3 b) {
a.y = p.y;
b.y = p.y;
float magn = (a-b).magnitude;
if (magn == 0) return a;
float closest = Mathf.Clamp01(VectorMath.ClosestPointOnLineFactor(a, b, p));
Vector3 point = (b-a)*closest + a;
float distance = (point-p).magnitude;
float lookAhead = Mathf.Clamp(forwardLook - distance, 0.0F, forwardLook);
float offset = lookAhead / magn;
offset = Mathf.Clamp(offset+closest, 0.0F, 1.0F);
return (b-a)*offset + a;
}
}
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c5ac18cdd242041b6bebc0e95b624c85
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}

View File

@@ -0,0 +1,55 @@
using UnityEngine;
using Pathfinding;
using System.Collections.Generic;
namespace Pathfinding.Legacy {
using Pathfinding.RVO;
/// <summary>
/// RVO Character Controller.
/// Designed to be used as a drop-in replacement for the Unity Character Controller,
/// it supports almost all of the same functions and fields with the exception
/// that due to the nature of the RVO implementation, desired velocity is set in the Move function
/// and is assumed to stay the same until something else is requested (as opposed to reset every frame).
///
/// For documentation of many of the variables of this class: refer to the Pathfinding.RVO.IAgent interface.
///
/// Note: Requires an RVOSimulator in the scene
///
/// See: Pathfinding.RVO.IAgent
/// See: RVOSimulator
///
/// Deprecated: Use the RVOController class instead. This class only exists for compatibility reasons.
/// </summary>
[AddComponentMenu("Pathfinding/Legacy/Local Avoidance/Legacy RVO Controller")]
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_legacy_1_1_legacy_r_v_o_controller.php")]
public class LegacyRVOController : RVOController {
/// <summary>
/// Layer mask for the ground.
/// The RVOController will raycast down to check for the ground to figure out where to place the agent.
/// </summary>
[Tooltip("Layer mask for the ground. The RVOController will raycast down to check for the ground to figure out where to place the agent")]
public new LayerMask mask = -1;
public new bool enableRotation = true;
public new float rotationSpeed = 30;
public void Update () {
if (rvoAgent == null) return;
RaycastHit hit;
Vector3 pos = tr.position + CalculateMovementDelta(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;
} else {
pos.y = 0;
}
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));
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 533427594e96f4344a2564c629ef0383
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: -200
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,295 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using Pathfinding.RVO;
namespace Pathfinding.Legacy {
[RequireComponent(typeof(Seeker))]
[AddComponentMenu("Pathfinding/Legacy/AI/Legacy RichAI (3D, for navmesh)")]
/// <summary>
/// Advanced AI for navmesh based graphs.
///
/// Deprecated: Use the RichAI class instead. This class only exists for compatibility reasons.
/// </summary>
[HelpURL("https://arongranberg.com/astar/documentation/stable/class_pathfinding_1_1_legacy_1_1_legacy_rich_a_i.php")]
public class LegacyRichAI : RichAI {
/// <summary>
/// Use a 3rd degree equation for calculating slowdown acceleration instead of a 2nd degree.
/// A 3rd degree equation can also make sure that the velocity when reaching the target is roughly zero and therefore
/// it will have a more direct stop. In contrast solving a 2nd degree equation which will just make sure the target is reached but
/// will usually have a larger velocity when reaching the target and therefore look more "bouncy".
/// </summary>
public bool preciseSlowdown = true;
public bool raycastingForGroundPlacement = false;
/// <summary>
/// Current velocity of the agent.
/// Includes eventual velocity due to gravity
/// </summary>
new Vector3 velocity;
Vector3 lastTargetPoint;
Vector3 currentTargetDirection;
public override void OnSyncLoad()
{
base.OnSyncLoad();
if (rvoController != null) {
if (rvoController is LegacyRVOController) (rvoController as LegacyRVOController).enableRotation = false;
else Debug.LogError("The LegacyRichAI component only works with the legacy RVOController, not the latest one. Please upgrade this component", this);
}
}
/// <summary>Smooth delta time to avoid getting overly affected by e.g GC</summary>
static float deltaTime;
public override void OnSyncUpdate(int dt, JNFrameInfo frame, Object input)
{
base.OnSyncUpdate(dt, frame, input);
deltaTime = Mathf.Min(Time.smoothDeltaTime*2, Time.deltaTime);
if (richPath != null) {
//System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
//w.Start();
RichPathPart pt = richPath.GetCurrentPart();
var fn = pt as RichFunnel;
if (fn != null) {
//Clear buffers for reuse
Vector3 position = UpdateTarget(fn);
//tr.position = ps;
//Only get walls every 5th frame to save on performance
if (Time.frameCount % 5 == 0 && wallForce > 0 && wallDist > 0) {
wallBuffer.Clear();
fn.FindWalls(wallBuffer, wallDist);
}
/*for (int i=0;i<wallBuffer.Count;i+=2) {
* Debug.DrawLine (wallBuffer[i],wallBuffer[i+1],Color.magenta);
* }*/
//Pick next waypoint if current is reached
int tgIndex = 0;
/*if (buffer.Count > 1) {
* if ((buffer[tgIndex]-tr.position).sqrMagnitude < pickNextWaypointDist*pickNextWaypointDist) {
* tgIndex++;
* }
* }*/
//Target point
Vector3 tg = nextCorners[tgIndex];
Vector3 dir = tg-position;
dir.y = 0;
bool passedTarget = Vector3.Dot(dir, currentTargetDirection) < 0;
//Check if passed target in another way
if (passedTarget && nextCorners.Count-tgIndex > 1) {
tgIndex++;
tg = nextCorners[tgIndex];
}
if (tg != lastTargetPoint) {
currentTargetDirection = (tg - position);
currentTargetDirection.y = 0;
currentTargetDirection.Normalize();
lastTargetPoint = tg;
//Debug.DrawRay (tr.position, Vector3.down*2,Color.blue,0.2f);
}
//Direction to target
dir = (tg-position);
dir.y = 0;
float magn = dir.magnitude;
//Write out for other scripts to read
distanceToSteeringTarget = magn;
//Normalize
dir = magn == 0 ? Vector3.zero : dir/magn;
Vector3 normdir = dir;
Vector3 force = Vector3.zero;
if (wallForce > 0 && wallDist > 0) {
float wLeft = 0;
float wRight = 0;
for (int i = 0; i < wallBuffer.Count; i += 2) {
Vector3 closest = VectorMath.ClosestPointOnSegment(wallBuffer[i], wallBuffer[i+1], tr.position);
float dist = (closest-position).sqrMagnitude;
if (dist > wallDist*wallDist) continue;
Vector3 tang = (wallBuffer[i+1]-wallBuffer[i]).normalized;
//Using the fact that all walls are laid out clockwise (seeing from inside)
//Then left and right (ish) can be figured out like this
float dot = Vector3.Dot(dir, tang) * (1 - System.Math.Max(0, (2*(dist / (wallDist*wallDist))-1)));
if (dot > 0) wRight = System.Math.Max(wRight, dot);
else wLeft = System.Math.Max(wLeft, -dot);
}
Vector3 norm = Vector3.Cross(Vector3.up, dir);
force = norm*(wRight-wLeft);
//Debug.DrawRay (tr.position, force, Color.cyan);
}
//Is the endpoint of the path (part) the current target point
bool endPointIsTarget = lastCorner && nextCorners.Count-tgIndex == 1;
if (endPointIsTarget) {
//Use 2nd or 3rd degree motion equation to figure out acceleration to reach target in "exact" [slowdownTime] seconds
//Clamp to avoid divide by zero
if (slowdownTime < 0.001f) {
slowdownTime = 0.001f;
}
Vector3 diff = tg - position;
diff.y = 0;
if (preciseSlowdown) {
//{ t = slowdownTime
//{ diff = vt + at^2/2 + qt^3/6
//{ 0 = at + qt^2/2
//{ solve for a
dir = (6*diff - 4*slowdownTime*velocity)/(slowdownTime*slowdownTime);
} else {
dir = 2*(diff - slowdownTime*velocity)/(slowdownTime*slowdownTime);
}
dir = Vector3.ClampMagnitude(dir, acceleration);
force *= System.Math.Min(magn/0.5f, 1);
if (magn < endReachedDistance) {
//END REACHED
NextPart();
}
} else {
dir *= acceleration;
}
//Debug.DrawRay (tr.position+Vector3.up, dir*3, Color.blue);
velocity += (dir + force*wallForce)*deltaTime;
if (slowWhenNotFacingTarget) {
float dot = (Vector3.Dot(normdir, tr.forward)+0.5f)*(1.0f/1.5f);
//velocity = Vector3.ClampMagnitude (velocity, maxSpeed * Mathf.Max (dot, 0.2f) );
float xzmagn = Mathf.Sqrt(velocity.x*velocity.x + velocity.z*velocity.z);
float prevy = velocity.y;
velocity.y = 0;
float mg = Mathf.Min(xzmagn, maxSpeed * Mathf.Max(dot, 0.2f));
velocity = Vector3.Lerp(tr.forward * mg, velocity.normalized * mg, Mathf.Clamp(endPointIsTarget ? (magn*2) : 0, 0.5f, 1.0f));
velocity.y = prevy;
} else {
// Clamp magnitude on the XZ axes
float xzmagn = Mathf.Sqrt(velocity.x*velocity.x + velocity.z*velocity.z);
xzmagn = maxSpeed/xzmagn;
if (xzmagn < 1) {
velocity.x *= xzmagn;
velocity.z *= xzmagn;
//Vector3.ClampMagnitude (velocity, maxSpeed);
}
}
//Debug.DrawLine (tr.position, tg, lastCorner ? Color.red : Color.green);
if (endPointIsTarget) {
Vector3 trotdir = Vector3.Lerp(velocity, currentTargetDirection, System.Math.Max(1 - magn*2, 0));
RotateTowards(trotdir);
} else {
RotateTowards(velocity);
}
//Applied after rotation to enable proper checks on if velocity is zero
velocity += deltaTime * gravity;
if (rvoController != null && rvoController.enabled) {
//Use RVOController
tr.position = position;
rvoController.Move(velocity);
} else
if (controller != null && controller.enabled) {
//Use CharacterController
tr.position = position;
controller.Move(velocity * deltaTime);
} else {
//Use Transform
float lasty = position.y;
position += velocity*deltaTime;
position = RaycastPosition(position, lasty);
tr.position = position;
}
} else {
if (rvoController != null && rvoController.enabled) {
//Use RVOController
rvoController.Move(Vector3.zero);
}
}
if (pt is RichSpecial) {
if (!traversingOffMeshLink) {
StartCoroutine(TraverseSpecial(pt as RichSpecial));
}
}
//w.Stop();
//Debug.Log ((w.Elapsed.TotalMilliseconds*1000));
} else {
if (rvoController != null && rvoController.enabled) {
//Use RVOController
rvoController.Move(Vector3.zero);
} else
if (controller != null && controller.enabled) {
} else {
tr.position = RaycastPosition(tr.position, tr.position.y);
}
}
UpdateVelocity();
lastDeltaTime = Time.deltaTime;
}
/// <summary>Update is called once per frame</summary>
new Vector3 RaycastPosition (Vector3 position, float lasty) {
if (raycastingForGroundPlacement) {
RaycastHit hit;
float up = Mathf.Max(height*0.5f, lasty-position.y+height*0.5f);
if (Physics.Raycast(position+Vector3.up*up, Vector3.down, out hit, up, groundMask)) {
if (hit.distance < up) {
//grounded
position = hit.point;//.up * -(hit.distance-centerOffset);
velocity.y = 0;
}
}
}
return position;
}
/// <summary>Rotates along the Y-axis the transform towards trotdir</summary>
bool RotateTowards (Vector3 trotdir) {
trotdir.y = 0;
if (trotdir != Vector3.zero) {
Quaternion rot = tr.rotation;
Vector3 trot = Quaternion.LookRotation(trotdir).eulerAngles;
Vector3 eul = rot.eulerAngles;
eul.y = Mathf.MoveTowardsAngle(eul.y, trot.y, rotationSpeed*deltaTime);
tr.rotation = Quaternion.Euler(eul);
//Magic number, should expose as variable
return Mathf.Abs(eul.y-trot.y) < 5f;
}
return false;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1f789196df654477383806c1ab239336
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,152 @@
using UnityEngine;
using Pathfinding.Util;
namespace Pathfinding {
// Obsolete methods in AIPath
public partial class AIPath {
/// <summary>
/// True if the end of the path has been reached.
/// Deprecated: When unifying the interfaces for different movement scripts, this property has been renamed to <see cref="reachedEndOfPath"/>
/// </summary>
[System.Obsolete("When unifying the interfaces for different movement scripts, this property has been renamed to reachedEndOfPath. [AstarUpgradable: 'TargetReached' -> 'reachedEndOfPath']")]
public bool TargetReached { get { return reachedEndOfPath; } }
/// <summary>
/// Rotation speed.
/// Deprecated: This field has been renamed to <see cref="rotationSpeed"/> and is now in degrees per second instead of a damping factor.
/// </summary>
[System.Obsolete("This field has been renamed to #rotationSpeed and is now in degrees per second instead of a damping factor")]
public float turningSpeed { get { return rotationSpeed/90; } set { rotationSpeed = value*90; } }
/// <summary>
/// Maximum speed in world units per second.
/// Deprecated: Use <see cref="maxSpeed"/> instead
/// </summary>
[System.Obsolete("This member has been deprecated. Use 'maxSpeed' instead. [AstarUpgradable: 'speed' -> 'maxSpeed']")]
public float speed { get { return maxSpeed; } set { maxSpeed = value; } }
/// <summary>
/// Direction that the agent wants to move in (excluding physics and local avoidance).
/// Deprecated: Only exists for compatibility reasons. Use <see cref="desiredVelocity"/> or <see cref="steeringTarget"/> instead instead.
/// </summary>
[System.Obsolete("Only exists for compatibility reasons. Use desiredVelocity or steeringTarget instead.")]
public Vector3 targetDirection {
get {
return (steeringTarget - tr.position).normalized;
}
}
/// <summary>
/// Current desired velocity of the agent (excluding physics and local avoidance but it includes gravity).
/// Deprecated: This method no longer calculates the velocity. Use the <see cref="desiredVelocity"/> property instead.
/// </summary>
[System.Obsolete("This method no longer calculates the velocity. Use the desiredVelocity property instead")]
public Vector3 CalculateVelocity (Vector3 position) {
return desiredVelocity;
}
}
// Obsolete methods in RichAI
public partial class RichAI {
/// <summary>
/// Force recalculation of the current path.
/// If there is an ongoing path calculation, it will be canceled (so make sure you leave time for the paths to get calculated before calling this function again).
///
/// Deprecated: Use <see cref="SearchPath"/> instead
/// </summary>
[System.Obsolete("Use SearchPath instead. [AstarUpgradable: 'UpdatePath' -> 'SearchPath']")]
public void UpdatePath () {
SearchPath();
}
/// <summary>
/// Current velocity of the agent.
/// Includes velocity due to gravity.
/// Deprecated: Use <see cref="velocity"/> instead (lowercase 'v').
/// </summary>
[System.Obsolete("Use velocity instead (lowercase 'v'). [AstarUpgradable: 'Velocity' -> 'velocity']")]
public Vector3 Velocity { get { return velocity; } }
/// <summary>
/// Waypoint that the agent is moving towards.
/// This is either a corner in the path or the end of the path.
/// Deprecated: Use steeringTarget instead.
/// </summary>
[System.Obsolete("Use steeringTarget instead. [AstarUpgradable: 'NextWaypoint' -> 'steeringTarget']")]
public Vector3 NextWaypoint { get { return steeringTarget; } }
/// <summary>
/// \details
/// Deprecated: Use Vector3.Distance(transform.position, ai.steeringTarget) instead.
/// </summary>
[System.Obsolete("Use Vector3.Distance(transform.position, ai.steeringTarget) instead.")]
public float DistanceToNextWaypoint { get { return distanceToSteeringTarget; } }
/// <summary>Search for new paths repeatedly</summary>
[System.Obsolete("Use canSearch instead. [AstarUpgradable: 'repeatedlySearchPaths' -> 'canSearch']")]
public bool repeatedlySearchPaths { get { return canSearch; } set { canSearch = value; } }
/// <summary>
/// True if the end of the path has been reached.
/// Deprecated: When unifying the interfaces for different movement scripts, this property has been renamed to <see cref="reachedEndOfPath"/>
/// </summary>
[System.Obsolete("When unifying the interfaces for different movement scripts, this property has been renamed to reachedEndOfPath (lowercase t). [AstarUpgradable: 'TargetReached' -> 'reachedEndOfPath']")]
public bool TargetReached { get { return reachedEndOfPath; } }
/// <summary>
/// True if a path to the target is currently being calculated.
/// Deprecated: Use <see cref="pathPending"/> instead (lowercase 'p').
/// </summary>
[System.Obsolete("Use pathPending instead (lowercase 'p'). [AstarUpgradable: 'PathPending' -> 'pathPending']")]
public bool PathPending { get { return pathPending; } }
/// <summary>
/// \details
/// Deprecated: Use approachingPartEndpoint (lowercase 'a') instead
/// </summary>
[System.Obsolete("Use approachingPartEndpoint (lowercase 'a') instead")]
public bool ApproachingPartEndpoint { get { return approachingPartEndpoint; } }
/// <summary>
/// \details
/// Deprecated: Use approachingPathEndpoint (lowercase 'a') instead
/// </summary>
[System.Obsolete("Use approachingPathEndpoint (lowercase 'a') instead")]
public bool ApproachingPathEndpoint { get { return approachingPathEndpoint; } }
/// <summary>
/// \details
/// Deprecated: This property has been renamed to 'traversingOffMeshLink'
/// </summary>
[System.Obsolete("This property has been renamed to 'traversingOffMeshLink'. [AstarUpgradable: 'TraversingSpecial' -> 'traversingOffMeshLink']")]
public bool TraversingSpecial { get { return traversingOffMeshLink; } }
/// <summary>
/// Current waypoint that the agent is moving towards.
/// Deprecated: This property has been renamed to <see cref="steeringTarget"/>
/// </summary>
[System.Obsolete("This property has been renamed to steeringTarget")]
public Vector3 TargetPoint { get { return steeringTarget; } }
[UnityEngine.Serialization.FormerlySerializedAs("anim")][SerializeField][HideInInspector]
Animation animCompatibility;
/// <summary>
/// Anim for off-mesh links.
/// Deprecated: Use the onTraverseOffMeshLink event or the ... component instead. Setting this value will add a ... component
/// </summary>
[System.Obsolete("Use the onTraverseOffMeshLink event or the ... component instead. Setting this value will add a ... component")]
public Animation anim {
get {
var setter = GetComponent<Pathfinding.Examples.AnimationLinkTraverser>();
return setter != null ? setter.anim : null;
}
set {
animCompatibility = null;
var setter = GetComponent<Pathfinding.Examples.AnimationLinkTraverser>();
if (setter == null) setter = gameObject.AddComponent<Pathfinding.Examples.AnimationLinkTraverser>();
setter.anim = value;
}
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8caf3dccb5aae46daa9684e513307841
timeCreated: 1498571379
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: