本文整理汇总了C#中GridNode类的典型用法代码示例。如果您正苦于以下问题:C# GridNode类的具体用法?C# GridNode怎么用?C# GridNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GridNode类属于命名空间,在下文中一共展示了GridNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
// Use this for initialization
void Start()
{
m_Grid = GameObject.FindGameObjectWithTag("Grid").GetComponent<Grid>();
m_target = m_Grid.GetRandGrid();
m_actor = GetComponent<IActor>();
m_path = new List<GridNode>();
}
示例2: PathRequest
public PathRequest(GridNode start, GridNode end, List<List<GridNode>> grid, Action<GridNode[], bool> callback)
{
pathStart = start;
pathEnd = end;
pathGrid = grid;
this.callback = callback;
}
示例3: RequestPath
public static void RequestPath(GridNode pathStart, GridNode pathEnd, List<List<GridNode>> pathGrid, Action<GridNode[], bool> callback)
{
PathRequest newRequest = new PathRequest(pathStart, pathEnd, pathGrid, callback);
Instance.pathRequestQueue.Enqueue(newRequest);
Instance.TryProcessNext();
}
示例4: getDistanceBetween
public int getDistanceBetween(GridNode current, GridNode goal)
{
int dx = Math.Abs(goal.gridPositionX - current.gridPositionX);
int dy = Math.Abs(goal.gridPositionY - current.gridPositionY);
int h = (int)(10*Math.Sqrt(dx*dx + dy*dy));
return h;
}
示例5: getHeuristic
public int getHeuristic(GridNode current, GridNode goal)
{
int dx = Math.Abs(goal.gridPositionX - current.gridPositionX);
int dy = Math.Abs(goal.gridPositionY - current.gridPositionY);
int h = (int)(10*(dx+dy)+(14-2*10)+Math.Min(dx,dy));
return h;
}
示例6: getManhattanHeuristic
public int getManhattanHeuristic(GridNode current, GridNode goal)
{
int dx = Math.Abs(goal.gridPositionX - current.gridPositionX);
int dy = Math.Abs(goal.gridPositionY - current.gridPositionY);
int h = (int)(dx + dy);
return h;
}
示例7: createGrid
// Use this for initialization
protected void createGrid(MeshRenderer f)
{
// get the mesh renderer to calculate the floor bounds
floor = f;
floor_width = floor.bounds.size.x;
floor_depth = floor.bounds.size.z;
// init grid array
grid = new GridNode[blockRows, blockColumns];
// calculate the block width & depth
block_width = floor_width / blockRows;
block_depth = floor_depth / blockColumns;
// get the top left point to draw from
Vector3 TopLeftPoint = new Vector3(transform.position.x - (floor_width/2), transform.position.y, transform.position.z + (floor_depth / 2));
// the current position of the new block in the loop
Vector3 currentPosition = TopLeftPoint;
// loop through to add the blocks (nodes) to the grid
for (int i = 0; i < blockRows; i++)
{
for (int j = 0; j < blockColumns; j++)
{
grid[i, j] = new GridNode(currentPosition, new Vector2(block_width, block_depth)); // add a node at the current position
currentPosition.x += block_width; // move to the right one block
}
// move to the next row
currentPosition.x = TopLeftPoint.x;
currentPosition.z -= block_depth;
}
}
示例8: AStar
public AStar(int width, int height)
{
w = width;
h = height;
//MAKE THE ARRAY OF COORDINATES SO THAT WE SEARCH THEM IN THE RIGHT ORDER
coords = new System.Collections.Generic.List<Vector2>();
coords.Add(new Vector2(0,-1)); // UP
coords.Add(new Vector2(1,0)); // RIGHT
coords.Add(new Vector2(0,1)); // DOWN
coords.Add(new Vector2(-1,0)); // LEFT
if(allowDiagonals)
{
coords.Add(new Vector2(-1,-1)); // UP-LEFT
coords.Add(new Vector2(1,-1)); // UP-RIGHT
coords.Add(new Vector2(1,1)); // DOWN-RIGHT
coords.Add(new Vector2(-1,1)); // DOWNLEFT
}
relCurrent = new Vector2();
relLast = new Vector2();
startNode = new GridNode();
endNode = new GridNode();
open = new NodeList(w*h);
closed = new NodeList(w*h);
createGrid(w,h);
r = new RandomSeed(THE_SEED);
}
示例9: Update
// Update is called once per frame
void Update()
{
Vector2 steering = Vector2.zero;
GridNode m_current = m_Grid.GetGridForPosition(transform.position);
if (!m_target.Passable || m_current == m_target || m_path.Count == 0)
{
m_target = m_Grid.GetRandGrid();
m_needToCalPath = true;
}
if (m_current != null && m_needToCalPath)
{
m_needToCalPath = false;
if (m_path.Count > 0 && m_showPath)
{
m_path.First().Start = false;
m_path.Last().End = false;
foreach (GridNode node in m_path)
{
node.Path = false;
}
}
AStar.GetShortestPath(m_current, m_target, m_Grid.diagnoal, out m_path);
if (m_path.Count > 0 && m_showPath)
{
m_path.First().Start = true;
m_path.Last().End = true;
foreach (GridNode node in m_path)
{
node.Path = true;
}
}
m_path_index = 1;
}
if (m_path.Count > 1)
{
GridNode seeking = m_path[m_path_index];
if (m_current == seeking)
{
m_path_index += 1;
seeking = m_path[m_path_index];
}
if (seeking == m_target)
{
Renderer renderer = seeking.GetComponent<Renderer>();
if (renderer != null)
{
steering = SteeringHelper.GetArriveSteering(m_actor, seeking.transform.position, renderer.bounds.size.x);
}
}
else
{
steering = SteeringHelper.GetSeekSteering(m_actor, seeking.transform.position);
}
}
m_actor.SetInput(steering.x, steering.y);
}
示例10: Start
public override void Start()
{
base.Start();
node = AstarPath.active.GetNearest(this.transform.position).node as GridNode;
_bounds = new Bounds(transform.position, new Vector3(1.5f, 3f, 1.5f));
//_bounds.extents = new Vector3(1.5f, 3f, 1.5f);
//gameObject.collider.enabled = false;
}
示例11: GetDistance
int GetDistance(GridNode nodeA, GridNode nodeB)
{
int distX = Mathf.Abs(nodeA.gridX - nodeB.gridX);
int distY = Mathf.Abs(nodeA.gridY - nodeB.gridY);
if (distX > distY)
return 14 * distY + 10 * (distX - distY);
return 14 * distX + 10 * (distY - distX);
}
示例12: connections
public static List<int> connections(GridNode node)
{
Node[] nodes = node.connections;
List<int> indexes = new List<int>();
foreach (Node n in new PerceivableNode(node)){
indexes.Add(n.GetNodeIndex());
}
return indexes;
}
示例13: FindPath
public IEnumerator FindPath(GridNode start, GridNode end, List<List<GridNode>> grid)
{
List<GridNode> path;
bool success = FindPathImmediate(start, end, grid, out path);
yield return null;
requestManager.FinishedProcessingPath(path.ToArray(), success);
}
示例14: Arrive
public void Arrive(GridNode i_seeking)
{
Vector2 steering = Vector2.zero;
Renderer renderer = i_seeking.GetComponent<Renderer>();
if (renderer != null)
{
steering = SteeringHelper.GetArriveSteering(m_actor, i_seeking.transform.position, renderer.bounds.size.x);
}
m_actor.SetInput(steering.x, steering.y);
}
示例15: Execute
/// <summary>
/// Implement this method as an external command for Revit.
/// </summary>
/// <param name="commandData">An object that is passed to the external application
/// which contains data related to the command,
/// such as the application object and active view.</param>
/// <param name="message">A message that can be set by the external application
/// which will be displayed if a failure or cancellation is returned by
/// the external command.</param>
/// <param name="elements">A set of elements to which the external application
/// can add elements that are to be highlighted in case of failure or cancellation.</param>
/// <returns>Return the status of the external command.
/// A result of Succeeded means that the API external method functioned as expected.
/// Cancelled can be used to signify that the user cancelled the external operation
/// at some point. Failure should be returned if the application is unable to proceed with
/// the operation.</returns>
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
Autodesk.Revit.ApplicationServices.Application app = commandData.Application.Application;
Document doc = commandData.Application.ActiveUIDocument.Document;
Parameter param = null;
Bitmap image = new Bitmap(doc.PathName + "_grayscale.bmp");
FilteredElementCollector collector = new FilteredElementCollector(doc);
ICollection<Element> collection = collector.OfClass(typeof(DividedSurface)).ToElements();
foreach (Element element in collection)
{
DividedSurface ds = element as DividedSurface;
GridNode gn = new GridNode();
for (int u = 0; u < ds.NumberOfUGridlines; u++)
{
gn.UIndex = u;
for (int v = 0; v < ds.NumberOfVGridlines; v++)
{
gn.VIndex = v;
if (ds.IsSeedNode(gn))
{
FamilyInstance familyinstance = ds.GetTileFamilyInstance(gn, 0);
if (familyinstance != null)
{
param = familyinstance.get_Parameter("Grayscale");
if (param == null) throw new Exception("Panel family must have a Grayscale instance parameter");
else
{
System.Drawing.Color pixelColor = new System.Drawing.Color();
try
{
pixelColor = image.GetPixel(image.Width - v, image.Height - u);
double grayscale = 255 - ((pixelColor.R + pixelColor.G + pixelColor.B) / 3);
if (grayscale == 0)
{
doc.Delete(familyinstance);
}
else
{
param.Set(grayscale / 255);
}
}
catch (System.Exception)
{
// MessageBox.Show("Exception: " + u + ", " + v);
}
}
}
}
}
}
}
doc.Regenerate(); ;
return Result.Succeeded;
}