-
Notifications
You must be signed in to change notification settings - Fork 0
/
script_City.cs
141 lines (116 loc) · 3.39 KB
/
script_City.cs
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class script_City : MonoBehaviour {
// Use this for initialization
public List<GameObject> connections = new List<GameObject>();
public List<GameObject> cityList = new List<GameObject>();
private script_City otherCityScript;
public float myMinZ;
public float myMinX;
public float myMaxZ;
public float myMaxX;
public List<float> cityMinZ = new List<float>();
public List<float> cityMinX = new List<float>();
public List<float> cityMaxZ = new List<float>();
public List<float> cityMaxX = new List<float>();
public GameObject influenceObj;
public Collider influenceCollider;
public GameObject[] buildings;
public int buildingType;
public script_GameManager gameManager;
public Texture icon;
void Awake () {
if (this.transform.FindChild("prefab_Influence"))
{
influenceObj = this.transform.FindChild("prefab_Influence").gameObject;
}
else
{
Transform parentObj = this.gameObject.transform.parent;
influenceObj = parentObj.transform.FindChild("prefab_Influence").gameObject;
}
influenceCollider = influenceObj.GetComponent<SphereCollider>();
myMinZ = influenceCollider.bounds.min.z;
myMinX = influenceCollider.bounds.min.x;
myMaxZ = influenceCollider.bounds.max.z;
myMaxX = influenceCollider.bounds.max.x;
cityMinX.Add(myMinX);
cityMinZ.Add(myMinZ);
cityMaxX.Add(myMaxX);
cityMaxZ.Add(myMaxZ);
Debug.Log("This Object: " + this.gameObject.name + " MinX = " + myMinX);
}
// Update is called once per frame
void Update () {
}
public void FindBuildings () {
buildings = GameObject.FindGameObjectsWithTag("Building");
foreach (GameObject building in buildings)
{
//Update our Local Connections
if (!connections.Contains(building.gameObject))
{
connections.Add(building.gameObject);
}
//Add all buildings to City List
if (!cityList.Contains(building.gameObject))
{
cityList.Add(building.gameObject);
}
//Get the other Object's script and add it's city list as well
if (building.gameObject.GetComponent<script_City>() != null)
{
otherCityScript = building.gameObject.GetComponent<script_City>();
}
else
{
otherCityScript = building.gameObject.GetComponentInChildren<script_City>();
}
foreach (GameObject otherObj in otherCityScript.cityList)
{
if (!cityList.Contains(otherObj))
{
cityList.Add(otherObj);
}
//Add all of the other building's Min X Values
foreach (float minX in otherCityScript.cityMinX)
{
if (!cityMinX.Contains(minX))
{
cityMinX.Add(minX);
cityMinX.Sort();
Debug.Log("City X Min Bounds: " + cityMinX[0]);
}
}
//Add all of the other building's Max X Values
foreach (float maxX in otherCityScript.cityMaxX)
{
if (!cityMaxX.Contains(maxX))
{
cityMaxX.Add(maxX);
cityMaxX.Sort();
}
}
//Add all of the other building's Min Z Values
foreach (float minZ in otherCityScript.cityMinZ)
{
if (!cityMinZ.Contains(minZ))
{
cityMinZ.Add(minZ);
cityMinZ.Sort();
}
}
//Add all of the other building's Max Z Values
foreach (float maxZ in otherCityScript.cityMaxZ)
{
if (!cityMaxZ.Contains(maxZ))
{
cityMaxZ.Add(maxZ);
cityMaxZ.Sort();
}
}
}
}
}
}