您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

90 行
2.3 KiB

  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace SUISSEngine
  5. {
  6. public class BeachTiler : MonoBehaviour
  7. {
  8. private void Start()
  9. {
  10. if (this.tilesX < 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. for (int i = 0; i < this.tilesX; i++)
  35. {
  36. if (i != 0)
  37. {
  38. GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject, new Vector3(position.x + num2 * (float)i, position.y - (float)(290 * i), position.z), Quaternion.identity);
  39. if (this.doNotCopyScripts)
  40. {
  41. foreach (MonoBehaviour obj in gameObject2.GetComponents<MonoBehaviour>())
  42. {
  43. UnityEngine.Object.Destroy(obj);
  44. }
  45. }
  46. else
  47. {
  48. UnityEngine.Object.Destroy(gameObject2.GetComponents<Component>()[num]);
  49. }
  50. gameObject2.name = string.Concat(new object[]
  51. {
  52. name,
  53. " (",
  54. i,
  55. ")"
  56. });
  57. arrayList.Add(gameObject2);
  58. }
  59. }
  60. IEnumerator enumerator = arrayList.GetEnumerator();
  61. try
  62. {
  63. while (enumerator.MoveNext())
  64. {
  65. object obj2 = enumerator.Current;
  66. GameObject gameObject3 = (GameObject)obj2;
  67. gameObject3.transform.parent = gameObject.transform;
  68. }
  69. }
  70. finally
  71. {
  72. IDisposable disposable;
  73. if ((disposable = (enumerator as IDisposable)) != null)
  74. {
  75. disposable.Dispose();
  76. }
  77. }
  78. }
  79. public int tilesX = 1;
  80. public bool reverseX;
  81. public bool reverseY;
  82. public bool doNotCopyScripts = true;
  83. }
  84. }