public void AddBamboo(BambooGroup _bambooGroup) { bambooGroup = _bambooGroup; SetShowerHeadReady(); }
IEnumerator CreateBamboo() { // spawn markers yield return(new WaitForEndOfFrame()); GameObject bambooMarker1 = Instantiate(bambooMarkersPrefabs[0], transform.position, transform.rotation) as GameObject; yield return(new WaitForEndOfFrame()); GameObject bambooMarker2 = Instantiate(bambooMarkersPrefabs[1], transform.position, transform.rotation) as GameObject; yield return(new WaitForEndOfFrame()); GameObject bambooMarker3 = Instantiate(bambooMarkersPrefabs[2], transform.position, transform.rotation) as GameObject; bambooGroupMarkers = new GameObject[3]; bambooGroupMarkers[0] = bambooMarker1.transform.Find("BAMBOO_01").gameObject; bambooGroupMarkers[1] = bambooMarker2.transform.Find("BAMBOO_02").gameObject; bambooGroupMarkers[2] = bambooMarker3.transform.Find("BAMBOO_03").gameObject; List <BambooInfo> bambooList = new List <BambooInfo>(); for (int groupIndex = 0; groupIndex < bambooGroupMarkers.Length; groupIndex++) { Transform groupObj = transform.Find("Group" + (groupIndex + 1)); BambooGroup bambooGroup = groupObj.GetComponent <BambooGroup>(); bambooGroups[groupIndex] = bambooGroup; bambooGroups[groupIndex].AddShowerHead(showerHeads[groupIndex].GetComponent <ShowerHead>()); bambooGroups[groupIndex].AddPlants(control.GetPlantGroup(groupIndex)); bambooGroups[groupIndex].AddLeafFadeCurve(leafFade); GameObject groupMarker = bambooGroupMarkers[groupIndex]; destroyAfterSpawn.Add(groupMarker.transform.parent.gameObject); foreach (Transform stalk in groupMarker.transform) { yield return(new WaitForSeconds(0.05f)); int selector = groupIndex; GameObject prefab = bambooPrefabs[selector]; GameObject bambooStalk = Instantiate(prefab, stalk.position, stalk.rotation) as GameObject; float height = Random.Range(plantHeightRange.x, plantHeightRange.y); bambooStalk.transform.localScale = new Vector3(1, height, 1); bambooStalk.transform.SetParent(groupObj); BambooInfo info = new BambooInfo( bambooStalk.transform, Random.Range(stalkFrequencyRange.x, stalkFrequencyRange.y), Random.Range(stalkAmplitudeRange.x, stalkAmplitudeRange.y), bambooStalk.transform.localRotation ); bambooList.Add(info); bambooStands[groupIndex].Add(info); foreach (Transform stem in bambooStalk.transform) { for (int i = 0; i < showerHeads.Length; i++) { Vector2 stemPos = new Vector2(stem.position.x, stem.position.z); Vector2 showerPos = new Vector2(showerHeads[i].position.x, showerHeads[i].position.z); float distance = Vector2.Distance(stemPos, showerPos); float maxDistance = 1.0f; if (distance < maxDistance && stem.position.y < (showerHeads[i].position.y - 0.25f)) { float scale = 1 - (distance / maxDistance); float invert = Random.value > 0.5f ? -1 : 1; BambooInfo stemInfo = new BambooInfo( stem, Random.Range(stemFrequencyRange.x, stemFrequencyRange.y) * scale * invert, Random.Range(stemAmplitudeRange.x, stemAmplitudeRange.y) * scale * invert, stem.localRotation ); stemsGroups[i].Add(stemInfo); } } } } } allBamboo = bambooList.ToArray(); foreach (GameObject killme in destroyAfterSpawn) { Destroy(killme); } bambooReady = true; control.Init(); }