summaryrefslogtreecommitdiff
path: root/GameCode/Populate.cs
blob: b59ce5972ac72bbf111ba1b920f19a32a271a9fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System.Collections.Generic;
using UnityEngine;

public class Populate : MonoBehaviour
{
	public GameObject target;

	public bool setTargetsActive;

	public bool includeTargetInList = true;

	public int times = 5;

	public List<GameObject> DoPopulate()
	{
		List<GameObject> list = new List<GameObject>();
		if (includeTargetInList)
		{
			list.Add(target);
		}
		for (int i = 0; i < times; i++)
		{
			GameObject gameObject = Object.Instantiate(target, target.transform.position, base.transform.transform.rotation, base.transform);
			gameObject.transform.localScale = target.transform.localScale;
			list.Add(gameObject);
			if (setTargetsActive)
			{
				gameObject.SetActive(value: true);
			}
		}
		return list;
	}

	public List<T> DoPopulate<T>(bool addComponentIfMissing = true) where T : MonoBehaviour
	{
		List<T> list = new List<T>();
		if (includeTargetInList && target != null)
		{
			T val = target.GetComponent<T>();
			if ((Object)val == (Object)null && addComponentIfMissing)
			{
				val = target.AddComponent<T>();
			}
			if (!((Object)val != (Object)null))
			{
				Debug.LogError("Could not find component");
				return null;
			}
			list.Add(val);
		}
		for (int i = 0; i < times; i++)
		{
			GameObject gameObject = Object.Instantiate(target, target.transform.position, base.transform.transform.rotation, target.transform.transform.parent);
			gameObject.transform.localScale = target.transform.localScale;
			T val2 = gameObject.GetComponent<T>();
			if ((Object)val2 == (Object)null && addComponentIfMissing)
			{
				val2 = gameObject.AddComponent<T>();
			}
			if ((Object)val2 != (Object)null)
			{
				list.Add(val2);
			}
			if (setTargetsActive)
			{
				gameObject.SetActive(value: true);
			}
		}
		return list;
	}
}