Map.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System;
  5. using UnityEngine.UI;
  6. namespace YLBattle
  7. {
  8. public class Map : MonoBehaviour
  9. {
  10. static private Map mInstance;
  11. /// 地图数据
  12. /// </summary>
  13. public MapData mapData;
  14. /// <summary>
  15. /// 地图ID
  16. /// </summary>
  17. public int mapId;
  18. /// <summary>
  19. /// 地图文件
  20. /// </summary>
  21. public string mapFile;
  22. /// <summary>
  23. /// 单例
  24. /// </summary>
  25. /// <value>The instance.</value>
  26. static public Map Instance
  27. {
  28. set
  29. {
  30. mInstance = value;
  31. }
  32. get
  33. {
  34. return mInstance;
  35. }
  36. }
  37. void Awake()
  38. {
  39. mInstance = this;
  40. mapId = 1;
  41. }
  42. // Use this for initialization
  43. void Start()
  44. {
  45. this.transform.parent.Rotate (0, 0, 0);
  46. mapFile = "";
  47. }
  48. public void InitData(ref MapData data)
  49. {
  50. // 创建孵化点
  51. foreach (ZoneSpawner spawn in data.spawnUnitList)
  52. {
  53. GameObject spawnObj = new GameObject();
  54. SpawnPoint spawnCmpt = spawnObj.AddComponent<SpawnPoint>();
  55. spawnObj.name = "SpawnPoint";
  56. spawnCmpt.Init(spawn);
  57. spawnCmpt.transform.parent = this.transform.parent;
  58. }
  59. }
  60. private void Update()
  61. {
  62. }
  63. public void AddSpawnPoint(ZoneSpawner sp)
  64. {
  65. this.mapData.spawnUnitList.Add(sp);
  66. }
  67. public void RemoveSpawner(ZoneSpawner sp)
  68. {
  69. }
  70. public void PlaceSelectBuild()
  71. {
  72. }
  73. public void PlaceSelectGroup()
  74. {
  75. }
  76. public void PlaceSelectRole()
  77. {
  78. }
  79. public void PlaceUnitEventHandle()
  80. {
  81. }
  82. void OnMouseDown()
  83. {
  84. }
  85. public void AddUnitSpawner(ZoneSpawner sp)
  86. {
  87. this.mapData.spawnUnitList.Add(sp);
  88. }
  89. public void RemoveUnitSpawner(ZoneSpawner sp)
  90. {
  91. this.mapData.spawnUnitList.Remove(sp);
  92. }
  93. public void SpawnerSave()
  94. {
  95. }
  96. public void Export()
  97. {
  98. MapParse.ExportMapData(this.mapData);
  99. }
  100. public void Import(string fileName)
  101. {
  102. this.mapFile = fileName;
  103. this.mapData = MapParse.ImportMapFile(fileName);
  104. this.mapData.MapDataCreate();
  105. this.InitData(ref this.mapData);
  106. }
  107. }
  108. }