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 2.3 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 MessageOfStudent Student;
  11. private int rowCount = 50;
  12. private int colCount = 50;
  13. public GameObject wall;
  14. public GameObject grass;
  15. public GameObject land;
  16. public GameObject door;
  17. public GameObject window;
  18. public GameObject box;
  19. public GameObject book;
  20. public GameObject student_1;
  21. public GameObject student_2;
  22. public GameObject student_3;
  23. public GameObject student_4;
  24. public GameObject Monster_1;
  25. public GameObject Monster_2;
  26. public GameObject Monster_3;
  27. void Start()
  28. {
  29. mapFinished = false;
  30. }
  31. // Update is called once per frame
  32. void Update()
  33. {
  34. if (!mapFinished && MessageReceiver.map != null)
  35. {
  36. map = MessageReceiver.map;
  37. //Debug.Log("valid map");
  38. mapFinished = true;
  39. ShowMap(map);
  40. }
  41. }
  42. private void ShowMap(MessageOfMap map)
  43. {
  44. var position = new Vector3(-0.5f, 49.5f, 49.5f);
  45. var block = new GameObject();
  46. for (int i = 0; i < rowCount; i++)
  47. {
  48. for (int j = 0; j < colCount; j++)
  49. {
  50. position.x = position.x + 1;
  51. block = ShowBlock(map.Row[i].Col[j]);
  52. if (block != null)
  53. {
  54. Instantiate(block, position, new Quaternion(0, 0, 0, 0));
  55. }
  56. }
  57. position.x = -0.5f;
  58. position.z=position.y = position.y - 1.0f;
  59. }
  60. }
  61. private GameObject ShowBlock(PlaceType obj)
  62. {
  63. switch(obj)
  64. {
  65. case PlaceType.Land:return land;
  66. case PlaceType.Grass:return grass;
  67. case PlaceType.Wall:return wall;
  68. case PlaceType.Door3: return door;
  69. case PlaceType.Door5: return door;
  70. case PlaceType.Door6: return door;
  71. case PlaceType.Window: return window;
  72. case PlaceType.Chest:return box;
  73. case PlaceType.Classroom:return book;
  74. default:return land;
  75. }
  76. }
  77. }