123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263 |
- using UnityEngine;
- using System.Collections.Generic;
- namespace Pathfinding.RVO {}
- namespace Pathfinding {
- using Pathfinding.Util;
- [System.Serializable]
-
- public class AstarColor {
- public Color _SolidColor;
- public Color _UnwalkableNode;
- public Color _BoundsHandles;
- public Color _ConnectionLowLerp;
- public Color _ConnectionHighLerp;
- public Color _MeshEdgeColor;
-
-
-
-
- public Color[] _AreaColors;
- public static Color SolidColor = new Color(30/255f, 102/255f, 201/255f, 0.9F);
- public static Color UnwalkableNode = new Color(1, 0, 0, 0.5F);
- public static Color BoundsHandles = new Color(0.29F, 0.454F, 0.741F, 0.9F);
- public static Color ConnectionLowLerp = new Color(0, 1, 0, 0.5F);
- public static Color ConnectionHighLerp = new Color(1, 0, 0, 0.5F);
- public static Color MeshEdgeColor = new Color(0, 0, 0, 0.5F);
- private static Color[] AreaColors = new Color[1];
- public static int ColorHash () {
- var hash = SolidColor.GetHashCode() ^ UnwalkableNode.GetHashCode() ^ BoundsHandles.GetHashCode() ^ ConnectionLowLerp.GetHashCode() ^ ConnectionHighLerp.GetHashCode() ^ MeshEdgeColor.GetHashCode();
- for (int i = 0; i < AreaColors.Length; i++) hash = 7*hash ^ AreaColors[i].GetHashCode();
- return hash;
- }
-
-
-
-
-
- public static Color GetAreaColor (uint area) {
- if (area >= AreaColors.Length) return AstarMath.IntToColor((int)area, 1F);
- return AreaColors[(int)area];
- }
-
-
-
-
-
- public static Color GetTagColor (uint tag) {
- if (tag >= AreaColors.Length) return AstarMath.IntToColor((int)tag, 1F);
- return AreaColors[(int)tag];
- }
-
-
-
-
-
-
- public void PushToStatic (AstarPath astar) {
- _AreaColors = _AreaColors ?? new Color[1];
- SolidColor = _SolidColor;
- UnwalkableNode = _UnwalkableNode;
- BoundsHandles = _BoundsHandles;
- ConnectionLowLerp = _ConnectionLowLerp;
- ConnectionHighLerp = _ConnectionHighLerp;
- MeshEdgeColor = _MeshEdgeColor;
- AreaColors = _AreaColors;
- }
- public AstarColor () {
-
- _SolidColor = new Color(30/255f, 102/255f, 201/255f, 0.9F);
- _UnwalkableNode = new Color(1, 0, 0, 0.5F);
- _BoundsHandles = new Color(0.29F, 0.454F, 0.741F, 0.9F);
- _ConnectionLowLerp = new Color(0, 1, 0, 0.5F);
- _ConnectionHighLerp = new Color(1, 0, 0, 0.5F);
- _MeshEdgeColor = new Color(0, 0, 0, 0.5F);
- }
- }
-
-
-
-
-
-
-
- public struct GraphHitInfo {
-
-
-
-
- public Vector3 origin;
-
-
-
-
- public Vector3 point;
-
-
-
-
-
-
-
- public GraphNode node;
-
-
-
-
- public Vector3 tangentOrigin;
-
-
-
-
- public Vector3 tangent;
-
- public float distance {
- get {
- return (point-origin).magnitude;
- }
- }
- public GraphHitInfo (Vector3 point) {
- tangentOrigin = Vector3.zero;
- origin = Vector3.zero;
- this.point = point;
- node = null;
- tangent = Vector3.zero;
- }
- }
-
- public class NNConstraint {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public GraphMask graphMask = -1;
-
- public bool constrainArea;
-
- public int area = -1;
-
- public bool constrainWalkability = true;
-
-
-
-
-
- public bool walkable = true;
-
-
-
-
-
-
-
-
-
- public bool distanceXZ;
-
-
-
-
- public bool constrainTags = true;
-
-
-
-
-
-
-
- public int tags = -1;
-
-
-
-
-
-
-
-
- public bool constrainDistance = true;
-
-
-
-
-
-
- public virtual bool SuitableGraph (int graphIndex, NavGraph graph) {
- return graphMask.Contains(graphIndex);
- }
-
- public virtual bool Suitable (GraphNode node) {
- if (constrainWalkability && node.Walkable != walkable) return false;
- if (constrainArea && area >= 0 && node.Area != area) return false;
- if (constrainTags && ((tags >> (int)node.Tag) & 0x1) == 0) return false;
- return true;
- }
-
-
-
-
-
-
- public static NNConstraint Default {
- get {
- return new NNConstraint();
- }
- }
-
- public static NNConstraint None {
- get {
- return new NNConstraint {
- constrainWalkability = false,
- constrainArea = false,
- constrainTags = false,
- constrainDistance = false,
- graphMask = -1,
- };
- }
- }
-
- public NNConstraint () {
- }
- }
-
-
-
-
-
- public class PathNNConstraint : NNConstraint {
- public static new PathNNConstraint Default {
- get {
- return new PathNNConstraint {
- constrainArea = true
- };
- }
- }
-
- public virtual void SetStart (GraphNode node) {
- if (node != null) {
- area = (int)node.Area;
- } else {
- constrainArea = false;
- }
- }
- }
-
-
-
-
- public struct NNInfoInternal {
-
-
-
-
-
- public GraphNode node;
-
-
-
-
- public GraphNode constrainedNode;
-
- public Vector3 clampedPosition;
-
- public Vector3 constClampedPosition;
- public NNInfoInternal (GraphNode node) {
- this.node = node;
- constrainedNode = null;
- clampedPosition = Vector3.zero;
- constClampedPosition = Vector3.zero;
- UpdateInfo();
- }
-
- public void UpdateInfo () {
- clampedPosition = node != null ? (Vector3)node.position : Vector3.zero;
- constClampedPosition = constrainedNode != null ? (Vector3)constrainedNode.position : Vector3.zero;
- }
- }
-
- public struct NNInfo {
-
- public readonly GraphNode node;
-
-
-
-
- public readonly Vector3 position;
-
-
-
-
- [System.Obsolete("This field has been renamed to 'position'")]
- public Vector3 clampedPosition {
- get {
- return position;
- }
- }
- public NNInfo (NNInfoInternal internalInfo) {
- node = internalInfo.node;
- position = internalInfo.clampedPosition;
- }
- public static explicit operator Vector3(NNInfo ob) {
- return ob.position;
- }
- public static explicit operator GraphNode(NNInfo ob) {
- return ob.node;
- }
- }
-
-
-
-
-
- public struct Progress {
-
- public readonly float progress;
-
- public readonly string description;
- public Progress (float progress, string description) {
- this.progress = progress;
- this.description = description;
- }
- public Progress MapTo (float min, float max, string prefix = null) {
- return new Progress(Mathf.Lerp(min, max, progress), prefix + description);
- }
- public override string ToString () {
- return progress.ToString("0.0") + " " + description;
- }
- }
-
- public interface IUpdatableGraph {
-
-
-
-
-
-
-
-
-
-
- void UpdateArea(GraphUpdateObject o);
-
-
-
-
- void UpdateAreaInit(GraphUpdateObject o);
-
-
-
-
- void UpdateAreaPost(GraphUpdateObject o);
- GraphUpdateThreading CanUpdateAsync(GraphUpdateObject o);
- }
-
- public enum GraphUpdateStage {
-
-
-
-
- Created,
-
- Pending,
-
- Applied,
-
-
-
-
- Aborted,
- }
-
-
-
-
-
- public class GraphUpdateObject {
-
-
-
-
- public Bounds bounds;
-
-
-
-
-
-
-
-
-
-
-
-
- [System.Obsolete("Not necessary anymore")]
- public bool requiresFloodFill { set {} }
-
-
-
-
-
-
-
-
-
-
-
-
-
- public bool updatePhysics = true;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public bool resetPenaltyOnPhysics = true;
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public bool updateErosion = true;
-
-
-
-
-
- public NNConstraint nnConstraint = NNConstraint.None;
-
-
-
-
- public int addPenalty;
-
-
-
-
-
- public bool modifyWalkability;
-
- public bool setWalkability;
-
- public bool modifyTag;
-
- public int setTag;
-
-
-
-
- public bool trackChangedNodes;
-
-
-
-
-
-
- public List<GraphNode> changedNodes;
- private List<uint> backupData;
- private List<Int3> backupPositionData;
-
-
-
-
-
-
- public GraphUpdateShape shape;
-
-
-
-
-
- internal int internalStage = STAGE_CREATED;
- internal const int STAGE_CREATED = -1;
- internal const int STAGE_PENDING = -2;
- internal const int STAGE_ABORTED = -3;
- internal const int STAGE_APPLIED = 0;
-
- public GraphUpdateStage stage {
- get {
- switch (internalStage) {
- case STAGE_CREATED:
- return GraphUpdateStage.Created;
- case STAGE_APPLIED:
- return GraphUpdateStage.Applied;
- case STAGE_ABORTED:
- return GraphUpdateStage.Aborted;
-
- default:
- case STAGE_PENDING:
- return GraphUpdateStage.Pending;
- }
- }
- }
-
-
-
-
-
- public virtual void WillUpdateNode (GraphNode node) {
- if (trackChangedNodes && node != null) {
- if (changedNodes == null) { changedNodes = ListPool<GraphNode>.Claim(); backupData = ListPool<uint>.Claim(); backupPositionData = ListPool<Int3>.Claim(); }
- changedNodes.Add(node);
- backupPositionData.Add(node.position);
- backupData.Add(node.Penalty);
- backupData.Add(node.Flags);
- #if !ASTAR_NO_GRID_GRAPH
- var gridNode = node as GridNode;
- if (gridNode != null) backupData.Add(gridNode.InternalGridFlags);
- #endif
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public virtual void RevertFromBackup () {
- if (trackChangedNodes) {
- if (changedNodes == null) return;
- int counter = 0;
- for (int i = 0; i < changedNodes.Count; i++) {
- changedNodes[i].Penalty = backupData[counter];
- counter++;
-
- var tmp = changedNodes[i].HierarchicalNodeIndex;
- changedNodes[i].Flags = backupData[counter];
- changedNodes[i].HierarchicalNodeIndex = tmp;
- counter++;
- #if !ASTAR_NO_GRID_GRAPH
- var gridNode = changedNodes[i] as GridNode;
- if (gridNode != null) {
- gridNode.InternalGridFlags = (ushort)backupData[counter];
- counter++;
- }
- #endif
- changedNodes[i].position = backupPositionData[i];
- changedNodes[i].SetConnectivityDirty();
- }
- ListPool<GraphNode>.Release(ref changedNodes);
- ListPool<uint>.Release(ref backupData);
- ListPool<Int3>.Release(ref backupPositionData);
- } else {
- throw new System.InvalidOperationException("Changed nodes have not been tracked, cannot revert from backup. Please set trackChangedNodes to true before applying the update.");
- }
- }
-
- public virtual void Apply (GraphNode node) {
- if (shape == null || shape.Contains(node)) {
-
- node.Penalty = (uint)(node.Penalty+addPenalty);
- if (modifyWalkability) {
- node.Walkable = setWalkability;
- }
-
- if (modifyTag) node.Tag = (uint)setTag;
- }
- }
- public GraphUpdateObject () {
- }
-
- public GraphUpdateObject (Bounds b) {
- bounds = b;
- }
- }
-
- public interface ITransformedGraph {
- GraphTransform transform { get; }
- }
-
- public interface IRaycastableGraph {
-
-
-
-
-
-
-
- bool Linecast(Vector3 start, Vector3 end);
-
- [System.Obsolete]
- bool Linecast(Vector3 start, Vector3 end, GraphNode hint);
-
- [System.Obsolete]
- bool Linecast(Vector3 start, Vector3 end, GraphNode hint, out GraphHitInfo hit);
-
- [System.Obsolete]
- bool Linecast(Vector3 start, Vector3 end, GraphNode hint, out GraphHitInfo hit, List<GraphNode> trace);
-
-
-
-
-
-
-
-
-
-
- bool Linecast(Vector3 start, Vector3 end, out GraphHitInfo hit, List<GraphNode> trace = null, System.Func<GraphNode, bool> filter = null);
- }
-
-
-
-
-
-
- [System.Serializable]
- public struct IntRect {
- public int xmin, ymin, xmax, ymax;
- public IntRect (int xmin, int ymin, int xmax, int ymax) {
- this.xmin = xmin;
- this.xmax = xmax;
- this.ymin = ymin;
- this.ymax = ymax;
- }
- public bool Contains (int x, int y) {
- return !(x < xmin || y < ymin || x > xmax || y > ymax);
- }
- public Int2 Min {
- get {
- return new Int2(xmin, ymin);
- }
- }
- public Int2 Max {
- get {
- return new Int2(xmax, ymax);
- }
- }
- public int Width {
- get {
- return xmax-xmin+1;
- }
- }
- public int Height {
- get {
- return ymax-ymin+1;
- }
- }
- public int Area {
- get {
- return Width * Height;
- }
- }
-
-
-
-
-
- public bool IsValid () {
- return xmin <= xmax && ymin <= ymax;
- }
- public static bool operator == (IntRect a, IntRect b) {
- return a.xmin == b.xmin && a.xmax == b.xmax && a.ymin == b.ymin && a.ymax == b.ymax;
- }
- public static bool operator != (IntRect a, IntRect b) {
- return a.xmin != b.xmin || a.xmax != b.xmax || a.ymin != b.ymin || a.ymax != b.ymax;
- }
- public override bool Equals (System.Object obj) {
- var rect = (IntRect)obj;
- return xmin == rect.xmin && xmax == rect.xmax && ymin == rect.ymin && ymax == rect.ymax;
- }
- public override int GetHashCode () {
- return xmin*131071 ^ xmax*3571 ^ ymin*3109 ^ ymax*7;
- }
-
-
-
-
-
-
- public static IntRect Intersection (IntRect a, IntRect b) {
- return new IntRect(
- System.Math.Max(a.xmin, b.xmin),
- System.Math.Max(a.ymin, b.ymin),
- System.Math.Min(a.xmax, b.xmax),
- System.Math.Min(a.ymax, b.ymax)
- );
- }
-
- public static bool Intersects (IntRect a, IntRect b) {
- return !(a.xmin > b.xmax || a.ymin > b.ymax || a.xmax < b.xmin || a.ymax < b.ymin);
- }
-
-
-
-
- public static IntRect Union (IntRect a, IntRect b) {
- return new IntRect(
- System.Math.Min(a.xmin, b.xmin),
- System.Math.Min(a.ymin, b.ymin),
- System.Math.Max(a.xmax, b.xmax),
- System.Math.Max(a.ymax, b.ymax)
- );
- }
-
- public IntRect ExpandToContain (int x, int y) {
- return new IntRect(
- System.Math.Min(xmin, x),
- System.Math.Min(ymin, y),
- System.Math.Max(xmax, x),
- System.Math.Max(ymax, y)
- );
- }
-
-
- public IntRect Expand (int range) {
- return new IntRect(xmin-range,
- ymin-range,
- xmax+range,
- ymax+range
- );
- }
- public override string ToString () {
- return "[x: "+xmin+"..."+xmax+", y: " + ymin +"..."+ymax+"]";
- }
-
- public void DebugDraw (GraphTransform transform, Color color) {
- Vector3 p1 = transform.Transform(new Vector3(xmin, 0, ymin));
- Vector3 p2 = transform.Transform(new Vector3(xmin, 0, ymax));
- Vector3 p3 = transform.Transform(new Vector3(xmax, 0, ymax));
- Vector3 p4 = transform.Transform(new Vector3(xmax, 0, ymin));
- Debug.DrawLine(p1, p2, color);
- Debug.DrawLine(p2, p3, color);
- Debug.DrawLine(p3, p4, color);
- Debug.DrawLine(p4, p1, color);
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- [System.Serializable]
- public struct GraphMask {
-
- public int value;
-
- public static GraphMask everything { get { return new GraphMask(-1); } }
- public GraphMask (int value) {
- this.value = value;
- }
- public static implicit operator int(GraphMask mask) {
- return mask.value;
- }
- public static implicit operator GraphMask (int mask) {
- return new GraphMask(mask);
- }
-
- public static GraphMask operator & (GraphMask lhs, GraphMask rhs) {
- return new GraphMask(lhs.value & rhs.value);
- }
-
- public static GraphMask operator | (GraphMask lhs, GraphMask rhs) {
- return new GraphMask(lhs.value | rhs.value);
- }
-
- public static GraphMask operator ~ (GraphMask lhs) {
- return new GraphMask(~lhs.value);
- }
-
- public bool Contains (int graphIndex) {
- return ((value >> graphIndex) & 1) != 0;
- }
-
- public static GraphMask FromGraph (NavGraph graph) {
- return 1 << (int)graph.graphIndex;
- }
- public override string ToString () {
- return value.ToString();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public static GraphMask FromGraphName (string graphName) {
- var graph = AstarData.active.data.FindGraph(g => g.name == graphName);
- if (graph == null) throw new System.ArgumentException("Could not find any graph with the name '" + graphName + "'");
- return FromGraph(graph);
- }
- }
- #region Delegates
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public delegate void OnPathDelegate(Path p);
- public delegate void OnGraphDelegate(NavGraph graph);
- public delegate void OnScanDelegate(AstarPath script);
-
- public delegate void OnScanStatus(Progress progress);
- #endregion
- #region Enums
- public enum GraphUpdateThreading {
-
-
-
-
-
- UnityThread = 0,
-
- SeparateThread = 1 << 0,
-
- UnityInit = 1 << 1,
-
-
-
-
-
-
- UnityPost = 1 << 2,
-
- SeparateAndUnityInit = SeparateThread | UnityInit
- }
-
- public enum PathLog {
-
- None,
-
- Normal,
-
- Heavy,
-
- InGame,
-
- OnlyErrors
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- public enum Heuristic {
-
- Manhattan,
-
-
-
-
- DiagonalManhattan,
-
- Euclidean,
-
-
-
-
-
-
-
-
- None
- }
-
- public enum GraphDebugMode {
-
- SolidColor,
-
-
-
-
-
- G,
-
-
-
-
-
- H,
-
-
-
-
-
- F,
-
-
-
-
-
-
- Penalty,
-
-
-
-
-
-
-
- Areas,
-
-
-
-
-
- Tags,
-
-
-
-
-
- HierarchicalNode,
- }
-
- public enum ThreadCount {
- AutomaticLowLoad = -1,
- AutomaticHighLoad = -2,
- None = 0,
- One = 1,
- Two,
- Three,
- Four,
- Five,
- Six,
- Seven,
- Eight
- }
-
- public enum PathState {
- Created = 0,
- PathQueue = 1,
- Processing = 2,
- ReturnQueue = 3,
- Returned = 4
- }
-
- public enum PathCompleteState {
-
-
-
-
- NotCalculated = 0,
-
-
-
-
- Error = 1,
-
- Complete = 2,
-
-
-
-
- Partial = 3,
- }
-
- public enum CloseToDestinationMode {
-
- Stop,
-
- ContinueToExactDestination,
- }
-
- public enum Side : byte {
-
- Colinear = 0,
-
- Left = 1,
-
- Right = 2
- }
- public enum InspectorGridHexagonNodeSize {
-
- Width,
-
- Diameter,
-
- NodeSize
- }
- public enum InspectorGridMode {
- Grid,
- IsometricGrid,
- Hexagonal,
- Advanced
- }
-
-
-
-
-
- public enum OrientationMode {
- ZAxisForward,
- YAxisForward,
- }
- #endregion
- }
- namespace Pathfinding.Util {
-
- public class PreserveAttribute : System.Attribute {
- }
- }
|