private void buildVoicesList() { clearVoicesList(); //make sure everything is deleted if (Target != null) { RectTransform containerRectTransform = Target.GetComponent <RectTransform>(); //items = Speaker.VoicesForCulture(Culture.text); items = Speaker.VoicesForGender(gender, Culture.text, false); /* * if (items.Count == 0) * { * if (!string.IsNullOrEmpty(Culture.text)) * { * Debug.LogWarning("No voices for culture '" + Culture.text + "' found - using the default system voices."); * } * items = Speaker.Voices; * } */ if (items.Count > 0) { //calculate the width and height of each child item. float width = containerRectTransform.rect.width / ColumnCount - SpaceWidth.x; float height = SpaceHeight.x + SpaceHeight.y; int rowCount = items.Count / ColumnCount; if (rowCount > 0 && items.Count % rowCount > 0) { rowCount++; } //adjust the height of the container so that it will just barely fit all its children float scrollHeight = height * rowCount; containerRectTransform.offsetMin = new Vector2(containerRectTransform.offsetMin.x, -scrollHeight / 2); containerRectTransform.offsetMax = new Vector2(containerRectTransform.offsetMax.x, scrollHeight / 2); int j = 0; for (int ii = 0; ii < items.Count; ii++) { //this is used instead of a double for loop because itemCount may not fit perfectly into the rows/columns if (ii % ColumnCount == 0) { j++; } //create a new item, name it, and set the parent GameObject newItem = Instantiate(ItemPrefab) as GameObject; newItem.name = Target.name + " item at (" + ii + "," + j + ")"; newItem.transform.SetParent(Target.transform); newItem.transform.localScale = Vector3.one; if (AudioFilter != null) { AudioFilter.Sources.Add(newItem.GetComponent <AudioSource>()); AudioFilter.ReverbFilters.Add(newItem.GetComponent <AudioReverbFilter>()); AudioFilter.ChorusFilters.Add(newItem.GetComponent <AudioChorusFilter>()); AudioFilter.EchoFilters.Add(newItem.GetComponent <AudioEchoFilter>()); AudioFilter.DistortionFilters.Add(newItem.GetComponent <AudioDistortionFilter>()); AudioFilter.LowPassFilters.Add(newItem.GetComponent <AudioLowPassFilter>()); AudioFilter.HighPassFilters.Add(newItem.GetComponent <AudioHighPassFilter>()); } SpeakWrapper wrapper = newItem.GetComponent <SpeakWrapper>(); wrapper.SpeakerVoice = items[ii]; wrapper.Input = Input; wrapper.Label.text = items[ii].Name; wrappers.Add(wrapper); //move and size the new item RectTransform rectTransform = newItem.GetComponent <RectTransform>(); float x = (width + SpaceWidth.x) * (ii % ColumnCount) + SpaceWidth.x; float y = -height * j; rectTransform.offsetMin = new Vector2(x, y); x = rectTransform.offsetMin.x + width; y = rectTransform.offsetMin.y + SpaceHeight.x; rectTransform.offsetMax = new Vector2(x, y); } if (AudioFilter != null) { AudioFilter.ResetFilters(); } } if (Scroll != null) { Scroll.value = 1f; } } if (Voices != null) { Voices.text = "Voices (" + items.Count + ")"; } }
private void buildVoicesList() { wrappers.Clear(); if (AudioFilter != null) { AudioFilter.ClearFilters(); } RectTransform rowRectTransform = ItemPrefab.GetComponent <RectTransform>(); RectTransform containerRectTransform = Target.GetComponent <RectTransform>(); for (var i = Target.transform.childCount - 1; i >= 0; i--) { Transform child = Target.transform.GetChild(i); child.SetParent(null); Destroy(child.gameObject); // Optionally destroy the objectA if not longer needed } List <Voice> items = Speaker.VoicesForCulture(Culture.text); if (items.Count == 0) { Debug.LogWarning("No voices for culture '" + Culture.text + "' found - using the default system voices."); items = Speaker.Voices; } if (items.Count > 0) { //Debug.Log("ITEMS: " + items.Count); //calculate the width and height of each child item. float width = containerRectTransform.rect.width / ColumnCount - (SpaceWidth.x + SpaceWidth.y) * ColumnCount; float height = rowRectTransform.rect.height - (SpaceHeight.x + SpaceHeight.y); int rowCount = items.Count / ColumnCount; if (rowCount > 0 && items.Count % rowCount > 0) { rowCount++; } //adjust the height of the container so that it will just barely fit all its children float scrollHeight = height * rowCount; containerRectTransform.offsetMin = new Vector2(containerRectTransform.offsetMin.x, -scrollHeight / 2); containerRectTransform.offsetMax = new Vector2(containerRectTransform.offsetMax.x, scrollHeight / 2); int j = 0; for (int ii = 0; ii < items.Count; ii++) { //this is used instead of a double for loop because itemCount may not fit perfectly into the rows/columns if (ii % ColumnCount == 0) { j++; } //create a new item, name it, and set the parent GameObject newItem = Instantiate(ItemPrefab) as GameObject; newItem.name = Target.name + " item at (" + ii + "," + j + ")"; newItem.transform.SetParent(Target.transform); newItem.transform.localScale = Vector3.one; if (AudioFilter != null) { AudioFilter.Sources.Add(newItem.GetComponent <AudioSource>()); AudioFilter.ReverbFilters.Add(newItem.GetComponent <AudioReverbFilter>()); AudioFilter.ChorusFilters.Add(newItem.GetComponent <AudioChorusFilter>()); AudioFilter.EchoFilters.Add(newItem.GetComponent <AudioEchoFilter>()); AudioFilter.DistortionFilters.Add(newItem.GetComponent <AudioDistortionFilter>()); AudioFilter.LowPassFilters.Add(newItem.GetComponent <AudioLowPassFilter>()); AudioFilter.HighPassFilters.Add(newItem.GetComponent <AudioHighPassFilter>()); } SpeakWrapper wrapper = newItem.GetComponent <SpeakWrapper>(); wrapper.SpeakerVoice = items[ii]; wrapper.Input = Input; wrapper.Label.text = items[ii].Name; wrappers.Add(wrapper); //move and size the new item RectTransform rectTransform = newItem.GetComponent <RectTransform>(); float x = -containerRectTransform.rect.width / 2 + (width + SpaceWidth.x) * (ii % ColumnCount) + SpaceWidth.x * ColumnCount; float y = containerRectTransform.rect.height / 2 - height * j; rectTransform.offsetMin = new Vector2(x, y); x = rectTransform.offsetMin.x + width; y = rectTransform.offsetMin.y + height; rectTransform.offsetMax = new Vector2(x, y); } if (AudioFilter != null) { AudioFilter.ResetFilters(); } } else { Debug.LogError("No voices found - speech is not possible!"); } Scroll.value = 1f; }