CreateWalls.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using static XunJianDataManager;
  5. public class CreateWalls : MonoBehaviour
  6. {
  7. public GameObject Wall;
  8. public List<Wall> listWall;
  9. private void Start()
  10. {
  11. this.listWall = getWallData();
  12. CreateWall(listWall);
  13. }
  14. List<Wall> getWallData()
  15. {
  16. List<Wall> listWall = new List<Wall>();
  17. for (int i = 0; i < 6; i++)
  18. {
  19. switch (i)
  20. {
  21. case 0:
  22. Wall wall = new Wall();
  23. wall.listPoint.Add(new Vector3(-5, 0, 0.25f));
  24. wall.listPoint.Add(new Vector3(5, 0, 0.25f));
  25. wall.listPoint.Add(new Vector3(5, 0, -0.25f));
  26. wall.listPoint.Add(new Vector3(-5, 0, -0.25f));
  27. listWall.Add(wall);
  28. break;
  29. case 1:
  30. Wall wall1 = new Wall();
  31. wall1.listPoint.Add(new Vector3(-5, 0, -4.75f));
  32. wall1.listPoint.Add(new Vector3(5, 0, -4.75f));
  33. wall1.listPoint.Add(new Vector3(5, 0, -5.25f));
  34. wall1.listPoint.Add(new Vector3(-5, 0, -5.25f));
  35. listWall.Add(wall1);
  36. break;
  37. case 2:
  38. Wall wall2 = new Wall();
  39. wall2.listPoint.Add(new Vector3(-5.25f, 0, 0));
  40. wall2.listPoint.Add(new Vector3(-4.75f, 0, 0));
  41. wall2.listPoint.Add(new Vector3(-4.75f, 0, -5));
  42. wall2.listPoint.Add(new Vector3(-5.25f, 0, -5));
  43. listWall.Add(wall2);
  44. break;
  45. case 3:
  46. Wall wall3 = new Wall();
  47. wall3.listPoint.Add(new Vector3(4.75f, 0, 0));
  48. wall3.listPoint.Add(new Vector3(5.25f, 0, 0));
  49. wall3.listPoint.Add(new Vector3(5.25f, 0, -5));
  50. wall3.listPoint.Add(new Vector3(4.75f, 0, -5));
  51. listWall.Add(wall3);
  52. break;
  53. case 4:
  54. Wall wall4 = new Wall();
  55. wall4.listPoint.Add(new Vector3(-2.75f, 0, -1f));
  56. wall4.listPoint.Add(new Vector3(-2.25f, 0, -1f));
  57. wall4.listPoint.Add(new Vector3(-2.25f, 0, -3f));
  58. wall4.listPoint.Add(new Vector3(-2.75f, 0, -3f));
  59. listWall.Add(wall4);
  60. break;
  61. case 5:
  62. Wall wall5 = new Wall();
  63. wall5.listPoint.Add(new Vector3(2.25f, 0, -2));
  64. wall5.listPoint.Add(new Vector3(2.75f, 0, -2));
  65. wall5.listPoint.Add(new Vector3(2.75f, 0, -4));
  66. wall5.listPoint.Add(new Vector3(2.25f, 0, -4));
  67. listWall.Add(wall5);
  68. break;
  69. default:
  70. break;
  71. }
  72. }
  73. return listWall;
  74. }
  75. public void CreateWall( List<Wall> listWall)
  76. {
  77. for (int i = 0; i < listWall.Count; i++)
  78. {
  79. Transform wallObj = GameObject.Instantiate(Wall).transform;
  80. wallObj.position = listWall[i].listPoint[0];
  81. float x = Vector3.Distance(listWall[i].listPoint[0], listWall[i].listPoint[1]);
  82. float y = Vector3.Distance(listWall[i].listPoint[0], listWall[i].listPoint[3]);
  83. wallObj.localScale = new Vector3(x, 3, y);
  84. }
  85. }
  86. }