Pathfinding.AstarData.AddGraph C# (CSharp) Method

AddGraph() public method

public AddGraph ( System type ) : NavGraph
type System
return NavGraph
		public NavGraph AddGraph (System.Type type) {
			NavGraph graph = null;
			
			for (int i=0;i<graphTypes.Length;i++) {
				
				if (graphTypes[i] == type) {
					graph = CreateGraph (graphTypes[i]);
				}
			}
			
			if (graph == null) {
				Debug.LogError ("No NavGraph of type '"+type+"' could be found, "+graphTypes.Length+" graph types are avaliable");
				return null;
			}
			
			AddGraph (graph);
			
			return graph;
		}
		

Same methods

AstarData::AddGraph ( string type ) : NavGraph
AstarData::AddGraph ( NavGraph graph ) : void

Usage Example

Ejemplo n.º 1
0
    void Start()
    {
        // Calculate the center of the first map element (i.e. (0, 0)) in
        // world space coordinates.
        m_minX = OriginX - ((Width * NodeSize) / 2) + (NodeSize / 2);
        m_minZ = OriginZ - ((Depth * NodeSize) / 2) + (NodeSize / 2);

        int[,] mapData;
        int[,] objectData;
        if (GenerateMap)
        {
            MapGenerator generator = new MapGenerator(Width, Depth, RandomSeed);
            generator.RoomCount = RoomCount;
            generator.SpawnDistance = SpawnDistance;
            generator.MinRoomSideRatio = MinRoomSideRatio;
            generator.SeparationStrength = SeparationStrength;
            generator.MinRoomWidth = MinRoomWidth;
            generator.MaxRoomWidth = MaxRoomWidth;
            generator.MinRoomHeight = MinRoomHeight;
            generator.MaxRoomHeight = MaxRoomHeight;
            generator.UseSmoothing = UseSmoothing;
            generator.SmoothingThreshold = SmoothingThreshold;
            generator.SmoothingIterations = SmoothingIterations;
            generator.WeightedGraphEdgeRadius = WeightedGraphEdgeRadius;
            generator.Generate();
            mapData = generator.MapData;
            objectData = generator.ObjectData;
        }
        else
        {
            mapData = MapCrafter.GetMapData(this);
            objectData = MapCrafter.GetPropData(this);
        }

        // The map generator works with 2D arrays of integers. The following
        // functions convert the output arrays into actual game objects in
        // the scene.
        InstantiateMap(mapData);
        InstantiateProps(objectData);
        InstantiateStairwells(mapData);

        // The user interface script can't register for map events until all
        // grid square prefabs are created. Instruct the script to register for
        // events now. We can also initialise the minimap at this stage.
        UserInterface.RegisterForMapEvents();
        UserInterface.InitializeMiniMap(mapData);

        // Initialize a A* pathfinding graph.
        m_astarData = AstarPath.active.astarData;
        GridGraph graph = (GridGraph)m_astarData.AddGraph(typeof(GridGraph));
        graph.width = Width;
        graph.depth = Depth;
        graph.nodeSize = NodeSize;
        graph.center = new Vector3(OriginX, -10f, OriginZ);
        graph.UpdateSizeFromWidthDepth();
        graph.cutCorners = false;
        graph.collision.collisionCheck = true;
        graph.collision.mask = 1 << LayerMask.NameToLayer("Obstacle");
        graph.collision.heightCheck = true;
        graph.collision.heightMask = 1 << LayerMask.NameToLayer("Ground");
        AstarPath.active.Scan();

        // Spawn enemies on the map.
        SpawnEnemies(mapData);
    }