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 SpawnPrefabsIn3DMesh(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);
        }