Guest User

Untitled

a guest
Sep 28th, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. using System.Linq;
  6. public class PathfindingMap : MonoBehaviour
  7. {
  8.     public NodeTemplate[] nodeTypes;
  9.     public GameObject NodeMesh;
  10.     public int width = 10, height = 10;
  11.     public static PathfindingMap Instance;
  12.     PathfindingMap()
  13.     {
  14.         Instance = this;
  15.     }
  16.     public int[,] map;
  17.     public SquareGrid grid = null;
  18.     void Awake()
  19.     {
  20.         map = new int[width, height];
  21.         grid = new SquareGrid(width, height);
  22.         for (int x = 0; x < width; x++)
  23.         {
  24.             for (int y = 0; y < height; y++)
  25.             {
  26.                 map[x, y] = 0;
  27.                 Vector3 pos = new Vector3(x, 0, y);
  28.                 GameObject temp = Instantiate(NodeMesh, pos, NodeMesh.transform.rotation) as GameObject;
  29.                 temp.transform.SetParent(transform);
  30.                 int type = map[x, y];
  31.                 NodeElement node = grid.nodes[x, y];
  32.                 node.mesh = temp.GetComponent<MeshRenderer>();
  33.                 node.mesh.material = nodeTypes[type].mat;
  34.                 node.passable = nodeTypes[type].enterable;
  35.                 node.item2 = nodeTypes[type].Cost;
  36.             }
  37.         }
  38.     }
  39.     public static NodeElement VecToNode(int x, int y)
  40.     {
  41.         return Instance.grid.nodes[x, y];
  42.     }
  43. }
  44. [System.Serializable]
  45. public class NodeTemplate
  46. {
  47.     public Material mat;
  48.     public double Cost;
  49.     public bool enterable;
  50. }
Add Comment
Please, Sign In to add comment