Advertisement
ttkhila

Teste Coordenadas Unity - Board

Jun 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Board : MonoBehaviour
  6. {
  7.  
  8.     public Dictionary<Vector3Int, TileLogic> tiles;
  9.     public List<Floor> floors;
  10.     public static Board instance;
  11.  
  12.     [HideInInspector]
  13.     public Grid grid;
  14.  
  15.     void Start()
  16.     {
  17.         InitSequence();
  18.     }
  19.  
  20.     void Awake() {
  21.         tiles = new Dictionary<Vector3Int, TileLogic>();
  22.         instance = this;
  23.         grid = GetComponent<Grid>();
  24.     }
  25.  
  26.     public void InitSequence() {
  27.         LoadFloors();
  28.         Debug.Log("Foram criados "+tiles.Count+ " tiles");
  29.     }
  30.  
  31.     void LoadFloors() {
  32.         for (int i = 0; i < floors.Count; i++) {
  33.             List<Vector3Int> floorsTiles = floors[i].loadTiles();
  34.             for (int j=0; j<floorsTiles.Count; j++) {
  35.                 if (!tiles.ContainsKey(floorsTiles[j])) {
  36.                     CreateTile(floorsTiles[j], floors[i]);
  37.                 }
  38.             }
  39.         }
  40.     }
  41.  
  42.     void CreateTile(Vector3Int pos, Floor floor) {
  43.         Vector3 worldPos = grid.CellToWorld(pos);
  44.         worldPos.y += (floor.tilemap.tileAnchor.y / 2) - 0.5f;
  45.         TileLogic tileLogic = new TileLogic(pos, worldPos, floor);
  46.         tiles.Add(pos, tileLogic);
  47.     }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement