Skip to content

Commit ff89cc2

Browse files
committed
[Pathfinding][WIP]: Show the last clicked node with a yellow color
Needs more improvements and sh ow line path when generate a PC build
1 parent 331f651 commit ff89cc2

File tree

13 files changed

+657
-357
lines changed

13 files changed

+657
-357
lines changed

Diff for: Assets/Materials/Black.Red.Yellow.Green.mat

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Material:
88
m_PrefabInstance: {fileID: 0}
99
m_PrefabAsset: {fileID: 0}
1010
m_Name: Black.Red.Yellow.Green
11-
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
11+
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
1212
m_ShaderKeywords:
1313
m_LightmapFlags: 4
1414
m_EnableInstancingVariants: 0

Diff for: Assets/Resources/Levels/Maps/arena.txt

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
type octile
2+
height 49
3+
width 49
4+
map
5+
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
6+
TTT............TTTT.TTT...TTTT.TTTT............TT
7+
TT.............TTT........TTT..TTT.............TT
8+
T...............................................T
9+
T...............................................T
10+
T...............................................T
11+
T...............................................T
12+
T.......................TT......................T
13+
T......................TTT......................T
14+
T......................TTT......................T
15+
T...............................................T
16+
T...............................................T
17+
T...............................................T
18+
T...............................................T
19+
T...............................................T
20+
TTT............TTTT............TTTT............TT
21+
TTT............TTTT............TTTT............TT
22+
TTT............TTTT............TTTT............TT
23+
TT.............TTT.............TTT.............TT
24+
TT..............................................T
25+
TT..............................................T
26+
TT..............................................T
27+
TT..............................................T
28+
T...............................................T
29+
T...............................................T
30+
T...............................................T
31+
TT..............................................T
32+
TTT.............................................T
33+
TTT.............................................T
34+
TTT.............................................T
35+
T...............................................T
36+
TTT............TTTT............TTTT............TT
37+
TTT............TTTT............TTTT............TT
38+
TTT............TTTT............TTTT............TT
39+
TT.............TTT.............TTT.............TT
40+
T...............................................T
41+
T...............................................T
42+
T...............................................T
43+
T...............................................T
44+
T...............................................T
45+
T...............................................T
46+
T...............................................T
47+
T...............................................T
48+
T...............................................T
49+
T...............................................T
50+
T...............................................T
51+
T...................TTT...TTT...................T
52+
TTT............TTTT.TTTT..TTTT.TTTT............TT
53+
TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

Diff for: Assets/Resources/Levels/Maps/arena.txt.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Resources/Levels/Maps/combat.txt

+197
Large diffs are not rendered by default.

Diff for: Assets/Resources/Levels/Maps/combat.txt.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Assets/Scenes/GridExample.unity

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ Transform:
272272
m_PrefabAsset: {fileID: 0}
273273
m_GameObject: {fileID: 950689533}
274274
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
275-
m_LocalPosition: {x: 0, y: 0, z: 0}
275+
m_LocalPosition: {x: 0, y: 0, z: -20}
276276
m_LocalScale: {x: 1, y: 1, z: 1}
277277
m_Children: []
278278
m_Father: {fileID: 550321}

Diff for: Assets/Scenes/SampleScene.unity

+7-6
Original file line numberDiff line numberDiff line change
@@ -289,13 +289,13 @@ Transform:
289289
m_PrefabInstance: {fileID: 0}
290290
m_PrefabAsset: {fileID: 0}
291291
m_GameObject: {fileID: 963194225}
292-
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
293-
m_LocalPosition: {x: 0, y: 1, z: -10}
292+
m_LocalRotation: {x: 0.24602868, y: 0.65276533, z: -0.23758711, w: 0.6759584}
293+
m_LocalPosition: {x: -58, y: 50, z: -10}
294294
m_LocalScale: {x: 1, y: 1, z: 1}
295295
m_Children: []
296296
m_Father: {fileID: 0}
297297
m_RootOrder: 0
298-
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
298+
m_LocalEulerAnglesHint: {x: 40, y: 88, z: 0}
299299
--- !u!1 &1919555902
300300
GameObject:
301301
m_ObjectHideFlags: 0
@@ -325,9 +325,10 @@ MonoBehaviour:
325325
m_Script: {fileID: 11500000, guid: a804a9fa87b25b74c993b721f77ab9b3, type: 3}
326326
m_Name:
327327
m_EditorClassIdentifier:
328-
images:
329-
- {fileID: 2800000, guid: 368c965391d2c5049b4f34d0befebf4f, type: 3}
330-
mapsText: []
328+
images: []
329+
mapsText:
330+
- {fileID: 4900000, guid: 054855899fe99f54daea0239986d7550, type: 3}
331+
- {fileID: 4900000, guid: 62ab02be9f6075c418af027157c8f0f7, type: 3}
331332
levelElements:
332333
wall: {fileID: 5774084726847290072, guid: f5bc3a42bee4fea4abfc86b15f7d290f, type: 3}
333334
ground: {fileID: 825213705861597184, guid: e3c199f43a551584486ca185b4773ef0, type: 3}

Diff for: Assets/Scripts/Pathfinding/PathNode.cs

+63-49
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,63 @@
1-
using UnityEngine;
2-
3-
public class PathNode
4-
{
5-
public const int DEFAULT_GCOST = 99999999; //int.MaxValue;
6-
7-
public int gCost = DEFAULT_GCOST;
8-
public int hCost;
9-
public int fCost;
10-
11-
protected bool walkable = true;
12-
13-
public PathNode cameFromNode = null;
14-
public Vector2Int Position { get; set; }
15-
16-
public bool IsWalkable {
17-
18-
get => walkable;
19-
20-
set {
21-
walkable = value;
22-
if (grid != null)
23-
{
24-
grid.TriggerCellChange(Position);
25-
}
26-
}
27-
}
28-
29-
protected GridBase<PathNode> grid;
30-
31-
public PathNode() { }
32-
33-
public PathNode(GridBase<PathNode> grid, int width, int height)
34-
{
35-
this.grid = grid;
36-
Position = new Vector2Int(width, height);
37-
}
38-
39-
public override string ToString()
40-
{
41-
return $"{Position.x},{Position.y}";
42-
}
43-
44-
public int CalculateF()
45-
{
46-
fCost = gCost + hCost;
47-
return fCost;
48-
}
49-
}
1+
using UnityEngine;
2+
3+
public class PathNode
4+
{
5+
public const int DEFAULT_GCOST = 99999999; //int.MaxValue;
6+
7+
public int gCost = DEFAULT_GCOST;
8+
public int hCost;
9+
public int fCost;
10+
11+
protected bool walkable = true;
12+
protected bool last = false;
13+
14+
public PathNode cameFromNode = null;
15+
public Vector2Int Position { get; set; }
16+
public bool IsLast
17+
{
18+
get => last;
19+
20+
set
21+
{
22+
last = value;
23+
if (grid != null)
24+
{
25+
grid.TriggerCellChange(Position);
26+
}
27+
}
28+
}
29+
30+
public bool IsWalkable {
31+
32+
get => walkable;
33+
34+
set {
35+
walkable = value;
36+
if (grid != null)
37+
{
38+
grid.TriggerCellChange(Position);
39+
}
40+
}
41+
}
42+
43+
protected GridBase<PathNode> grid;
44+
45+
public PathNode() { }
46+
47+
public PathNode(GridBase<PathNode> grid, int width, int height)
48+
{
49+
this.grid = grid;
50+
Position = new Vector2Int(width, height);
51+
}
52+
53+
public override string ToString()
54+
{
55+
return $"{Position.x},{Position.y}";
56+
}
57+
58+
public int CalculateF()
59+
{
60+
fCost = gCost + hCost;
61+
return fCost;
62+
}
63+
}

0 commit comments

Comments
 (0)