@ -0,0 +1,8 @@ |
|||
fileFormatVersion: 2 |
|||
guid: f8d0d8ed565d460408795fae027d33cf |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,103 @@ |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class AStarManager : Singleton<AStarManager> |
|||
{ |
|||
//开启列表
|
|||
public List<MapUnity> openList = new List<MapUnity>(); |
|||
//关闭列表
|
|||
public List<MapUnity> closeList = new List<MapUnity>(); |
|||
|
|||
//返回路径
|
|||
public List <MapUnity> FindPath(MapUnity starNode ,MapUnity endNode) |
|||
{ |
|||
//判断传入的点是否合法
|
|||
//1.在地图范围内 2.不是阻挡,不合法返回null不能寻路
|
|||
|
|||
//得到起点和终点对应的格子
|
|||
|
|||
//清空上一次列表数据
|
|||
closeList.Clear(); |
|||
openList .Clear (); |
|||
|
|||
//把起点放到关闭列表中
|
|||
starNode.aStarNode.fatherNode = null; |
|||
starNode.aStarNode.f = 0; |
|||
starNode.aStarNode.g = 0; |
|||
starNode.aStarNode.h = 0; |
|||
closeList.Add(starNode); |
|||
|
|||
while (true ) |
|||
{ |
|||
//从起点开始找周围的点放入开启列表中
|
|||
//判断这些点是否是边界是否是阻挡,是否在开启列表或者关闭列表中,都不是才能放入
|
|||
FindNodeToOpenList(starNode, endNode); |
|||
|
|||
//选出开启列表中寻路消耗最小的点
|
|||
openList.Sort(SortOpenList); |
|||
|
|||
//死路判断
|
|||
if(openList.Count ==0) |
|||
{ |
|||
Debug.Log("无法找到路径"); |
|||
return null; |
|||
} |
|||
|
|||
//放入关闭列表中,再从开启列表中移除
|
|||
closeList.Add(openList[0]); |
|||
starNode = openList[0]; |
|||
openList.RemoveAt(0); |
|||
|
|||
//如果已经是终点,返回路径
|
|||
//如果不是结果,继续寻路
|
|||
if(starNode == endNode ) |
|||
{ |
|||
//找到路径,回溯路径
|
|||
List<MapUnity> path = new List<MapUnity>(); |
|||
path.Add(endNode); |
|||
while (endNode .aStarNode .fatherNode !=null ) |
|||
{ |
|||
path.Add(endNode.aStarNode.fatherNode); |
|||
endNode = endNode.aStarNode.fatherNode; |
|||
} |
|||
//列表反置
|
|||
path.Reverse(); |
|||
return path; |
|||
} |
|||
} |
|||
} |
|||
private int SortOpenList(MapUnity a,MapUnity b) |
|||
{ |
|||
if (a.aStarNode.f > b.aStarNode.f) |
|||
return 1; |
|||
else |
|||
return -1; |
|||
} |
|||
|
|||
public void FindNodeToOpenList(MapUnity currentNode,MapUnity endNode) |
|||
{ |
|||
for(int i=0;i<currentNode .unitPool .Count;i++) |
|||
{ |
|||
if(currentNode .unitPool [i] ==null ||currentNode.unitPool[i].blocked ==true ||currentNode.unitPool[i].enemyNode != null ) |
|||
{ |
|||
//不加入起点
|
|||
} |
|||
else if(openList .Contains (currentNode.unitPool[i]) ||closeList .Contains (currentNode.unitPool[i])) |
|||
{ |
|||
//不加入起点
|
|||
} |
|||
else |
|||
{ |
|||
//记录父对象
|
|||
currentNode.unitPool[i].aStarNode.fatherNode = currentNode; |
|||
//计算g.累计父对象的g
|
|||
currentNode.unitPool[i].aStarNode.g = currentNode.unitPool[i].aStarNode.fatherNode.aStarNode.g + 1; |
|||
currentNode.unitPool[i].aStarNode.h = Mathf.Abs(endNode.locationX - currentNode.unitPool[i].locationX) + Mathf.Abs(endNode.locationY - currentNode.unitPool[i].locationY); |
|||
currentNode.unitPool[i].aStarNode.f = currentNode.unitPool[i].aStarNode.g + currentNode.unitPool[i].aStarNode.h; |
|||
|
|||
openList.Add(currentNode.unitPool[i]); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 169f62e95b6bd104bb1f3670b6679bdc |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,34 @@ |
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
public class AStarNode :MonoBehaviour |
|||
{ |
|||
//坐标
|
|||
public int positionX, positionY; |
|||
|
|||
//寻路消耗 f=g+h
|
|||
public float f; |
|||
//离起点的距离
|
|||
public float g; |
|||
//离终点的距离
|
|||
public float h; |
|||
//父对象
|
|||
public MapUnity fatherNode; |
|||
|
|||
//格子类型-能不能走
|
|||
public enum E_Node_Type |
|||
{ |
|||
walk, |
|||
block |
|||
} |
|||
public E_Node_Type type; |
|||
|
|||
//构造函数
|
|||
public AStarNode (int x,int y,E_Node_Type type ) |
|||
{ |
|||
this.positionX = x; |
|||
this.positionY = y; |
|||
this.type = type; |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 9e31d7fef6d6d38408c4f6559b1df330 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,8 @@ |
|||
fileFormatVersion: 2 |
|||
guid: a520b80f7ced2bd48b84fcd0426fe7e6 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
@ -0,0 +1,11 @@ |
|||
|
|||
public interface IEnemyObserver |
|||
{ |
|||
void GetEnemyPosition(); |
|||
|
|||
void EnemyMove(); |
|||
|
|||
void EnemyColour(); |
|||
|
|||
} |
|||
|
|||
@ -0,0 +1,11 @@ |
|||
fileFormatVersion: 2 |
|||
guid: 8332bbbe0e51bb544b2fe2e9571e3bb5 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|||
|
Before Width: | Height: | Size: 36 KiB |
|
Before Width: | Height: | Size: 12 KiB |
|
Before Width: | Height: | Size: 60 KiB |
|
Before Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 958 B |
|
Before Width: | Height: | Size: 48 KiB |
|
Before Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 43 KiB |
|
Before Width: | Height: | Size: 9.5 KiB |
|
Before Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 68 KiB |
|
Before Width: | Height: | Size: 44 KiB |
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||
@ -1 +1 @@ |
|||
D:\GitInventory\test_45\ColorlessWorld-2024-4-2 |
|||
D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2 |
|||
@ -1 +1 @@ |
|||
/pathmap:"D:\GitInventory\test_45\ColorlessWorld-2024-4-2"=. |
|||
/pathmap:"D:\GitInventory_2024-5-28\test_45\ColorlessWorld-2024-4-2"=. |
|||