Esempio n. 1
0
        public IEnumerator SpawnPrefabsInMesh(GOFeature feature, GameObject parent, GOEnvironmentKind kind)
        {
            if (feature.preloadedMeshData == null)
            {
                yield break;
            }

            float area = Area(feature.convertedGeometry);
            float rate = kind.density / 1000.0f;
            int   k    = Mathf.FloorToInt(area * rate / 100);

            //Debug.Log (area + " " + rate + " " + k);

            for (int i = 0; i < k; i++)
            {
                try {
//					int spawn = UnityEngine.Random.Range (0, rate);
//					if (spawn != 0)
//						continue;

                    int     n   = UnityEngine.Random.Range(0, kind.prefabs.Length);
                    Vector3 pos = randomPointInShape(feature.convertedGeometry);

                    if (GOMap.IsPointAboveWater(pos))
                    {
                        continue;
                    }

                    pos.y += kind.prefabs [n].transform.position.y;


                    var rotation       = kind.prefabs [n].transform.eulerAngles;
                    var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0);

                    GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation));
                    obj.transform.parent = parent.transform;
                } catch {
                }

                if (Application.isPlaying)
                {
                    yield return(null);
                }
            }

            yield return(null);
        }
Esempio n. 2
0
        public IEnumerator SpawnPrefabsInMesh(GOFeature feature, GameObject parent, GOEnvironmentKind kind)
        {
            if (feature.preloadedMeshData == null)
            {
                yield break;
            }

            int rate = 100 / kind.density;

            foreach (Vector3 vertex in feature.preloadedMeshData.vertices)
            {
                try {
                    int spawn = UnityEngine.Random.Range(0, rate);
                    if (spawn != 0)
                    {
                        continue;
                    }

                    int     n   = UnityEngine.Random.Range(0, kind.prefabs.Length);
                    Vector3 pos = vertex;

                    if (GOMap.IsPointAboveWater(pos))
                    {
                        continue;
                    }

                    pos.y += kind.prefabs [n].transform.position.y;


                    var rotation       = kind.prefabs [n].transform.eulerAngles;
                    var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0);

                    GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation));
                    obj.transform.parent = parent.transform;
                } catch {
                }

                if (Application.isPlaying)
                {
                    yield return(null);
                }
            }

            yield return(null);
        }
        public IEnumerator SpawnBuildings(GOFeature feature, GameObject parent, GOEnvironmentKind kind)
        {
            if (feature.preloadedMeshData == null)
            {
                yield break;
            }


            int rate = 100 / (kind.density + 1);

//			foreach (Vector3 vertex in feature.preloadedMeshData.vertices) {
//
//				try {
            int spawn = UnityEngine.Random.Range(0, rate);

            if (spawn != 0)
            {
                yield break;
            }

            int n = UnityEngine.Random.Range(0, kind.prefabs.Length);

            Vector3 pos = feature.featureCenter;

            pos.y += kind.prefabs [n].transform.position.y;

            var rotation       = kind.prefabs [n].transform.eulerAngles;
            var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0);

            GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation));

            obj.transform.parent = parent.transform;

//				} catch {
//				}

            if (Application.isPlaying)
            {
                yield return(null);
            }
//			}

            yield return(null);
        }
Esempio n. 4
0
        public IEnumerator SpawnPrefabsInTile(GOTile tile, GameObject parent, GOEnvironmentKind kind)
        {
            if (tile == null)
            {
                yield break;
            }

            float rate = Mathf.FloorToInt(tile.goTile.diagonalLenght * (kind.density / 100));


            for (int i = 0; i <= rate; i++)
            {
                float randomX = UnityEngine.Random.Range(tile.goTile.getXRange().x, tile.goTile.getXRange().y);
                float randomZ = UnityEngine.Random.Range(tile.goTile.getZRange().x, tile.goTile.getZRange().y);
                float randomY = UnityEngine.Random.Range(200, 320);

                int     n   = UnityEngine.Random.Range(0, kind.prefabs.Length);
                Vector3 pos = new Vector3(randomX, randomY, randomZ);

                pos.y += kind.prefabs [n].transform.position.y;

                pos.y += GOMap.AltitudeForPoint(pos);

                var rotation       = kind.prefabs [n].transform.eulerAngles;
                var randomRotation = new Vector3(0, UnityEngine.Random.Range(0, 360), 0);

                GameObject obj = (GameObject)GameObject.Instantiate(kind.prefabs[n], pos, Quaternion.Euler(rotation + randomRotation));
                obj.transform.parent   = parent.transform;
                obj.transform.position = pos;
                if (Application.isPlaying)
                {
                    yield return(null);
                }
            }

            yield return(null);
        }