本文整理汇总了C#中Tile.GetNeighbours方法的典型用法代码示例。如果您正苦于以下问题:C# Tile.GetNeighbours方法的具体用法?C# Tile.GetNeighbours怎么用?C# Tile.GetNeighbours使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tile
的用法示例。
在下文中一共展示了Tile.GetNeighbours方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTilesWithinRange
public static List<Tile> GetTilesWithinRange(Tile rootHT, int rangeMin, int rangeMax)
{
if(rangeMin==0 && rangeMax==0) return new List<Tile>();
List<Tile> tileNeighbours=rootHT.GetNeighbours();
if(rangeMax==1){
List<Tile> list=new List<Tile>();
for(int i=0; i<tileNeighbours.Count; i++) list.Add(tileNeighbours[i]);
return list;
}
//for performance benchmarking
//DateTime timeS;
//DateTime timeE;
//TimeSpan timeSpan;
//timeS=System.DateTime.Now;
List<Tile> closeList=new List<Tile>();
List<Tile> openList=new List<Tile>();
List<Tile> newOpenList=new List<Tile>();
foreach(Tile neighbour in tileNeighbours){
if(!newOpenList.Contains(neighbour)){
newOpenList.Add(neighbour);
}
}
for(int i=0; i<rangeMax; i++){
openList=newOpenList;
newOpenList=new List<Tile>();
foreach(Tile ht in openList){
foreach(Tile neighbour in ht.GetNeighbours()){
if(!closeList.Contains(neighbour) && !openList.Contains(neighbour) && !newOpenList.Contains(neighbour)){
newOpenList.Add(neighbour);
}
}
}
foreach(Tile t in openList){
if(t!=rootHT && !closeList.Contains(t)) closeList.Add(t);
}
}
for(int i=0; i<closeList.Count; i++){
Tile ht=closeList[i];
if(Distance(ht, rootHT)<=rangeMin){
closeList.RemoveAt(i);
i-=1;
}
}
//show how much time has been used
//timeE=System.DateTime.Now;
//timeSpan=timeE-timeS;
//Debug.Log( "Time:"+timeSpan.TotalMilliseconds);
return closeList;
}
示例2: GetWalkableTilesWithinRange
public static List<Tile> GetWalkableTilesWithinRange(Tile rootHT, int range)
{
if(range==0) return new List<Tile>();
List<Tile> tileNeighbours=rootHT.GetNeighbours();
if(range==1){
List<Tile> list=new List<Tile>();
for(int i=0; i<tileNeighbours.Count; i++){
if(tileNeighbours[i].walkable) list.Add(tileNeighbours[i]);
}
return list;
}
//for performance benchmarking
//DateTime timeS;
//DateTime timeE;
//TimeSpan timeSpan;
//timeS=System.DateTime.Now;
List<Tile> closeList=new List<Tile>();
List<Tile> openList=new List<Tile>();
List<Tile> newOpenList=new List<Tile>();
foreach(Tile neighbour in tileNeighbours){
if(neighbour.walkable && neighbour.unit==null && !newOpenList.Contains(neighbour)){
newOpenList.Add(neighbour);
}
}
for(int i=0; i<range; i++){
openList=newOpenList;
newOpenList=new List<Tile>();
foreach(Tile ht in openList){
foreach(Tile neighbour in ht.GetNeighbours()){
if(neighbour.walkable && neighbour.unit==null && !newOpenList.Contains(neighbour)){
//if(!neighbour.walkable) Debug.Log("tittt");
newOpenList.Add(neighbour);
}
}
}
foreach(Tile t in openList){
if(t!=rootHT && !closeList.Contains(t)){
//if(!t.walkable) Debug.Log("tit");
closeList.Add(t);
}
}
}
//show how much time has been used
//timeE=System.DateTime.Now;
//timeSpan=timeE-timeS;
//Debug.Log( "Time:"+timeSpan.TotalMilliseconds);
return closeList;
}
示例3: GetAllNeighbouringTile
//get all neighbours of the a tile
public static List<Tile> GetAllNeighbouringTile(Tile tile)
{
List<Tile> list=new List<Tile>();
list.Add(tile);
foreach(Tile neighbour in tile.GetNeighbours()){
list.Add(neighbour);
}
return list;
}