本文整理汇总了C#中Path.destination方法的典型用法代码示例。如果您正苦于以下问题:C# Path.destination方法的具体用法?C# Path.destination怎么用?C# Path.destination使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Path
的用法示例。
在下文中一共展示了Path.destination方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: moveUnitAlongPath
public static IEnumerator moveUnitAlongPath(float time, Unit u, Path path, StageManager stage)
{
float dt = 0;
int distance = path.distance();
for(;;){
dt += Time.deltaTime;
if (dt >= time || distance == 1) {
break;
}
//which step
float completedAMT = ((dt*(distance-1))/time);
int sq = (int)completedAMT;
float pct = completedAMT - sq;
Point p1 = path.at(sq);
Point p2 = path.at(sq+1);
float x = Mathf.Lerp(p1.x, p2.x, pct);
float y = Mathf.Lerp(p1.y, p2.y, pct);
u.transform.position = new Vector2(x, y);
yield return null;
}
Point dest = path.destination();
u.transform.position = new Vector2(dest.x, dest.y);
u.tile.unit = null;
u.tile = stage.tiles[dest.x][dest.y];
u.tile.unit = u;
}
示例2: totalCost
private static int totalCost(Unit actor, StageManager manager, Path newPath, Point target)
{
Point dest = newPath.destination();
int distanceCost = (int)Mathf.Sqrt((target.x - dest.x)*(target.x - dest.x) + (target.y - dest.y)*(target.y - dest.y));
return distanceCost + newPath.cost(actor, manager);
}
示例3: findPathsMaster
private static List<Path> findPathsMaster(Unit actor, StageManager manager, Point target)
{
Point start = actor.tile.p;
List<Path> discoveredPaths = new List<Path>();
List<Path> unexploredPaths = new List<Path>();
Path[] starterPaths = {
new Path(start),
};
foreach (Path p in starterPaths) {
discoveredPaths.Add(p);
unexploredPaths.Add(p);
}
while(unexploredPaths.Count > 0) {
// TODO - get a real priority queue in here...
Path current = unexploredPaths[0];
unexploredPaths.RemoveAt(0);
Point destination = current.destination();
Point[] neighbors = {
new Point(destination.x-1, destination.y),
new Point(destination.x+1, destination.y),
new Point(destination.x, destination.y-1),
new Point(destination.x, destination.y+1)
};
foreach(Point dest in neighbors) {
Path newPath = new Path(current, dest);
if (onMap(dest, manager) &&
newPath.cost(actor, manager) <= actor.stats.klass.Movement() &&
notSeen(start, discoveredPaths, dest)) {
if (newPath.destination().Equals(target)) {
List<Path> rtn = new List<Path>(1);
rtn.Add(newPath);
return rtn;
}
discoveredPaths.Add(newPath);
queueUp(actor, manager, unexploredPaths, newPath, target);
}
}
}
if (target != null) {
return new List<Path>();
}
return discoveredPaths;
}