MapItem.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class MapItem : MapObject
  5. {
  6. public const int BIGGER = 1;
  7. public Texture[] textureArr;
  8. public int id;
  9. private List<int> tileIndexs;
  10. public override void Init (Map map)
  11. {
  12. base.Init (map);
  13. tileIndexs = new List<int>();
  14. }
  15. // public override TeamUtil.Team team {
  16. // get {
  17. // return base.team;
  18. // }
  19. // set {
  20. // base.team = value;
  21. // int index = value.GetHashCode() - 1;
  22. // Renderer[] renderers = this.GetComponentsInChildren<Renderer>();
  23. // for(int i=0; i<renderers.Length; i++)
  24. // {
  25. // renderers[i].material.mainTexture = textureArr[index];
  26. // }
  27. // }
  28. // }
  29. public void SetPosition(Vector3 pos)
  30. {
  31. this.transform.position = pos;
  32. }
  33. public List<int> GetTileIndexs()
  34. {
  35. return tileIndexs;
  36. }
  37. public void TakeTiles()
  38. {
  39. int col = Map.XToColumn(position.x);
  40. int row = Map.ZToRow(position.z);
  41. CleanTiles();
  42. AddTile(col, row);
  43. AddTile(col-1, row);
  44. AddTile(col, row-1);
  45. AddTile(col+1, row);
  46. AddTile(col, row+1);
  47. AddTile(col+1, row+1);
  48. AddTile(col+1, row-1);
  49. AddTile(col-1, row+1);
  50. AddTile(col-1, row-1);
  51. }
  52. private void AddTile(int col, int row)
  53. {
  54. int index = map.GetIndexByGrid(col, row);
  55. tileIndexs.Add(index);
  56. map.MapItemPlace(index, this);
  57. }
  58. protected void CleanTiles()
  59. {
  60. map.MapItemClean(this);
  61. tileIndexs.Clear();
  62. }
  63. public override void Remove ()
  64. {
  65. CleanTiles();
  66. map.RemoveMapItem(this);
  67. Destroy(this.gameObject);
  68. }
  69. }