You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MapManager.cs 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using Protobuf;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. public class MapManager : MonoBehaviour
  6. {
  7. // Start is called before the first frame update
  8. private bool mapFinished;
  9. private MessageOfMap map;
  10. private int rowCount = 50;
  11. private int colCount = 50;
  12. public GameObject wall;
  13. public GameObject grass;
  14. public GameObject land;
  15. public GameObject door;
  16. public GameObject window;
  17. void Start()
  18. {
  19. mapFinished = false;
  20. }
  21. // Update is called once per frame
  22. void Update()
  23. {
  24. if (!mapFinished && MessageReceiver.map != null)
  25. {
  26. map = MessageReceiver.map;
  27. Debug.Log("valid map");
  28. //Debug.Log("valid map");
  29. mapFinished = true;
  30. ShowMap(map);
  31. }
  32. }
  33. private void ShowMap(MessageOfMap map)
  34. {
  35. var position = new Vector3(-24.5f, 12.25f, 12.25f);
  36. var block = new GameObject();
  37. for (int i = 0; i < rowCount; i++)
  38. {
  39. for (int j = 0; j < colCount; j++)
  40. {
  41. position.x = position.x + 1;
  42. block = ShowBlock(map.Row[i].Col[j]);
  43. if (block != null)
  44. {
  45. Instantiate(block, position, new Quaternion(0, 0, 0, 0));
  46. }
  47. }
  48. position.x = -24.5f;
  49. position.z=position.y = position.y - 0.5f;
  50. }
  51. }
  52. private GameObject ShowBlock(PlaceType obj)
  53. {
  54. switch(obj)
  55. {
  56. case PlaceType.Land:return land;
  57. case PlaceType.Grass:return grass;
  58. case PlaceType.Wall:return wall;
  59. case PlaceType.Door3: return door;
  60. case PlaceType.Door5: return door;
  61. case PlaceType.Door6: return door;
  62. case PlaceType.Window: return window;
  63. default:return null;
  64. }
  65. }
  66. }