|
- using System;
- using System.Collections;
- using UnityEngine;
-
- namespace SUISSEngine
- {
- public class WaterTiler : MonoBehaviour
- {
- private void Start()
- {
- if (this.tilesX < 1 || this.tilesY < 1)
- {
- throw new ArgumentException("Number of tiles must be at least 1", (this.tilesX >= 1) ? "tilesY" : "tilesX");
- }
- SpriteRenderer component = base.GetComponent<SpriteRenderer>();
- if (component == null)
- {
- throw new InvalidOperationException("Can't tile this game object because it has no SpriteRenderer.");
- }
- Sprite sprite = component.sprite;
- if (sprite == null)
- {
- throw new InvalidOperationException("Can't tile this game object because its SpriteRenderer has no sprite.");
- }
- GameObject gameObject = base.gameObject;
- string name = gameObject.name;
- int num = Array.IndexOf<Component>(base.GetComponents<Component>(), this);
- ArrayList arrayList = new ArrayList();
- Vector3 position = gameObject.transform.position;
- float num2 = 580f;
- if (this.reverseX)
- {
- num2 = -num2;
- }
- float num3 = 580f;
- if (this.reverseY)
- {
- num3 = -num3;
- }
- for (int i = 0; i < this.tilesY; i++)
- {
- for (int j = 0; j < this.tilesX; j++)
- {
- if (i != 0 || j != 0)
- {
- if (i >= j / 2)
- {
- 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);
- if (this.doNotCopyScripts)
- {
- foreach (MonoBehaviour obj in gameObject2.GetComponents<MonoBehaviour>())
- {
- UnityEngine.Object.Destroy(obj);
- }
- }
- else
- {
- UnityEngine.Object.Destroy(gameObject2.GetComponents<Component>()[num]);
- }
- gameObject2.name = string.Concat(new object[]
- {
- name,
- " (",
- j,
- ", ",
- i,
- ")"
- });
- arrayList.Add(gameObject2);
- }
- }
- }
- }
- IEnumerator enumerator = arrayList.GetEnumerator();
- try
- {
- while (enumerator.MoveNext())
- {
- object obj2 = enumerator.Current;
- GameObject gameObject3 = (GameObject)obj2;
- gameObject3.transform.parent = gameObject.transform;
- }
- }
- finally
- {
- IDisposable disposable;
- if ((disposable = (enumerator as IDisposable)) != null)
- {
- disposable.Dispose();
- }
- }
- }
-
- public int tilesX = 1;
-
- public int tilesY = 1;
-
- public bool reverseX;
-
- public bool reverseY;
-
- public bool doNotCopyScripts = true;
- }
- }
|