private List <PetalLocalData> DistributePetalLocalData(FlowerLocalData flower, PetalData petalData) { List <PetalLocalData> dataList = new List <PetalLocalData>(); int PetalLayerCount = flower.PetalLayerCount; int[] PetalCounts = flower.PetalCounts; float PetalMinClosedTime = petalData.MinClosedTime; float PetalMaxClosedTime = petalData.MaxClosedTime; float PetalMinOpenTime = petalData.MinOpenTime; float PetalMaxOpenTime = petalData.MaxOpenTime; float PetalRandomTimeValue = petalData.RandomTimeValue; for (int i = 0; i < flower.PetalLayerCount; i++) { float petalLayerClosedTime = (PetalMaxClosedTime - PetalMinClosedTime) / PetalLayerCount * i + PetalMinClosedTime; float petalLayerOpenTime = (PetalMaxOpenTime - PetalMinOpenTime) / PetalLayerCount * i + PetalMinOpenTime; for (int j = 0; j < flower.PetalCounts[i]; j++) { PetalLocalData petalLocalData = new PetalLocalData(); float RandomValue = Util.RandomRange(PetalRandomTimeValue); petalLocalData.Rotation = (360 / PetalCounts[i] * j) + i * 30; petalLocalData.PetalLayer = i; petalLocalData.PetalIndex = j; petalLocalData.StartTime = petalLayerClosedTime + RandomValue; petalLocalData.EndTime = petalLayerOpenTime + RandomValue; petalLocalData.Color = flower.PetalColor; dataList.Add(petalLocalData); } } return(dataList); }
private void InitFlowerChildren(GameObject flowerObject, FlowerLocalData flowerData, List <PetalLocalData> petalDatas) { flowerObject.AddComponent <FlowerLocalData>(); flowerData = flowerObject.GetComponent <FlowerLocalData>().AssignValues(flowerData); GameObject Pistil = Util.InitWithParent(PistilPrefab, flowerObject.transform); GameObject Petals = Util.InitWithParent("Petals", flowerObject.transform); List <GameObject> tempPetalLayers = new List <GameObject>(); for (int i = 0; i < flowerData.PetalLayerCount; ++i) { GameObject petalLayer = Util.InitWithParent("PetalLayer" + i, Petals.transform); tempPetalLayers.Add(petalLayer); } for (int i = 0; i < petalDatas.Count; ++i) { GameObject petal = Util.InitWithParent(PetalPrefab, tempPetalLayers[petalDatas[i].PetalLayer].transform); petal.AddComponent <PetalLocalData>(); PetalLocalData petalData = petal.GetComponent <PetalLocalData>().AssignValues(petalDatas[i]); petal.transform.Rotate(new Vector3(0, petalData.Rotation, 0)); petal.GetComponent <Animator>().SetFloat("Time", petalData.StartTime); petal.transform.Find("Plane").GetComponent <SkinnedMeshRenderer>().material.color = petalData.Color; PetalsList.Add(petal); } UpdateTransformOnSpline(flowerObject, CurrentMainSpline, 1f, 0f, 0f); flowerObject.SetActive(false); }
public FlowerLocalData(FlowerLocalData data) { FlowerIndex = data.FlowerIndex; TotalPetalCount = data.TotalPetalCount; PetalLayerCount = data.PetalLayerCount; PetalFallPercentage = data.PetalFallPercentage; PetalColor = data.PetalColor; PetalCounts = data.PetalCounts; }
public FlowerLocalData AssignValues(FlowerLocalData data) { FlowerIndex = data.FlowerIndex; TotalPetalCount = data.TotalPetalCount; PetalLayerCount = data.PetalLayerCount; PetalFallPercentage = data.PetalFallPercentage; PetalColor = data.PetalColor; PetalCounts = data.PetalCounts; return(this); }
private FlowerLocalData DistributeFlowerLocalData(PetalData petalData, ColorData colorData) { FlowerLocalData data = new FlowerLocalData(); Vector2Int petalLayerCountRange = petalData.PetalLayerCountRange; Vector2Int petalCountRange = petalData.PetalCountRange; int tempPetalLayerCount = UnityEngine.Random.Range(petalLayerCountRange.x, petalLayerCountRange.y + 1); data.PetalLayerCount = tempPetalLayerCount; data.PetalCounts = Util.DistributeRandomIntArray(tempPetalLayerCount, petalCountRange); data.TotalPetalCount = Util.SumArray(data.PetalCounts); data.PetalFallPercentage = petalData.FallPercentage; data.PetalColor = !colorData.isRandom ? colorData.Color : Util.GetColorFromRange(colorData.ColorRange1, colorData.ColorRange2); return(data); }
public PlantLocalData(PlantFormData data) { InitialTime = DateTime.Now; PlantName = data.plantName; Description = data.description; Rotation = Util.RandomRange(-150f, -30f); PlantFormType = data.plantFormType; FlowerFormType = data.flowerFormType; PetalPrefab = data.PetalPrefab; PistilPrefab = data.PistilPrefab; BudPrefab = data.BudPrefab; LeafPrefab = data.LeafPrefab; SproutParticles = data.SproutParticles; CurrentAnimationState = FlowerAnimationState.Sprout; LastStateChangedTime = InitialTime; AnimationDurationList = new List <float>() { data.SproutAnimationDuration, data.GrowAniamtionDuration, data.BloomAnimationDuration, data.FallAnimationDuration, data.RebloomAnimationDuration }; AnimationCycleTime = data.BloomAnimationDuration + data.FallAnimationDuration + data.RebloomAnimationDuration; MainStem = DistributeMainStemLocalData(data.SproutPathData, data.StemPathData, data.StemColorData); Flower = DistributeFlowerLocalData(data.PetalData, data.PetalColorData); Petals = DistributePetalLocalData(Flower, data.PetalData); Leaves = DistributeLeafLocalData(data.leafGrowRelation, data.SproutLeafData, data.GrownLeafData, data.LeafColorData); Debug.Log("PlantLocalData Constructed"); }