Elin Decompiled Documentation EA 23.102 Nightly
All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events Pages
PathManager.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Threading;
3using Algorithms;
4using UnityEngine;
5
6public class PathManager : MonoBehaviour
7{
8 public enum MoveType
9 {
10 Default,
11 Combat
12 }
13
14 public static int requestCount;
15
16 public static PathManager Instance;
17
18 public static PathProgress tempProgress = new PathProgress();
19
21
22 public int searchLimit = 1000000;
23
25
26 private void Awake()
27 {
28 Instance = this;
29 }
30
31 public void RequestPath(PathProgress progress)
32 {
34 progress.state = PathProgress.State.Searching;
35 ThreadPool.QueueUserWorkItem(delegate
36 {
37 new PathThread().Start(progress);
38 });
39 }
40
41 public void RequestPathImmediate(PathProgress progress)
42 {
44 pathfinder.FindPath(progress);
45 }
46
47 public bool IsPathClear(Point origin, Point dest, IPathfindWalker walker, int radius)
48 {
49 tempProgress.walker = walker;
50 tempProgress.moveType = MoveType.Default;
51 tempProgress.RequestPathImmediate(origin, dest, 0, _ignoreConnection: false);
52 if (tempProgress.nodes.Count > 0)
53 {
54 return tempProgress.nodes.Count < radius;
55 }
56 return false;
57 }
58
59 public PathProgress RequestPathImmediate(Point origin, Point dest, IPathfindWalker walker, MoveType moveType = MoveType.Default, int searchLimit = -1, int destDist = 0)
60 {
61 tempProgress.walker = walker;
62 tempProgress.moveType = moveType;
63 tempProgress.RequestPathImmediate(origin, dest, destDist, _ignoreConnection: false, searchLimit);
64 return tempProgress;
65 }
66
67 public Point GetFirstStep(Point origin, Point _dest, IPathfindWalker walker, int maxDist = 20, MoveType moveType = MoveType.Default)
68 {
69 Point dest = _dest.Copy();
70 Point point = _GetFirstStep(origin, dest, walker, maxDist, moveType);
71 if (point.IsValid)
72 {
73 return point;
74 }
75 return Point.Invalid;
76 }
77
78 public Point _GetFirstStep(Point origin, Point dest, IPathfindWalker walker, int maxDist = 20, MoveType moveType = MoveType.Default)
79 {
80 if (!dest.IsValid || (dest.cell.blocked && origin.Distance(dest) <= 1))
81 {
82 return Point.Invalid;
83 }
84 tempProgress.walker = walker;
85 tempProgress.moveType = moveType;
86 tempProgress.RequestPathImmediate(origin, dest, (moveType == MoveType.Combat) ? 1 : 0, _ignoreConnection: false, maxDist);
88 {
89 return Point.Invalid;
90 }
91 List<PathFinderNode> nodes = tempProgress.nodes;
92 if (nodes.Count > 0)
93 {
94 PathFinderNode pathFinderNode = nodes[nodes.Count - 1];
95 if (pathFinderNode.X == origin.x && pathFinderNode.Z == origin.z && nodes.Count > 1)
96 {
97 pathFinderNode = nodes[nodes.Count - 2];
98 }
99 if (Mathf.Abs(pathFinderNode.X - origin.x) > 1 || Mathf.Abs(pathFinderNode.Z - origin.z) > 1)
100 {
101 return Point.Invalid;
102 }
103 Point point = new Point(pathFinderNode.X, pathFinderNode.Z);
104 if (point.x == origin.x && point.z == origin.z)
105 {
106 return Point.Invalid;
107 }
108 return point;
109 }
110 return Point.Invalid;
111 }
112
113 public void OnGridModified()
114 {
115 }
116}
void RequestPathImmediate(PathProgress progress)
Definition: PathManager.cs:41
void Awake()
Definition: PathManager.cs:26
IPathfinder pathfinder
Definition: PathManager.cs:24
Point GetFirstStep(Point origin, Point _dest, IPathfindWalker walker, int maxDist=20, MoveType moveType=MoveType.Default)
Definition: PathManager.cs:67
PathFinder _pathfinder
Definition: PathManager.cs:20
void OnGridModified()
Definition: PathManager.cs:113
void RequestPath(PathProgress progress)
Definition: PathManager.cs:31
Point _GetFirstStep(Point origin, Point dest, IPathfindWalker walker, int maxDist=20, MoveType moveType=MoveType.Default)
Definition: PathManager.cs:78
PathProgress RequestPathImmediate(Point origin, Point dest, IPathfindWalker walker, MoveType moveType=MoveType.Default, int searchLimit=-1, int destDist=0)
Definition: PathManager.cs:59
int searchLimit
Definition: PathManager.cs:22
static PathManager Instance
Definition: PathManager.cs:16
static int requestCount
Definition: PathManager.cs:14
bool IsPathClear(Point origin, Point dest, IPathfindWalker walker, int radius)
Definition: PathManager.cs:47
static PathProgress tempProgress
Definition: PathManager.cs:18
List< PathFinderNode > nodes
Definition: PathProgress.cs:16
void RequestPathImmediate(Point _startPoint, Point _destPoint, int _destDist, bool _ignoreConnection, int _searchLimit=-1)
Definition: PathProgress.cs:61
void Start(PathProgress progress)
Definition: PathThread.cs:3
Definition: Point.cs:9
static Point Invalid
Definition: Point.cs:28
Point Copy()
Definition: Point.cs:467
int x
Definition: Point.cs:36
int z
Definition: Point.cs:39
bool IsValid
Definition: Point.cs:88
int Distance(Point p)
Definition: Point.cs:953
Cell cell
Definition: Point.cs:51
void FindPath(PathProgress progress)