-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreatePrefabsInCircle.cs
More file actions
123 lines (94 loc) · 2.79 KB
/
CreatePrefabsInCircle.cs
File metadata and controls
123 lines (94 loc) · 2.79 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using UnityEngine;
using System.Collections;
using ScriptUtilities;
using System.Collections.Generic;
public class CreatePrefabsInCircle : MonoBehaviour
{
// Use this for initialization
public int numberOfObjects;
public float radius;
public GameObject prefab;
public bool drawLines;
public bool spawnObjects;
public int circleIndex;
public List<PrefabGroup> circleList = new List<PrefabGroup> (1);
private RecursiveScaleChange rsc;
void Start ()
{
if (GetComponent<RecursiveScaleChange> () != null) {
rsc = GetComponent<RecursiveScaleChange> () as RecursiveScaleChange;
}
//SpawnObjects (numberOfObjects, radius, prefab);
NotificationCenter.DefaultCenter.AddObserver (this, "CityDone");
}
public void CityDone ()
{
StartCoroutine ("CoSpawnObjects");
}
private IEnumerator CoSpawnObjects ()
{
if (spawnObjects) {
foreach (PrefabGroup pg in circleList) {
foreach (Vector3 p in pg.GetPosList()) {
GameObject treeCluster = null;
treeCluster = (GameObject)Instantiate (pg.GetPrefab (), p, Quaternion.identity);
treeCluster.transform.parent = transform;
yield return new WaitForSeconds (0.0f);
}
}
rsc.Go ();
}
NotificationCenter.DefaultCenter.PostNotification (this, "ScanAStarGrid");
yield return null;
}
void OnDrawGizmos ()
{
foreach (PrefabGroup pg in circleList) {
Vector3 lastPos = pg.objectPositions [pg.objectPositions.Count - 1];
foreach (Vector3 p in pg.objectPositions) {
Gizmos.color = Color.white;
Gizmos.DrawLine (lastPos, p);
Gizmos.color = Color.black;
Gizmos.DrawWireSphere (p, 1);
lastPos = p;
}
}
DrawDummyCircle ();
}
void DrawDummyCircle ()
{
List<Vector3> dummyCircle = CircleUtils.CalculatePointsOnCircle (numberOfObjects, radius, transform.position);
Vector3 lastPos = dummyCircle [dummyCircle.Count - 1];
foreach (Vector3 p in dummyCircle) {
Gizmos.color = Color.magenta;
Gizmos.DrawLine (lastPos, p);
Gizmos.color = Color.white;
Gizmos.DrawWireSphere (p, 1);
lastPos = p;
}
}
public void AddCircle ()
{
Debug.Log ("adding a circle");
circleList.Add (new PrefabGroup (numberOfObjects, radius, transform.position, prefab));
}
[System.Serializable]
public class PrefabGroup
{
public List<Vector3> objectPositions;
public GameObject objectPrefab;
public PrefabGroup (int n, float r, Vector3 pos, GameObject go)
{
objectPositions = CircleUtils.CalculatePointsOnCircle (n, r, pos);
objectPrefab = go;
}
public List<Vector3> GetPosList ()
{
return objectPositions;
}
public GameObject GetPrefab ()
{
return objectPrefab;
}
}
}