25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

105 lines
2.6 KiB

  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace SUISSEngine
  5. {
  6. public class WaterTiler : MonoBehaviour
  7. {
  8. private void Start()
  9. {
  10. if (this.tilesX < 1 || this.tilesY < 1)
  11. {
  12. throw new ArgumentException("Number of tiles must be at least 1", (this.tilesX >= 1) ? "tilesY" : "tilesX");
  13. }
  14. SpriteRenderer component = base.GetComponent<SpriteRenderer>();
  15. if (component == null)
  16. {
  17. throw new InvalidOperationException("Can't tile this game object because it has no SpriteRenderer.");
  18. }
  19. Sprite sprite = component.sprite;
  20. if (sprite == null)
  21. {
  22. throw new InvalidOperationException("Can't tile this game object because its SpriteRenderer has no sprite.");
  23. }
  24. GameObject gameObject = base.gameObject;
  25. string name = gameObject.name;
  26. int num = Array.IndexOf<Component>(base.GetComponents<Component>(), this);
  27. ArrayList arrayList = new ArrayList();
  28. Vector3 position = gameObject.transform.position;
  29. float num2 = 580f;
  30. if (this.reverseX)
  31. {
  32. num2 = -num2;
  33. }
  34. float num3 = 580f;
  35. if (this.reverseY)
  36. {
  37. num3 = -num3;
  38. }
  39. for (int i = 0; i < this.tilesY; i++)
  40. {
  41. for (int j = 0; j < this.tilesX; j++)
  42. {
  43. if (i != 0 || j != 0)
  44. {
  45. if (i >= j / 2)
  46. {
  47. GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject, new Vector3(position.x + (float)j * num2, position.y + (float)i * num3 - (float)(279 * j), position.z), Quaternion.identity);
  48. if (this.doNotCopyScripts)
  49. {
  50. foreach (MonoBehaviour obj in gameObject2.GetComponents<MonoBehaviour>())
  51. {
  52. UnityEngine.Object.Destroy(obj);
  53. }
  54. }
  55. else
  56. {
  57. UnityEngine.Object.Destroy(gameObject2.GetComponents<Component>()[num]);
  58. }
  59. gameObject2.name = string.Concat(new object[]
  60. {
  61. name,
  62. " (",
  63. j,
  64. ", ",
  65. i,
  66. ")"
  67. });
  68. arrayList.Add(gameObject2);
  69. }
  70. }
  71. }
  72. }
  73. IEnumerator enumerator = arrayList.GetEnumerator();
  74. try
  75. {
  76. while (enumerator.MoveNext())
  77. {
  78. object obj2 = enumerator.Current;
  79. GameObject gameObject3 = (GameObject)obj2;
  80. gameObject3.transform.parent = gameObject.transform;
  81. }
  82. }
  83. finally
  84. {
  85. IDisposable disposable;
  86. if ((disposable = (enumerator as IDisposable)) != null)
  87. {
  88. disposable.Dispose();
  89. }
  90. }
  91. }
  92. public int tilesX = 1;
  93. public int tilesY = 1;
  94. public bool reverseX;
  95. public bool reverseY;
  96. public bool doNotCopyScripts = true;
  97. }
  98. }