Tile.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using UnityEngine;
  2. using System.Collections;
  3. public class Tile : MapObject
  4. {
  5. public const float TILE_WIDTH = 1f;
  6. public const float TILE_LENGTH = 1f;
  7. private int col;
  8. private int row;
  9. public int type;
  10. public void setGridPosition(int col, int row)
  11. {
  12. this.col = col;
  13. this.row = row;
  14. Vector3 position = transform.position;
  15. position.x = TILE_WIDTH*col + TILE_WIDTH*0.5f;
  16. position.z = TILE_LENGTH*row + TILE_LENGTH*0.5f;
  17. transform.position = position;
  18. }
  19. public int getCol()
  20. {
  21. return col;
  22. }
  23. public int getRow()
  24. {
  25. return row;
  26. }
  27. public void setType(int type)
  28. {
  29. this.type = type;
  30. Color color = this.GetComponent<Renderer>().material.color;
  31. if(type == AStarNode.Type.Empty.GetHashCode())
  32. {
  33. color = Color.white;
  34. color.a = 0.5f;
  35. }
  36. else if(type == AStarNode.Type.Wall.GetHashCode())
  37. {
  38. color = Color.black;
  39. color.a = 0.5f;
  40. }
  41. else if(type == AStarNode.Type.BlueWall.GetHashCode())
  42. {
  43. color = TeamUtil.GetTeamColor(TeamUtil.Team.Blue.GetHashCode());
  44. color.a = 0.5f;
  45. }
  46. else if(type == AStarNode.Type.RedWall.GetHashCode())
  47. {
  48. color = TeamUtil.GetTeamColor(TeamUtil.Team.Red.GetHashCode());
  49. color.a = 0.5f;
  50. }
  51. else if(type == AStarNode.Type.YellowWall.GetHashCode())
  52. {
  53. color = TeamUtil.GetTeamColor(TeamUtil.Team.Yellow.GetHashCode());
  54. color.a = 0.5f;
  55. }
  56. this.GetComponent<Renderer>().material.color = color;
  57. }
  58. }