public void Init(Levels.FlowerConfiguration config) { flowerFace.flower = this; flowerState.Init(config.isHappy); flowerPetals.SetPetals(this, config); if (onStateChange != null) { onStateChange.Invoke(config.isHappy); } }
public void SetPetals(FlowerController flower, Levels.FlowerConfiguration config) { var petals = config.petals; this.angle = config.angle; this.count = petals.Length; for (int i = 0; i < allPetals.Length; i++) { allPetals[i].gameObject.SetActive(false); } int len = Mathf.Max(config.slots, petals.Length); slots = new Quaternion[len]; float angle = 360f / len; for (int i = 0; i < len; i++) { slots[i] = Quaternion.Euler(0f, angle * i + config.angle, 0f); } var list = new List <KeyValuePair <int, int> >(petals.Length); activePetals = new FlowerPetal[len]; int half = petals.Length / 2; for (int j = 0, i; j < petals.Length; j++) { i = j > half ? (activePetals.Length - (petals.Length - j)) : j; activePetals[i] = allPetals[i]; activePetals[i].flower = flower; activePetals[i].index = i; list.Add(new KeyValuePair <int, int>(i, petals[j].showIndex)); activePetals[i].Init(slots[i], petals[j].color, i == 0 ? 0 : (i > half ? -1 : 1)); activePetals[i].petalAnchor.localScale = Vector3.one * 0.01f; activePetals[i].gameObject.SetActive(true); } isAnimate = true; removeIndex = 0; list.Sort(PetalsQueueComparer); StartCoroutine(ShowPetalsRoutine(list.ConvertAll(x => x.Key))); }