本文整理汇总了C#中Pathfinding.GraphUpdateObject类的典型用法代码示例。如果您正苦于以下问题:C# GraphUpdateObject类的具体用法?C# GraphUpdateObject怎么用?C# GraphUpdateObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphUpdateObject类属于Pathfinding命名空间,在下文中一共展示了GraphUpdateObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBounds
/// <summary>
/// Adds the bounds to the pathfinder.
/// </summary>
/// <param name='t'>
/// T.
/// </param>
public static void AddBounds(Transform t)
{
//Debug.Log (t.name);
Bounds b = t.collider.bounds;
GraphUpdateObject guo = new GraphUpdateObject(b);
AstarPath.active.UpdateGraphs (guo);
}
示例2: DoStuff
public void DoStuff()
{
guo = new GraphUpdateObject(Fsm.GetOwnerDefaultTarget(target).collider.bounds);
startNode = AstarPath.active.GetNearest (Start.Value).node;
endNode = AstarPath.active.GetNearest (End.Value).node;
PathIsPossible.Value = GraphUpdateUtilities.UpdateGraphsNoBlock(guo, startNode, endNode, true);
}
示例3: SetState
public void SetState (bool open) {
this.open = open;
if (updateGraphsWithGUO) {
// Update the graph below the door
// Set the tag of the nodes below the door
// To something indicating that the door is open or closed
GraphUpdateObject guo = new GraphUpdateObject(bounds);
int tag = open ? opentag : closedtag;
// There are only 32 tags
if (tag > 31) { Debug.LogError("tag > 31"); return; }
guo.modifyTag = true;
guo.setTag = tag;
guo.updatePhysics = false;
AstarPath.active.UpdateGraphs(guo);
}
// Play door animations
if (open) {
GetComponent<Animation>().Play("Open");
} else {
GetComponent<Animation>().Play("Close");
}
}
示例4: PlaceObject
public GameObject obstacle; // Cube
#endregion Fields
#region Methods
public void PlaceObject(GameObject go)
{
Ray ray = Camera.main.ScreenPointToRay (Input.mousePosition);
RaycastHit hit;
if ( Physics.Raycast (ray, out hit, Mathf.Infinity)) {
string hitName = hit.collider.name;
Debug.Log ("Voici la hauteur du GO : " + go.transform.lossyScale.y);
if (hitName == "Ground") {
Vector3 posGO = hit.collider.gameObject.transform.position;
//Vector3 p = new Vector3(hit.point.x, posGO.y + go.transform.lossyScale.y / 2, hit.point.z);
Vector3 p = new Vector3(hit.point.x, 1, hit.point.z);
Debug.Log ("Avec la position : " + p);
GameObject obj = (GameObject)GameObject.Instantiate (go,p,Quaternion.identity);
Bounds b = obj.collider.bounds;
//Pathfinding.Console.Write ("// Placing Object\n");
GraphUpdateObject guo = new GraphUpdateObject(b);
AstarPath.active.UpdateGraphs (guo);
if (direct) {
//Pathfinding.Console.Write ("// Flushing\n");
AstarPath.active.FlushGraphUpdates();
}
}
}
}
示例5: Apply
/** Updates graphs with a created GUO.
* Creates a Pathfinding::GraphUpdateObject with a Pathfinding::GraphUpdateShape
* representing the polygon of this object and update all graphs using AstarPath::UpdateGraphs.
* This will not update graphs directly. See AstarPath::UpdateGraph for more info.
*/
public void Apply()
{
if (AstarPath.active == null) {
Debug.LogError ("There is no AstarPath object in the scene");
return;
}
firstApplied = true;
Pathfinding.GraphUpdateShape shape = new Pathfinding.GraphUpdateShape ();
shape.convex = convex;
shape.points = points;
GraphUpdateObject guo = new GraphUpdateObject (shape.GetBounds ());
guo.shape = shape;
guo.modifyWalkability = modifyWalkability;
guo.setWalkability = setWalkability;
guo.addPenalty = penalty;
#if ConfigureTagsAsMultiple
guo.tags = tags;
#else
guo.modifyTag = modifyTag;
guo.setTag = setTag;
#endif
AstarPath.active.UpdateGraphs (guo);
}
示例6: UpdateGraphsNoBlock
/** Updates graphs and checks if all nodes are still reachable from each other.
* Graphs are updated, then a check is made to see if the nodes are still reachable from each other.
* If they are not, the graphs are reverted to before the update and \a false is returned.
* This is slower than a normal graph update.
* All queued graph updates and thread safe callbacks will be flushed during this function.
*
* \note This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0).
* So when using this, it is recommended to set AstarPath.minAreaSize to 0. (A* Inspector -> Settings -> Pathfinding)
*
* \param guo The GraphUpdateObject to update the graphs with
* \param nodes Nodes which should have valid paths between them. All nodes should be walkable or \a false will be returned.
* \param alwaysRevert If true, reverts the graphs to the old state even if no blocking ocurred
*
* \returns True if the given nodes are still reachable from each other after the \a guo has been applied. False otherwise.
*/
public static bool UpdateGraphsNoBlock (GraphUpdateObject guo, List<GraphNode> nodes, bool alwaysRevert = false) {
//Make sure all nodes are walkable
for (int i = 0; i < nodes.Count; i++) if (!nodes[i].Walkable) return false;
//Track changed nodes to enable reversion of the guo
guo.trackChangedNodes = true;
bool worked = true;
AstarPath.RegisterSafeUpdate(delegate() {
AstarPath.active.UpdateGraphs(guo);
//Call thread safe callbacks, includes graph updates
AstarPath.active.FlushGraphUpdates();
//Check if all nodes are in the same area and that they are walkable, i.e that there are paths between all of them
worked = worked && PathUtilities.IsPathPossible(nodes);
//If it did not work, revert the GUO
if (!worked || alwaysRevert) {
guo.RevertFromBackup();
//The revert operation does not revert ALL nodes' area values, so we must flood fill again
AstarPath.active.FloodFill();
}
});
//Force the thread safe callback to be called
AstarPath.active.FlushThreadSafeCallbacks();
//Disable tracking nodes, not strictly necessary, but will slightly reduce the cance that some user causes errors
guo.trackChangedNodes = false;
return worked;
}
示例7: SetState
public void SetState (bool open) {
this.open = open;
if (updateGraphsWithGUO) {
GraphUpdateObject guo = new GraphUpdateObject(bounds);
#if ConfigureTagsAsMultiple
guo.tags = new TagMask ();
guo.tags.tagsChange = 1 << bitToChange;
guo.tags.tagsSet = open ? 1 << bitToChange : 0;
#else
int tag = open ? opentag : closedtag;
if (tag > 31) { Debug.LogError ("tag > 31"); return; }
guo.modifyTag = true;
guo.setTag = tag;
guo.updatePhysics = false;
#endif
AstarPath.active.UpdateGraphs (guo);
}
if (open) {
animation.Play ("Open");
} else {
animation.Play ("Close");
}
}
示例8: Start
// private float castle_offset = 10.0f;
// Use this for initialization
void Start()
{
// float ter_Width = Terrain.activeTerrain.terrainData.size.x;
// float ter_Height = Terrain.activeTerrain.terrainData.size.z;
for(int i = 0; i < 25; ++i)
{
for(int j = 0; j < 50; ++j)
{
if(ground_tiles[i,j] == 0)
{
}
else if(ground_tiles[i,j] == 1)
{
//Vector3 pos = new Vector3((-12 * j) + 5, 0.1f, (ter_Height - (250 * i) - 30f) / 4.0f);
Vector3 pos = new Vector3(10 * j + 5, 0.1f, 250 - (10 * i)-5f);
GameObject obj = (GameObject)Instantiate(water, pos, Quaternion.identity);
Bounds b = obj.collider.bounds;
GraphUpdateObject guo = new GraphUpdateObject(b);
AstarPath.active.UpdateGraphs(guo);
}
else if(ground_tiles[i,j] == 2)
{
Vector3 pos = new Vector3(10 * j + 5, 0.1f, 250 - (10 * i)-5f);
GameObject obj = (GameObject)Instantiate(tree, pos, Quaternion.Euler(-90,0,0));
Bounds b = obj.collider.bounds;
GraphUpdateObject guo = new GraphUpdateObject(b);
AstarPath.active.UpdateGraphs(guo);
}
//else if(ground_tiles[i,j] == 3)
//{
// Vector3 pos = new Vector3(10 * j + 5, 0.1f, ter_Height - (10 * i)-5f);
// Instantiate(goldmine, pos, Quaternion.identity);
//}
//else if(ground_tiles[i,j] == 4)
//{
// Vector3 pos = new Vector3(10 * j + 5, 0.1f, ter_Height - (10 * i)-5f);
// Instantiate(farm, pos, Quaternion.identity);
//}
//else if(ground_tiles[i,j] == 5)
//{
// Vector3 pos = new Vector3(10 * j + 5, 0.1f, ter_Height - (10 * i)-5f);
// Instantiate(barracks, pos, Quaternion.identity);
//}
else if(ground_tiles[i,j] == 6)
{
/*//Vector3 pos = new Vector3(10 * j + 5, 0.1f, (ter_Height - (250 * i) - 30f) / 4.0f);
Vector3 pos = new Vector3(10 * j + 5, 0.1f, ter_Height - (10 * i)-5f);
Instantiate(Ore_Fields, pos, Quaternion.identity); */
}
else
{
Debug.Log ("Invalid tile index");
}
}
}
}
示例9: GraphUpdateObject
/** Updates graphs and checks if all nodes are still reachable from each other.
* Graphs are updated, then a check is made to see if the nodes are still reachable from each other.
* If they are not, the graphs are reverted to before the update and \a false is returned.\n
* This is slower than a normal graph update.
* All queued graph updates and thread safe callbacks will be flushed during this function.
*
* \note This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0).
* So when using this, it is recommended to set AstarPath.minAreaSize to 0 (A* Inspector -> Settings -> Pathfinding)
*
* \param guo The GraphUpdateObject to update the graphs with
* \param node1 Node which should have a valid path to \a node2. All nodes should be walkable or \a false will be returned.
* \param node2 Node which should have a valid path to \a node1. All nodes should be walkable or \a false will be returned.
* \param alwaysRevert If true, reverts the graphs to the old state even if no blocking ocurred
*
* \returns True if the given nodes are still reachable from each other after the \a guo has been applied. False otherwise.
*
\code
var guo = new GraphUpdateObject (tower.GetComponent<Collider>.bounds);
var spawnPointNode = AstarPath.active.GetNearest (spawnPoint.position).node;
var goalNode = AstarPath.active.GetNearest (goalNode.position).node;
if (GraphUpdateUtilities.UpdateGraphsNoBlock (guo, spawnPointNode, goalNode, false)) {
// Valid tower position
// Since the last parameter (which is called "alwaysRevert") in the method call was false
// The graph is now updated and the game can just continue
} else {
// Invalid tower position. It blocks the path between the spawn point and the goal
// The effect on the graph has been reverted
Destroy (tower);
}
\endcode
*/
public static bool UpdateGraphsNoBlock (GraphUpdateObject guo, GraphNode node1, GraphNode node2, bool alwaysRevert = false) {
List<GraphNode> buffer = ListPool<GraphNode>.Claim ();
buffer.Add (node1);
buffer.Add (node2);
bool worked = UpdateGraphsNoBlock (guo, buffer, alwaysRevert);
ListPool<GraphNode>.Release (buffer);
return worked;
}
示例10: NoPathBlockage
private bool NoPathBlockage(GameObject placedObject) {
var updateObject = new GraphUpdateObject(placedObject.GetComponent<Collider2D>().bounds);
Vector3 start = GameManager.instance.spawnPoint.transform.position;
Vector3 end = GameManager.instance.exitPoint.transform.position;
var startNode = AstarPath.active.GetNearest(start).node;
var endNode = AstarPath.active.GetNearest(end).node;
return GraphUpdateUtilities.UpdateGraphsNoBlock(updateObject, startNode, endNode);
}
示例11: instatiateObject
private void instatiateObject(string asset, Vector3 coords)
{
GameObject resource = (GameObject)Instantiate (Resources.Load ("Prefabs/" + asset, typeof(GameObject)), coords, Quaternion.identity); //Crear l'arbre
if (GameObject.Find ("Map")) {
resource.transform.parent = GameObject.Find ("Map").transform;
}
var guo = new GraphUpdateObject (resource.GetComponent<Collider> ().bounds);
guo.updatePhysics = true;
AstarPath.active.UpdateGraphs (guo);
}
示例12: updateGraph
public void updateGraph(GameObject obj, bool addTower)
{
GraphUpdateObject graphObj = new GraphUpdateObject (obj.GetComponent<Collider> ().bounds);
if (!addTower) {
graphObj.modifyWalkability = true;
graphObj.setWalkability = true;
}
AstarPath.active.UpdateGraphs (graphObj);
updateMonstersPath ();
}
示例13: UpdateGraphsNoBlock
/** Updates graphs and checks if all nodes are still reachable from each other.
* Graphs are updated, then a check is made to see if the nodes are still reachable from each other.
* If they are not, the graphs are reverted to before the update and \a false is returned.\n
* This is slower than a normal graph update.
* All queued graph updates and thread safe callbacks will be flushed during this function.
*
* \note This might return true for small areas even if there is no possible path if AstarPath.minAreaSize is greater than zero (0).
* So when using this, it is recommended to set AstarPath.minAreaSize to 0 (A* Inspector -> Settings -> Pathfinding)
*
* \param guo The GraphUpdateObject to update the graphs with
* \param node1 Node which should have a valid path to \a node2. All nodes should be walkable or \a false will be returned.
* \param node2 Node which should have a valid path to \a node1. All nodes should be walkable or \a false will be returned.
* \param alwaysRevert If true, revert the graphs even though no blocking ocurred
*/
public static bool UpdateGraphsNoBlock(GraphUpdateObject guo, Node node1, Node node2, bool alwaysRevert = false)
{
List<Node> buffer = ClaimNodeBuffer ();
buffer.Add (node1);
buffer.Add (node2);
bool worked = UpdateGraphsNoBlock (guo,buffer, alwaysRevert);
ReleaseNodeBuffer (buffer);
return worked;
}
示例14: addToPathFinder
void addToPathFinder()
{
//AstarPath.active.UpdateGraphs(gameObject.collider.bounds);
//Bounds b = gameObject.collider.bounds;
//guo = new GraphUpdateObject(b);
//addToPathFinder();*/
//print ("add");
AstarPath.active.UpdateGraphs (guo,0.0f);
Bounds b = gameObject.collider.bounds;
guo = new GraphUpdateObject(b);
AstarPath.active.UpdateGraphs (guo);
}
示例15: UpdateGraph
public void UpdateGraph(GameObject go)
{
if(go.layer == LAYER_MASK )
AstarPath.active.UpdateGraphs (go.collider.bounds);
guo = new GraphUpdateObject(go.collider.bounds);
AstarPath.active.UpdateGraphs(guo);
graphUpdate.Apply();
AstarPath.active.FloodFill();
AstarPath.active.Scan();
}