1161 lines
35 KiB
C#
1161 lines
35 KiB
C#
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
/// <summary>
|
|
/// 模拟摄像头路径规划:通过摄像头拍到的节点推断行走轨迹,避开未被拍到的不可达节点。
|
|
/// 同时使用 LineRenderer 连线路径。
|
|
/// </summary>
|
|
public class LineManger : MonoBehaviour
|
|
{
|
|
private MapGraph _map;
|
|
public LineRenderer lineRenderer; // 路径连线渲染器
|
|
public Transform CameraTransParent;
|
|
public Transform PointParent;
|
|
private readonly List<Transform> _trajectory=new List<Transform>();
|
|
private readonly List<Transform> _cameraTransList=new List<Transform>();
|
|
private Dictionary<int, string> _cameraMappingDic = new Dictionary<int, string>();
|
|
private List<string> _carMustPassNodes = new List<string>();
|
|
private List<string> _personMustAvoidNodes = new List<string>();
|
|
public List<int> _passedCarForbiddenNodesList = new List<int>();
|
|
public List<int> _passedPersonForbiddenNodesList = new List<int>();
|
|
private readonly List<int> _carMustList = new List<int>();
|
|
private readonly List<int> _personMustList = new List<int>();
|
|
private readonly Dictionary<int,List<List<int>>>_levelDict=new Dictionary<int,List<List<int>>>();
|
|
List<SpriteRenderer> _cameraSpriteRendererList = new List<SpriteRenderer>();
|
|
|
|
public Color NormalGreenColor;
|
|
public Color HighlightedGreenColor;
|
|
|
|
private Transform mover;
|
|
public Transform orgin;
|
|
|
|
public static LineManger Instance;
|
|
private void Awake()
|
|
{
|
|
Instance = this;
|
|
Init();
|
|
}
|
|
|
|
private int GetLevelById(int id)
|
|
{
|
|
if (id > _cameraMappingDic.Count)
|
|
{
|
|
Debug.Log($"id:{id} cameraId:{_cameraMappingDic.Count}");
|
|
return -1;
|
|
}
|
|
|
|
foreach (var item in _levelDict)
|
|
{
|
|
var levelId = item.Key;
|
|
for (int i = 0; i < item.Value.Count; i++)
|
|
{
|
|
for (int j = 0; j < item.Value[i].Count; j++)
|
|
{
|
|
if (item.Value[i][j] == id)
|
|
{
|
|
return levelId;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
public int GetLevelById(int id,out Transform areaCenter,out Transform cameraTrans)
|
|
{
|
|
areaCenter=null;
|
|
cameraTrans=null;
|
|
cameraTrans = GetCameraTransformById(id);
|
|
var level=GetLevelById(id);
|
|
Debug.Log($"GetLevelById:{id} level:{level}");
|
|
switch (level)
|
|
{
|
|
case 1:
|
|
areaCenter = GetTransformById(id);
|
|
break;
|
|
case 2:
|
|
areaCenter = GetTransformById(id);
|
|
break;
|
|
case 3:
|
|
areaCenter = GetAreaCenterById(level,id);
|
|
break;
|
|
case 4:
|
|
areaCenter = GetAreaCenterById(level,id);
|
|
break;
|
|
|
|
}
|
|
return level;
|
|
}
|
|
|
|
|
|
private Transform GetTransformById(int id)
|
|
{
|
|
if(id>_cameraMappingDic.Count)return null;
|
|
var trans = GetTransformByName(_cameraMappingDic[id]);
|
|
return trans;
|
|
}
|
|
|
|
private Transform GetAreaCenterById(int level,int id)
|
|
{
|
|
var areaCenterID = -1;
|
|
var levelListIndex = -1;
|
|
switch (level)
|
|
{
|
|
case 3:
|
|
List<List<int>>level3List = _levelDict[level];
|
|
for (int i = 0; i < level3List.Count; i++)
|
|
{
|
|
for (int j = 0; j < level3List[i].Count; j++)
|
|
{
|
|
if (id == level3List[i][j])
|
|
{
|
|
levelListIndex = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (levelListIndex == -1)
|
|
{
|
|
Debug.LogError("There is no corresponding area center");
|
|
}
|
|
|
|
switch (levelListIndex)
|
|
{
|
|
case 0:
|
|
areaCenterID= 34;
|
|
break;
|
|
case 1:
|
|
areaCenterID = 13;
|
|
break;
|
|
}
|
|
|
|
break;
|
|
case 4:
|
|
List<List<int>>level4List = _levelDict[level];
|
|
for (int i = 0; i < level4List.Count; i++)
|
|
{
|
|
for (int j = 0; j < level4List[i].Count; j++)
|
|
{
|
|
if (id == level4List[i][j])
|
|
{
|
|
levelListIndex = i;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (levelListIndex == -1)
|
|
{
|
|
Debug.LogError("There is no corresponding area center");
|
|
}
|
|
|
|
switch (levelListIndex)
|
|
{
|
|
case 0:
|
|
areaCenterID= 8;
|
|
break;
|
|
case 1:
|
|
areaCenterID = 17;
|
|
break;
|
|
}
|
|
break;
|
|
}
|
|
var trans = GetTransformByName(_cameraMappingDic[areaCenterID]);
|
|
return trans;
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
EventManager.RefreshCarPathNodeEvent+= RefreshCarPathNodeEvent;
|
|
EventManager.RefreshPersonPathNodeEvent+= RefreshPersonPathNodeEvent;
|
|
|
|
EventManager.RefreshPersonPathEvent += RefreshPersonPathEvent;
|
|
EventManager.RefreshCarPathEvent += RefreshCarPathEvent;
|
|
EventManager.ResetNodeDetailEvent += ResetNodeDetailEvent;
|
|
|
|
lineRenderer.startWidth = 0.2f;
|
|
lineRenderer.endWidth = 0.2f;
|
|
GetCameraPoints();
|
|
GetMapPoints();
|
|
CreateMap();
|
|
ResetAllSpriteRenderColor();
|
|
mover = new GameObject().transform;
|
|
}
|
|
|
|
private void GetCameraPoints()
|
|
{
|
|
for (int i = 0; i < CameraTransParent.childCount; i++)
|
|
{
|
|
_cameraTransList.Add(CameraTransParent.GetChild(i)) ;
|
|
}
|
|
}
|
|
|
|
private void ResetNodeDetailEvent()
|
|
{
|
|
lineRenderer.positionCount = 0;
|
|
}
|
|
|
|
|
|
private void RefreshPersonPathEvent()
|
|
{
|
|
if(_personMustList.Count==0)return;
|
|
CreatePathWithMustPoints(_personMustList,new List<int>(),out _passedPersonForbiddenNodesList);
|
|
SetLineSpriteRender();
|
|
}
|
|
|
|
private void RefreshCarPathEvent()
|
|
{
|
|
if(_carMustList.Count==0)return;
|
|
CreatePathWithMustPoints(_carMustList,new List<int>(),out _passedCarForbiddenNodesList);
|
|
SetLineSpriteRender();
|
|
}
|
|
|
|
private void RefreshCarPathNodeEvent(List<ILoopData> pathNodeList)
|
|
{
|
|
_carMustList.Clear();
|
|
for (int i = 0; i < pathNodeList.Count; i++)
|
|
{
|
|
var pathNode= pathNodeList[i] as VehiclesResultsItem;
|
|
if (pathNode != null)
|
|
{
|
|
var cameraID = pathNode.camera_id;
|
|
if (!_carMustList.Contains(cameraID))
|
|
{
|
|
_carMustList.Add(cameraID);
|
|
}
|
|
}
|
|
}
|
|
|
|
var cameraTransList= new List<Transform>();
|
|
_cameraSpriteRendererList = new List<SpriteRenderer>();
|
|
foreach (var cameraID in _carMustList)
|
|
{
|
|
if (_cameraMappingDic.TryGetValue(cameraID, out string cameraName))
|
|
{
|
|
var cameraTrans = GetTransformByName(cameraName);
|
|
if (cameraTrans != null)
|
|
{
|
|
cameraTransList.Add(cameraTrans);
|
|
}
|
|
}
|
|
|
|
var spriteRender=GetSpriteRendererByName(cameraID.ToString());
|
|
Debug.Log($"sriteRenderer:{cameraID} {spriteRender.name}");
|
|
_cameraSpriteRendererList.Add(spriteRender);
|
|
|
|
}
|
|
EventManager.TriggerRefreshCarCameraNodesEvent(cameraTransList);
|
|
}
|
|
|
|
private void SetLineSpriteRender()
|
|
{
|
|
for (int i = 0; i < _cameraSpriteRendererList.Count; i++)
|
|
{
|
|
SetSpriteRenderColor(_cameraSpriteRendererList[i]);
|
|
}
|
|
}
|
|
|
|
private SpriteRenderer GetSpriteRendererByName(string name)
|
|
{
|
|
for (int i = 0; i < _cameraTransList.Count; i++)
|
|
{
|
|
if (_cameraTransList[i].name == name)
|
|
{
|
|
return _cameraTransList[i].GetComponent<SpriteRenderer>();
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private void RefreshPersonPathNodeEvent(List<ILoopData> pathNodeList)
|
|
{
|
|
_personMustList.Clear();
|
|
for (int i = 0; i < pathNodeList.Count; i++)
|
|
{
|
|
var pathNode= pathNodeList[i] as PersonResultsItem;
|
|
if (pathNode != null)
|
|
{
|
|
var cameraID = pathNode.camera_id;
|
|
if (!_personMustList.Contains(cameraID))
|
|
{
|
|
_personMustList.Add(cameraID);
|
|
}
|
|
}
|
|
}
|
|
var cameraTransList= new List<Transform>();
|
|
foreach (var cameraID in _personMustList)
|
|
{
|
|
if (_cameraMappingDic.TryGetValue(cameraID, out string cameraName))
|
|
{
|
|
var cameraTrans = GetTransformByName(cameraName);
|
|
if (cameraTrans != null)
|
|
{
|
|
cameraTransList.Add(cameraTrans);
|
|
}
|
|
}
|
|
var spriteRender=GetSpriteRendererByName(cameraID.ToString());
|
|
SetSpriteRenderColor(spriteRender);
|
|
Debug.Log($"sriteRenderer:{cameraID} {spriteRender.name}");
|
|
}
|
|
|
|
|
|
|
|
EventManager.TriggerRefreshPersonCameraNodesEvent(cameraTransList);
|
|
|
|
}
|
|
|
|
|
|
public void CreatePathWithMustPoints(List<int> mustPassIDs, List<int> mustAvoidIDs, out List<int> cameraList)
|
|
{
|
|
List<string> mustPassNodes = new List<string>();
|
|
List<string> mustAvoidNodes = new List<string>();
|
|
for (int i = 0; i < mustPassIDs.Count; i++)
|
|
{
|
|
mustPassNodes.Add(_cameraMappingDic[mustPassIDs[i]]);
|
|
}
|
|
for (int i = 0; i < mustAvoidIDs.Count; i++)
|
|
{
|
|
mustAvoidNodes.Add(_cameraMappingDic[mustAvoidIDs[i]]);
|
|
}
|
|
CreatePathWithMustPoints(mustPassNodes, mustAvoidNodes,out cameraList);
|
|
}
|
|
|
|
|
|
private void CreatePathWithMustPoints(List<string> mustPassIDs, List<string> mustAvoidIDs,out List<int>cameraList)
|
|
{
|
|
cameraList = new List<int>();
|
|
lineRenderer.positionCount = 0;
|
|
List<MapGraph.Node> mustPassNodes = new List<MapGraph.Node>();
|
|
List<MapGraph.Node> mustAvoidNodes = new List<MapGraph.Node>();
|
|
|
|
foreach (var id in mustPassIDs)
|
|
{
|
|
var node = _map.GetNode(id);
|
|
if (node != null) mustPassNodes.Add(node);
|
|
}
|
|
|
|
foreach (var id in mustAvoidIDs)
|
|
{
|
|
var node = _map.GetNode(id);
|
|
if (node != null) mustAvoidNodes.Add(node);
|
|
}
|
|
List<MapGraph.Node> forbiddenPassed;
|
|
var path = PathFinder.FindPathThroughNodes(mustPassNodes, mustAvoidNodes, out forbiddenPassed);
|
|
if (path == null) return;
|
|
|
|
foreach (var item in _cameraMappingDic)
|
|
{
|
|
for (int i = 0; i < forbiddenPassed.Count; i++)
|
|
{
|
|
if (item.Value == forbiddenPassed[i].id)
|
|
{
|
|
cameraList.Add(item.Key);
|
|
}
|
|
}
|
|
}
|
|
if (path != null)
|
|
{
|
|
Debug.Log($"成功生成路径,总点数: {path.Count}");
|
|
if (forbiddenPassed.Count > 0)
|
|
{
|
|
Debug.LogWarning($"注意:路径中经过了以下不可达节点:{string.Join(", ", forbiddenPassed.ConvertAll(n => n.id))}");
|
|
}
|
|
|
|
// 画线
|
|
List<Vector3> positions = new List<Vector3>();
|
|
foreach (var node in path)
|
|
{
|
|
positions.Add(node.position);
|
|
}
|
|
|
|
PathLineAnimator.Play(this, orgin,mover, lineRenderer, positions, moveSpeed: 3f);
|
|
// lineRenderer.positionCount = positions.Count;
|
|
// lineRenderer.SetPositions(positions.ToArray());
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("路径生成失败");
|
|
}
|
|
}
|
|
|
|
private void GetMapPoints()
|
|
{
|
|
for (int i = 0; i < PointParent.childCount; i++)
|
|
{
|
|
_trajectory.Add(PointParent.GetChild(i)) ;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 创建带有可达/不可达状态的地图图结构
|
|
/// </summary>
|
|
void CreateMap()
|
|
{
|
|
_map = new MapGraph();
|
|
#region 将节点加入map中
|
|
_map.AddNode("AA", GetTransformByName("AA").position);
|
|
_map.AddNode("AB", GetTransformByName("AB").position);
|
|
_map.AddNode("AC", GetTransformByName("AC").position);
|
|
_map.AddNode("AD", GetTransformByName("AD").position);
|
|
_map.AddNode("AE", GetTransformByName("AE").position);
|
|
_map.AddNode("AF", GetTransformByName("AF").position);
|
|
_map.AddNode("AG", GetTransformByName("AG").position);
|
|
_map.AddNode("AH", GetTransformByName("AH").position);
|
|
_map.AddNode("AI", GetTransformByName("AI").position);
|
|
_map.AddNode("AJ", GetTransformByName("AJ").position);
|
|
_map.AddNode("AK", GetTransformByName("AK").position);
|
|
_map.AddNode("AL", GetTransformByName("AL").position);
|
|
_map.AddNode("AM", GetTransformByName("AM").position);
|
|
_map.AddNode("AN", GetTransformByName("AN").position);
|
|
_map.AddNode("AO", GetTransformByName("AO").position);
|
|
_map.AddNode("AP", GetTransformByName("AP").position);
|
|
_map.AddNode("AQ", GetTransformByName("AQ").position);
|
|
_map.AddNode("AR", GetTransformByName("AR").position);
|
|
_map.AddNode("AS", GetTransformByName("AS").position);
|
|
_map.AddNode("AT", GetTransformByName("AT").position);
|
|
_map.AddNode("AU", GetTransformByName("AU").position);
|
|
_map.AddNode("AV", GetTransformByName("AV").position);
|
|
_map.AddNode("AW", GetTransformByName("AW").position);
|
|
_map.AddNode("AX", GetTransformByName("AX").position);
|
|
_map.AddNode("AY", GetTransformByName("AY").position);
|
|
_map.AddNode("AZ", GetTransformByName("AZ").position);
|
|
_map.AddNode("BB", GetTransformByName("BB").position);
|
|
_map.AddNode("BC", GetTransformByName("BC").position);
|
|
_map.AddNode("BD", GetTransformByName("BD").position);
|
|
_map.AddNode("BE", GetTransformByName("BE").position);
|
|
_map.AddNode("BF", GetTransformByName("BF").position);
|
|
_map.AddNode("BG", GetTransformByName("BG").position);
|
|
_map.AddNode("BH", GetTransformByName("BH").position);
|
|
_map.AddNode("BI", GetTransformByName("BI").position);
|
|
_map.AddNode("BJ", GetTransformByName("BJ").position);
|
|
_map.AddNode("BK", GetTransformByName("BK").position);
|
|
_map.AddNode("BL", GetTransformByName("BL").position);
|
|
_map.AddNode("BM", GetTransformByName("BM").position);
|
|
_map.AddNode("BN", GetTransformByName("BN").position);
|
|
_map.AddNode("BO", GetTransformByName("BO").position);
|
|
_map.AddNode("BP", GetTransformByName("BP").position);
|
|
_map.AddNode("BQ", GetTransformByName("BQ").position);
|
|
_map.AddNode("BR", GetTransformByName("BR").position);
|
|
_map.AddNode("BS", GetTransformByName("BS").position);
|
|
_map.AddNode("BT", GetTransformByName("BT").position);
|
|
_map.AddNode("BU", GetTransformByName("BU").position);
|
|
_map.AddNode("BV", GetTransformByName("BV").position);
|
|
_map.AddNode("BW", GetTransformByName("BW").position);
|
|
_map.AddNode("BX", GetTransformByName("BX").position);
|
|
_map.AddNode("BY", GetTransformByName("BY").position);
|
|
_map.AddNode("BZ", GetTransformByName("BZ").position);
|
|
_map.AddNode("CC", GetTransformByName("CC").position);
|
|
_map.AddNode("CD", GetTransformByName("CD").position);
|
|
_map.AddNode("CE", GetTransformByName("CE").position);
|
|
_map.AddNode("CF", GetTransformByName("CF").position);
|
|
_map.AddNode("CG", GetTransformByName("CG").position);
|
|
_map.AddNode("CH", GetTransformByName("CH").position);
|
|
_map.AddNode("CI", GetTransformByName("CI").position);
|
|
_map.AddNode("CJ", GetTransformByName("CJ").position);
|
|
_map.AddNode("CK", GetTransformByName("CK").position);
|
|
_map.AddNode("CL", GetTransformByName("CL").position);
|
|
_map.AddNode("CM", GetTransformByName("CM").position);
|
|
_map.AddNode("CN", GetTransformByName("CN").position);
|
|
_map.AddNode("CO", GetTransformByName("CO").position);
|
|
_map.AddNode("CP", GetTransformByName("CP").position);
|
|
_map.AddNode("CQ", GetTransformByName("CQ").position);
|
|
_map.AddNode("CR", GetTransformByName("CR").position);
|
|
_map.AddNode("CS", GetTransformByName("CS").position);
|
|
_map.AddNode("CT", GetTransformByName("CT").position);
|
|
_map.AddNode("CU", GetTransformByName("CU").position);
|
|
_map.AddNode("CV", GetTransformByName("CV").position);
|
|
_map.AddNode("CW", GetTransformByName("CW").position);
|
|
_map.AddNode("CX", GetTransformByName("CX").position);
|
|
_map.AddNode("CY", GetTransformByName("CY").position);
|
|
_map.AddNode("CZ", GetTransformByName("CZ").position);
|
|
_map.AddNode("DD", GetTransformByName("DD").position);
|
|
_map.AddNode("DE", GetTransformByName("DE").position);
|
|
_map.AddNode("DF", GetTransformByName("DF").position);
|
|
_map.AddNode("DG", GetTransformByName("DG").position);
|
|
_map.AddNode("DH", GetTransformByName("DH").position);
|
|
_map.AddNode("DI", GetTransformByName("DI").position);
|
|
_map.AddNode("DJ", GetTransformByName("DJ").position);
|
|
_map.AddNode("DK", GetTransformByName("DK").position);
|
|
_map.AddNode("DL", GetTransformByName("DL").position);
|
|
_map.AddNode("DM", GetTransformByName("DM").position);
|
|
_map.AddNode("DN", GetTransformByName("DN").position);
|
|
_map.AddNode("DO", GetTransformByName("DO").position);
|
|
_map.AddNode("DP", GetTransformByName("DP").position);
|
|
_map.AddNode("DQ", GetTransformByName("DQ").position);
|
|
_map.AddNode("DR", GetTransformByName("DR").position);
|
|
_map.AddNode("DS", GetTransformByName("DS").position);
|
|
_map.AddNode("DT", GetTransformByName("DT").position);
|
|
_map.AddNode("DU", GetTransformByName("DU").position);
|
|
_map.AddNode("DV", GetTransformByName("DV").position);
|
|
_map.AddNode("DW", GetTransformByName("DW").position);
|
|
_map.AddNode("DX", GetTransformByName("DX").position);
|
|
_map.AddNode("DY", GetTransformByName("DY").position);
|
|
_map.AddNode("DZ", GetTransformByName("DZ").position);
|
|
_map.AddNode("EE", GetTransformByName("EE").position);
|
|
_map.AddNode("EF", GetTransformByName("EF").position);
|
|
_map.AddNode("EG", GetTransformByName("EG").position);
|
|
_map.AddNode("EH", GetTransformByName("EH").position);
|
|
_map.AddNode("EI", GetTransformByName("EI").position);
|
|
_map.AddNode("EJ", GetTransformByName("EJ").position);
|
|
_map.AddNode("EK", GetTransformByName("EK").position);
|
|
_map.AddNode("EL", GetTransformByName("EL").position);
|
|
_map.AddNode("EM", GetTransformByName("EM").position);
|
|
_map.AddNode("EN", GetTransformByName("EN").position);
|
|
_map.AddNode("EO", GetTransformByName("EO").position);
|
|
_map.AddNode("EP", GetTransformByName("EP").position);
|
|
_map.AddNode("EQ", GetTransformByName("EQ").position);
|
|
_map.AddNode("ER", GetTransformByName("ER").position);
|
|
_map.AddNode("ES", GetTransformByName("ES").position);
|
|
_map.AddNode("ET", GetTransformByName("ET").position);
|
|
_map.AddNode("EU", GetTransformByName("EU").position);
|
|
_map.AddNode("EV", GetTransformByName("EV").position);
|
|
_map.AddNode("EW", GetTransformByName("EW").position);
|
|
_map.AddNode("EX", GetTransformByName("EX").position);
|
|
_map.AddNode("EY", GetTransformByName("EY").position);
|
|
_map.AddNode("EZ", GetTransformByName("EZ").position);
|
|
_map.AddNode("FF", GetTransformByName("FF").position);
|
|
_map.AddNode("FG", GetTransformByName("FG").position);
|
|
_map.AddNode("FH", GetTransformByName("FH").position);
|
|
_map.AddNode("FI", GetTransformByName("FI").position);
|
|
_map.AddNode("FK", GetTransformByName("FK").position);
|
|
_map.AddNode("FL", GetTransformByName("FL").position);
|
|
_map.AddNode("FM", GetTransformByName("FM").position);
|
|
_map.AddNode("FN", GetTransformByName("FN").position);
|
|
_map.AddNode("FO", GetTransformByName("FO").position);
|
|
_map.AddNode("FP", GetTransformByName("FP").position);
|
|
_map.AddNode("FQ", GetTransformByName("FQ").position);
|
|
_map.AddNode("FR", GetTransformByName("FR").position);
|
|
_map.AddNode("FS", GetTransformByName("FS").position);
|
|
_map.AddNode("FT", GetTransformByName("FT").position);
|
|
_map.AddNode("FU", GetTransformByName("FU").position);
|
|
_map.AddNode("FV", GetTransformByName("FV").position);
|
|
_map.AddNode("FW", GetTransformByName("FW").position);
|
|
_map.AddNode("FX", GetTransformByName("FX").position);
|
|
_map.AddNode("FY", GetTransformByName("FY").position);
|
|
_map.AddNode("FZ", GetTransformByName("FZ").position);
|
|
_map.AddNode("GG", GetTransformByName("GG").position);
|
|
_map.AddNode("GH", GetTransformByName("GH").position);
|
|
_map.AddNode("GI", GetTransformByName("GI").position);
|
|
_map.AddNode("GJ", GetTransformByName("GJ").position);
|
|
_map.AddNode("GK", GetTransformByName("GK").position);
|
|
_map.AddNode("GL", GetTransformByName("GL").position);
|
|
_map.AddNode("GM", GetTransformByName("GM").position);
|
|
_map.AddNode("GN", GetTransformByName("GN").position);
|
|
_map.AddNode("GO", GetTransformByName("GO").position);
|
|
_map.AddNode("GP", GetTransformByName("GP").position);
|
|
_map.AddNode("GQ", GetTransformByName("GQ").position);
|
|
_map.AddNode("GR", GetTransformByName("GR").position);
|
|
_map.AddNode("GS", GetTransformByName("GS").position);
|
|
_map.AddNode("GT", GetTransformByName("GT").position);
|
|
_map.AddNode("GU", GetTransformByName("GU").position);
|
|
_map.AddNode("GV", GetTransformByName("GV").position);
|
|
_map.AddNode("GW", GetTransformByName("GW").position);
|
|
_map.AddNode("GX", GetTransformByName("GX").position);
|
|
_map.AddNode("GY", GetTransformByName("GY").position);
|
|
_map.AddNode("GZ", GetTransformByName("GZ").position);
|
|
_map.AddNode("HH", GetTransformByName("HH").position);
|
|
_map.AddNode("HI", GetTransformByName("HI").position);
|
|
_map.AddNode("HJ", GetTransformByName("HJ").position);
|
|
_map.AddNode("HK", GetTransformByName("HK").position);
|
|
_map.AddNode("HL", GetTransformByName("HL").position);
|
|
_map.AddNode("HM", GetTransformByName("HM").position);
|
|
_map.AddNode("HN", GetTransformByName("HN").position);
|
|
_map.AddNode("HO", GetTransformByName("HO").position);
|
|
_map.AddNode("HP", GetTransformByName("HP").position);
|
|
_map.AddNode("HQ", GetTransformByName("HQ").position);
|
|
_map.AddNode("HR", GetTransformByName("HR").position);
|
|
_map.AddNode("HS", GetTransformByName("HS").position);
|
|
_map.AddNode("HT", GetTransformByName("HT").position);
|
|
_map.AddNode("HU", GetTransformByName("HU").position);
|
|
_map.AddNode("HV", GetTransformByName("HV").position);
|
|
_map.AddNode("HW", GetTransformByName("HW").position);
|
|
_map.AddNode("HX", GetTransformByName("HX").position);
|
|
_map.AddNode("HY", GetTransformByName("HY").position);
|
|
_map.AddNode("HZ", GetTransformByName("HZ").position);
|
|
_map.AddNode("II", GetTransformByName("II").position);
|
|
_map.AddNode("IJ", GetTransformByName("IJ").position);
|
|
_map.AddNode("IK", GetTransformByName("IK").position);
|
|
_map.AddNode("IL", GetTransformByName("IL").position);
|
|
_map.AddNode("IM", GetTransformByName("IM").position);
|
|
#endregion
|
|
|
|
#region 将Map初始化
|
|
_map.AddEdge("AA", "AB");
|
|
|
|
_map.AddEdge("AB", "AC");
|
|
_map.AddEdge("AB", "FM");
|
|
|
|
_map.AddEdge("AC", "HH");
|
|
_map.AddEdge("AC", "FL");
|
|
_map.AddEdge("AC", "AD");
|
|
|
|
_map.AddEdge("AD", "AE");
|
|
_map.AddEdge("AD", "FK");
|
|
|
|
_map.AddEdge("AE", "AG");
|
|
_map.AddEdge("AE", "FG");
|
|
_map.AddEdge("AE", "GZ");
|
|
|
|
_map.AddEdge("AG", "AH");
|
|
_map.AddEdge("AG", "FN");
|
|
_map.AddEdge("AG", "GY");
|
|
|
|
_map.AddEdge("AH", "AJ");
|
|
_map.AddEdge("AH", "GW");
|
|
_map.AddEdge("AH", "FO");
|
|
|
|
_map.AddEdge("AJ", "AF");
|
|
_map.AddEdge("AJ", "AI");
|
|
_map.AddEdge("AJ", "GW");
|
|
|
|
_map.AddEdge("AF", "FO");
|
|
_map.AddEdge("AF", "GM");
|
|
|
|
_map.AddEdge("AI", "GV");
|
|
_map.AddEdge("AI", "AK");
|
|
_map.AddEdge("AI", "GM");
|
|
|
|
_map.AddEdge("AK", "AL");
|
|
_map.AddEdge("AK", "GS");
|
|
_map.AddEdge("AK", "GN");
|
|
|
|
_map.AddEdge("AL", "GR");
|
|
_map.AddEdge("AL", "GO");
|
|
_map.AddEdge("AL", "AM");
|
|
|
|
_map.AddEdge("AM", "II");
|
|
_map.AddEdge("AM", "BG");
|
|
_map.AddEdge("AM", "AN");
|
|
|
|
_map.AddEdge("AN", "IJ");
|
|
_map.AddEdge("AN", "BF");
|
|
_map.AddEdge("AN", "AO");
|
|
|
|
_map.AddEdge("AO", "HZ");
|
|
_map.AddEdge("AO", "AP");
|
|
_map.AddEdge("AO", "AT");
|
|
|
|
_map.AddEdge("AP", "AR");
|
|
_map.AddEdge("AP", "AQ");
|
|
|
|
_map.AddEdge("AQ", "HY");
|
|
_map.AddEdge("AQ", "BS");
|
|
|
|
|
|
_map.AddEdge("AR", "AS");
|
|
|
|
_map.AddEdge("AS", "AX");
|
|
_map.AddEdge("AS", "AT");
|
|
|
|
|
|
_map.AddEdge("AT", "BF");
|
|
_map.AddEdge("AT", "AU");
|
|
|
|
|
|
_map.AddEdge("AU", "AV");
|
|
_map.AddEdge("AU", "BD");
|
|
_map.AddEdge("AU", "BB");
|
|
|
|
_map.AddEdge("AV", "AX");
|
|
_map.AddEdge("AV", "AW");
|
|
|
|
_map.AddEdge("AW", "AX");
|
|
_map.AddEdge("AW", "CJ");
|
|
_map.AddEdge("AW", "AY");
|
|
|
|
_map.AddEdge("AY", "BQ");
|
|
_map.AddEdge("AY", "AZ");
|
|
_map.AddEdge("AY", "BM");
|
|
|
|
_map.AddEdge("AZ", "BL");
|
|
_map.AddEdge("AZ", "BB");
|
|
|
|
_map.AddEdge("BB", "BC");
|
|
_map.AddEdge("BB", "BK");
|
|
|
|
_map.AddEdge("BC", "BD");
|
|
_map.AddEdge("BC", "CK");
|
|
|
|
_map.AddEdge("BD", "BE");
|
|
|
|
_map.AddEdge("BE", "BF");
|
|
|
|
_map.AddEdge("BF", "BG");
|
|
|
|
_map.AddEdge("BH", "BI");
|
|
_map.AddEdge("BH", "GI");
|
|
|
|
_map.AddEdge("BI", "CK");
|
|
_map.AddEdge("BI", "BJ");
|
|
|
|
_map.AddEdge("BJ", "CL");
|
|
_map.AddEdge("BJ", "CM");
|
|
_map.AddEdge("BJ", "FW");
|
|
|
|
_map.AddEdge("BK", "BL");
|
|
_map.AddEdge("BK", "CL");
|
|
_map.AddEdge("BK", "CN");
|
|
|
|
_map.AddEdge("BL", "CO");
|
|
_map.AddEdge("BL", "BM");
|
|
|
|
_map.AddEdge("BM", "BN");
|
|
_map.AddEdge("BM", "CP");
|
|
|
|
_map.AddEdge("BN", "BO");
|
|
_map.AddEdge("BN", "BQ");
|
|
|
|
_map.AddEdge("BO", "BU");
|
|
_map.AddEdge("BO", "BP");
|
|
|
|
_map.AddEdge("BP", "BQ");
|
|
_map.AddEdge("BP", "BR");
|
|
_map.AddEdge("BP", "BT");
|
|
|
|
_map.AddEdge("BQ", "CJ");
|
|
|
|
_map.AddEdge("BR", "BS");
|
|
_map.AddEdge("BR", "CJ");
|
|
|
|
_map.AddEdge("BS", "BT");
|
|
|
|
_map.AddEdge("BT", "BU");
|
|
|
|
_map.AddEdge("BU", "BV");
|
|
|
|
_map.AddEdge("BV", "BW");
|
|
|
|
_map.AddEdge("BW", "BX");
|
|
|
|
_map.AddEdge("BX", "BY");
|
|
_map.AddEdge("BX", "CC");
|
|
|
|
_map.AddEdge("BY", "CU");
|
|
|
|
_map.AddEdge("BZ", "CT");
|
|
|
|
_map.AddEdge("CC", "CD");
|
|
|
|
_map.AddEdge("CD", "CE");
|
|
_map.AddEdge("CD", "CU");
|
|
|
|
_map.AddEdge("CE", "CF");
|
|
|
|
_map.AddEdge("CF", "CG");
|
|
_map.AddEdge("CF", "CU");
|
|
|
|
_map.AddEdge("CG", "CV");
|
|
_map.AddEdge("CG", "CH");
|
|
|
|
_map.AddEdge("CH", "CT");
|
|
_map.AddEdge("CH", "CR");
|
|
|
|
_map.AddEdge("CI", "CY");
|
|
|
|
_map.AddEdge("CK", "CL");
|
|
|
|
_map.AddEdge("CM", "DD");
|
|
|
|
_map.AddEdge("CN", "CS");
|
|
_map.AddEdge("CN", "CO");
|
|
|
|
_map.AddEdge("CO", "CQ");
|
|
|
|
_map.AddEdge("CP", "CQ");
|
|
_map.AddEdge("CP", "CT");
|
|
|
|
_map.AddEdge("CQ", "CR");
|
|
|
|
_map.AddEdge("CR", "CW");
|
|
_map.AddEdge("CR", "CT");
|
|
|
|
_map.AddEdge("CS", "CW");
|
|
_map.AddEdge("CS", "CX");
|
|
|
|
_map.AddEdge("CT", "CU");
|
|
_map.AddEdge("CT", "CW");
|
|
|
|
_map.AddEdge("CV", "CW");
|
|
_map.AddEdge("CV", "CX");
|
|
|
|
_map.AddEdge("CX", "CY");
|
|
|
|
_map.AddEdge("CY", "CZ");
|
|
|
|
_map.AddEdge("CZ", "DE");
|
|
_map.AddEdge("CZ", "DQ");
|
|
_map.AddEdge("CZ", "DD");
|
|
|
|
_map.AddEdge("DD", "DQ");
|
|
|
|
_map.AddEdge("DE", "DF");
|
|
|
|
_map.AddEdge("DF", "DI");
|
|
_map.AddEdge("DF", "DG");
|
|
|
|
_map.AddEdge("DG", "DH");
|
|
|
|
_map.AddEdge("DH", "DK");
|
|
_map.AddEdge("DH", "DI");
|
|
|
|
_map.AddEdge("DI", "DJ");
|
|
|
|
_map.AddEdge("DJ", "DK");
|
|
_map.AddEdge("DJ", "DM");
|
|
_map.AddEdge("DJ", "DN");
|
|
|
|
_map.AddEdge("DK", "DL");
|
|
|
|
_map.AddEdge("DL", "DM");
|
|
_map.AddEdge("DL", "DV");
|
|
|
|
_map.AddEdge("DM", "DT");
|
|
|
|
_map.AddEdge("DN", "DP");
|
|
|
|
_map.AddEdge("DP", "DO");
|
|
|
|
_map.AddEdge("DO", "DP");
|
|
_map.AddEdge("DO", "DQ");
|
|
_map.AddEdge("DO", "DR");
|
|
_map.AddEdge("DO", "FU");
|
|
|
|
_map.AddEdge("DR", "DS");
|
|
|
|
_map.AddEdge("DS", "DU");
|
|
_map.AddEdge("DS", "EQ");
|
|
_map.AddEdge("DS", "EM");
|
|
|
|
_map.AddEdge("DT", "DV");
|
|
_map.AddEdge("DT", "DU");
|
|
_map.AddEdge("DT", "EO");
|
|
|
|
_map.AddEdge("DV", "EO");
|
|
|
|
_map.AddEdge("DW", "DX");
|
|
_map.AddEdge("DW", "EG");
|
|
|
|
_map.AddEdge("DX", "DY");
|
|
_map.AddEdge("DX", "EL");
|
|
_map.AddEdge("DX", "EE");
|
|
|
|
_map.AddEdge("DY", "DZ");
|
|
|
|
_map.AddEdge("DZ", "EL");
|
|
_map.AddEdge("DZ", "EN");
|
|
|
|
_map.AddEdge("EE", "EL");
|
|
_map.AddEdge("EE", "EF");
|
|
|
|
_map.AddEdge("EF", "EG");
|
|
_map.AddEdge("EF", "EJ");
|
|
|
|
_map.AddEdge("EG", "EH");
|
|
|
|
_map.AddEdge("EH", "EI");
|
|
|
|
_map.AddEdge("EI", "EJ");
|
|
|
|
_map.AddEdge("EJ", "EK");
|
|
|
|
_map.AddEdge("EK", "EL");
|
|
_map.AddEdge("EK", "EM");
|
|
|
|
_map.AddEdge("EL", "EN");
|
|
|
|
_map.AddEdge("EM", "EN");
|
|
|
|
_map.AddEdge("EN", "EO");
|
|
|
|
_map.AddEdge("EP", "ER");
|
|
_map.AddEdge("EP", "FF");
|
|
_map.AddEdge("EP", "IK");
|
|
|
|
_map.AddEdge("EQ", "FF");
|
|
_map.AddEdge("EQ", "FH");
|
|
_map.AddEdge("EQ", "FR");
|
|
|
|
_map.AddEdge("ER", "ES");
|
|
_map.AddEdge("ER", "EW");
|
|
|
|
_map.AddEdge("ET", "EU");
|
|
|
|
_map.AddEdge("EU", "EV");
|
|
_map.AddEdge("EU", "FM");
|
|
|
|
_map.AddEdge("EV", "FM");
|
|
_map.AddEdge("EV", "EW");
|
|
|
|
_map.AddEdge("EW", "EX");
|
|
_map.AddEdge("EW", "IL");
|
|
|
|
_map.AddEdge("EX", "IK");
|
|
_map.AddEdge("EX", "EY");
|
|
_map.AddEdge("EX", "FL");
|
|
|
|
_map.AddEdge("EY", "FG");
|
|
_map.AddEdge("EY", "EZ");
|
|
|
|
_map.AddEdge("EZ", "FH");
|
|
_map.AddEdge("EZ", "FQ");
|
|
_map.AddEdge("EZ", "FI");
|
|
|
|
_map.AddEdge("FF", "FG");
|
|
|
|
_map.AddEdge("FG", "IK");
|
|
_map.AddEdge("FG", "FH");
|
|
|
|
_map.AddEdge("FI", "FG");
|
|
|
|
_map.AddEdge("FG", "FK");
|
|
|
|
_map.AddEdge("FK", "FL");
|
|
|
|
_map.AddEdge("FL", "IL");
|
|
|
|
_map.AddEdge("FM", "IL");
|
|
|
|
_map.AddEdge("FN", "FO");
|
|
_map.AddEdge("FN", "FQ");
|
|
|
|
_map.AddEdge("FO", "FP");
|
|
_map.AddEdge("FO", "GM");
|
|
|
|
_map.AddEdge("FP", "FQ");
|
|
_map.AddEdge("FP", "GL");
|
|
|
|
_map.AddEdge("FR", "FS");
|
|
_map.AddEdge("FR", "FT");
|
|
|
|
_map.AddEdge("FS", "FY");
|
|
|
|
_map.AddEdge("FT", "FU");
|
|
|
|
_map.AddEdge("FU", "FY");
|
|
|
|
_map.AddEdge("FV", "FW");
|
|
|
|
_map.AddEdge("FW", "FX");
|
|
_map.AddEdge("FW", "GH");
|
|
|
|
_map.AddEdge("FX", "FY");
|
|
_map.AddEdge("FX", "GG");
|
|
|
|
_map.AddEdge("FY", "FZ");
|
|
|
|
_map.AddEdge("FZ", "GK");
|
|
_map.AddEdge("FZ", "GG");
|
|
|
|
_map.AddEdge("GG", "GJ");
|
|
_map.AddEdge("GG", "GH");
|
|
|
|
_map.AddEdge("GH", "GI");
|
|
|
|
_map.AddEdge("GI", "GQ");
|
|
_map.AddEdge("GI", "GP");
|
|
|
|
_map.AddEdge("GJ", "GK");
|
|
_map.AddEdge("GJ", "GQ");
|
|
|
|
_map.AddEdge("GK", "GL");
|
|
|
|
_map.AddEdge("GM", "GN");
|
|
|
|
_map.AddEdge("GN", "GO");
|
|
_map.AddEdge("GN", "IM");
|
|
|
|
_map.AddEdge("GO", "GP");
|
|
|
|
_map.AddEdge("GP", "IM");
|
|
|
|
_map.AddEdge("GQ", "IM");
|
|
|
|
_map.AddEdge("GR", "GS");
|
|
|
|
_map.AddEdge("GS", "GT");
|
|
|
|
_map.AddEdge("GT", "GU");
|
|
|
|
_map.AddEdge("GU", "GV");
|
|
|
|
_map.AddEdge("GV", "GW");
|
|
|
|
_map.AddEdge("GW", "GX");
|
|
|
|
_map.AddEdge("GX", "GY");
|
|
|
|
_map.AddEdge("GZ", "HR");
|
|
_map.AddEdge("GZ", "HH");
|
|
|
|
_map.AddEdge("HH", "HJ");
|
|
|
|
_map.AddEdge("HI", "HJ");
|
|
_map.AddEdge("HI", "HR");
|
|
_map.AddEdge("HI", "HK");
|
|
|
|
_map.AddEdge("HK", "HL");
|
|
_map.AddEdge("HK", "HS");
|
|
|
|
_map.AddEdge("HL", "HM");
|
|
|
|
_map.AddEdge("HN", "HO");
|
|
|
|
_map.AddEdge("HO", "HP");
|
|
|
|
_map.AddEdge("HP", "HS");
|
|
_map.AddEdge("HP", "HT");
|
|
|
|
_map.AddEdge("HQ", "HS");
|
|
_map.AddEdge("HQ", "HW");
|
|
|
|
_map.AddEdge("HT", "HU");
|
|
|
|
_map.AddEdge("HU", "HV");
|
|
_map.AddEdge("HU", "HX");
|
|
|
|
_map.AddEdge("HV", "HY");
|
|
|
|
_map.AddEdge("HW", "II");
|
|
_map.AddEdge("HW", "HX");
|
|
|
|
_map.AddEdge("HX", "HY");
|
|
_map.AddEdge("HX", "HZ");
|
|
|
|
_map.AddEdge("HZ", "IJ");
|
|
|
|
_map.AddEdge("II", "IJ");
|
|
#endregion
|
|
|
|
#region 初始化摄像头字典
|
|
_cameraMappingDic.Add(1, "GN");
|
|
_cameraMappingDic.Add(2, "GM");
|
|
_cameraMappingDic.Add(3, "FO");
|
|
_cameraMappingDic.Add(4, "FP");
|
|
_cameraMappingDic.Add(5, "IO");
|
|
_cameraMappingDic.Add(6, "IO");
|
|
_cameraMappingDic.Add(7, "GL");
|
|
_cameraMappingDic.Add(8, "GL");
|
|
_cameraMappingDic.Add(9, "GK");
|
|
_cameraMappingDic.Add(10, "IR");
|
|
_cameraMappingDic.Add(11, "FK");
|
|
_cameraMappingDic.Add(12, "CG");
|
|
_cameraMappingDic.Add(13, "GH");
|
|
_cameraMappingDic.Add(14, "GH");
|
|
_cameraMappingDic.Add(15, "GQ");
|
|
_cameraMappingDic.Add(16, "BF");
|
|
_cameraMappingDic.Add(17, "BH");
|
|
_cameraMappingDic.Add(18, "GP");
|
|
_cameraMappingDic.Add(19, "BH");
|
|
_cameraMappingDic.Add(20, "FH");
|
|
_cameraMappingDic.Add(21, "AB");
|
|
_cameraMappingDic.Add(22, "AQ");
|
|
_cameraMappingDic.Add(23, "AO");
|
|
_cameraMappingDic.Add(25, "AU");
|
|
_cameraMappingDic.Add(26, "GL");
|
|
_cameraMappingDic.Add(27, "AC");
|
|
_cameraMappingDic.Add(28, "AC");
|
|
_cameraMappingDic.Add(29, "FL");
|
|
_cameraMappingDic.Add(30, "AE");
|
|
_cameraMappingDic.Add(31, "GP");
|
|
_cameraMappingDic.Add(32, "BG");
|
|
_cameraMappingDic.Add(33, "BH");
|
|
_cameraMappingDic.Add(34, "IO");
|
|
_cameraMappingDic.Add(35, "GQ");
|
|
_cameraMappingDic.Add(36, "HH");
|
|
|
|
|
|
#endregion
|
|
|
|
#region 初始化Level Dic
|
|
|
|
List<int>_5_6_34 = new(){5,6,34};
|
|
List<int>_12_13_14 = new (){12,13,14};
|
|
|
|
List<int>_4_7_8_9_26 = new (){4,7,8,9,26};
|
|
List<int>_17_18_19_31_33 = new () { 17,18,19,31,33 };
|
|
|
|
List<int>_16_20 = new (){16,20};
|
|
List<int>_23_24 = new (){23,24};
|
|
List<int>_27_28 = new (){27,28};
|
|
List<int>_15_35 = new (){15,35};
|
|
|
|
List<int>_1 = new (){1};
|
|
List<int>_2 = new (){2};
|
|
List<int>_3 = new (){3};
|
|
List<int>_10 =new (){10};
|
|
List<int>_11= new (){11};
|
|
List<int>_20= new (){20};
|
|
List<int>_21= new (){21};
|
|
List<int>_22= new (){22};
|
|
List<int>_25= new (){25};
|
|
List<int>_29= new (){29};
|
|
List<int>_30= new (){30};
|
|
List<List<int>>level1 = new()
|
|
{
|
|
_1, _2, _3,_10, _11, _20, _21, _22, _25, _29, _30,
|
|
};
|
|
|
|
List<List<int>>level2 = new()
|
|
{
|
|
_16_20, _23_24, _27_28, _15_35
|
|
};
|
|
List<List<int>> level3 = new()
|
|
{
|
|
_5_6_34, _12_13_14
|
|
};
|
|
List<List<int>> level4 = new()
|
|
{
|
|
_4_7_8_9_26,_17_18_19_31_33
|
|
};
|
|
_levelDict.Add(1,level1);
|
|
_levelDict.Add(2,level2);
|
|
_levelDict.Add(3,level3);
|
|
_levelDict.Add(4,level4);
|
|
#endregion
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建带有可达/不可达状态的地图图结构
|
|
/// </summary>
|
|
private void ResetReachable()
|
|
{
|
|
_map.ResetReachable();
|
|
}
|
|
|
|
private void SetNodeReachable(int cameraID)
|
|
{
|
|
_map.GetNode(_cameraMappingDic[cameraID]).isReachable = false;
|
|
}
|
|
|
|
|
|
private Transform GetTransformByName(string name)
|
|
{
|
|
for (int i = 0; i < _trajectory.Count; i++)
|
|
{
|
|
if (_trajectory[i].name == name)
|
|
{
|
|
return _trajectory[i];
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
private Transform GetCameraTransformById(int id)
|
|
{
|
|
return _cameraTransList[id-1];
|
|
}
|
|
|
|
public void SetSpriteRenderColor(SpriteRenderer spriteRenderer)
|
|
{
|
|
spriteRenderer.color = HighlightedGreenColor;
|
|
}
|
|
|
|
public void ResetAllSpriteRenderColor()
|
|
{
|
|
for (int i = 0; i < _cameraTransList.Count; i++)
|
|
{
|
|
var spriteRenderer = _cameraTransList[i].GetComponent<SpriteRenderer>();
|
|
spriteRenderer.color = NormalGreenColor;
|
|
}
|
|
}
|
|
|
|
} |