Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using System;
- using System.Linq;
- public class PathfindingMap : MonoBehaviour
- {
- public NodeTemplate[] nodeTypes;
- public GameObject NodeMesh;
- public int width = 10, height = 10;
- public static PathfindingMap Instance;
- PathfindingMap()
- {
- Instance = this;
- }
- public int[,] map;
- public SquareGrid grid = null;
- void Awake()
- {
- map = new int[width, height];
- grid = new SquareGrid(width, height);
- for (int x = 0; x < width; x++)
- {
- for (int y = 0; y < height; y++)
- {
- map[x, y] = 0;
- Vector3 pos = new Vector3(x, 0, y);
- GameObject temp = Instantiate(NodeMesh, pos, NodeMesh.transform.rotation) as GameObject;
- temp.transform.SetParent(transform);
- int type = map[x, y];
- NodeElement node = grid.nodes[x, y];
- node.mesh = temp.GetComponent<MeshRenderer>();
- node.mesh.material = nodeTypes[type].mat;
- node.passable = nodeTypes[type].enterable;
- node.item2 = nodeTypes[type].Cost;
- }
- }
- }
- public static NodeElement VecToNode(int x, int y)
- {
- return Instance.grid.nodes[x, y];
- }
- }
- [System.Serializable]
- public class NodeTemplate
- {
- public Material mat;
- public double Cost;
- public bool enterable;
- }
Add Comment
Please, Sign In to add comment