private void DrawCategory(Model.CategoryItem item, int index) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); item.name = EditorGUILayout.TextField("Name", item.name); item.audioObjectPrefab = (GameObject)EditorGUILayout.ObjectField("Category AO prefab", item.audioObjectPrefab, typeof(GameObject), false); item.usingDefaultPrefab = item.audioObjectPrefab == null; item.isMute = EditorGUILayout.Toggle("Is Mute", item.isMute); item.categoryVolume = EditorGUILayout.Slider("Category Volume", item.categoryVolume, 0f, 1f); EditorGUILayout.BeginHorizontal(EditorStyles.helpBox); if (GUILayout.Button("ADD SOUND ITEM")) { var soundItem = new Model.SoundItem(); bool isNoSoundItems = item.soundItems == null; var soundItems = new Model.SoundItem[!isNoSoundItems ? item.soundItems.Length + 1 : 1]; if (!isNoSoundItems) { item.soundItems.CopyTo(soundItems, 0); } soundItems[soundItems.Length - 1] = soundItem; item.soundItems = soundItems; } string nameAbv = ""; if (string.IsNullOrEmpty(item.name) == false) { nameAbv = item.name.Length > NAME_ABV_LEN?item.name.Substring(0, NAME_ABV_LEN) : item.name; } if (GUILayout.Button("Delete " + nameAbv)) { DeleteCategory(index); } EditorGUILayout.EndHorizontal(); if (item.soundItems != null) { if (item.soundItems.Length != 0) { item.soundsSearchName = EditorGUILayout.TextField("Search sound item", item.soundsSearchName); } } item.foldOutSoundItems = DrawSoundItems(item, item.foldOutSoundItems, item.soundsSearchName); EditorGUILayout.EndVertical(); }
private void DrawSoundItem(Model.SoundItem item, int index, Model.SoundItem[] items) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); item.name = EditorGUILayout.TextField("Name", item.name); item.mixer = (AudioMixerGroup)EditorGUILayout.ObjectField("Mixer", item.mixer, typeof(AudioMixerGroup), false); if (item.clips == null) { item.clips = new AudioClip[1]; } int size = item.clips.Length; size = EditorGUILayout.IntField("Size", size); if (size != item.clips.Length) { var newClips = new AudioClip[size]; for (int i = 0; i < item.clips.Length; i++) { if (i >= size) { break; } newClips[i] = item.clips[i]; } item.clips = newClips; } for (int i = 0; i < item.clips.Length; i++) { item.clips[i] = (AudioClip)EditorGUILayout.ObjectField(item.clips[i], typeof(AudioClip), false); } item.volume = EditorGUILayout.Slider("Volume", item.volume, 0f, 1f); string nameAbv = ""; if (string.IsNullOrEmpty(item.name) == false) { nameAbv = item.name.Length > NAME_ABV_LEN?item.name.Substring(0, NAME_ABV_LEN) : item.name; } if (GUILayout.Button("Delete Item " + nameAbv)) { DeleteSoundItem(index, items); } EditorGUILayout.EndVertical(); }
private bool DrawSoundItems(Model.CategoryItem item, bool foldOut, string searchName) { Model.SoundItem[] items = item.soundItems; if (items == null || items.Length == 0) { return(foldOut); } EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); foldOut = EditorGUILayout.Foldout(foldOut, "SOUND ITEMS", true); if (items != null) { if (items.Length != 0) { if (GUILayout.Button("DELETE ALL SOUNDS")) { items = new Model.SoundItem[0]; item.soundItems = items; return(foldOut); } } } EditorGUILayout.EndHorizontal(); if (foldOut) { for (int j = items.Length - 1; j >= 0; j--) { if (!string.IsNullOrEmpty(items[j].name)) { if (items[j].name.ToLower().Contains(searchName.ToLower()) == false && string.IsNullOrEmpty(searchName) == false) { continue; } } DrawSoundItem(items[j], j, items); } } EditorGUI.indentLevel--; return(foldOut); }
private void DeleteSoundItem(int index, Model.SoundItem[] items) { var category = System.Array.Find(_ac._database.items, (x) => { return(x.soundItems == items); }); var soundItems = new Model.SoundItem[category.soundItems.Length - 1]; int soundInd = 0; for (int i = 0; i < category.soundItems.Length; i++) { if (i == index) { continue; } soundItems[soundInd] = category.soundItems[i]; soundInd += 1; } category.soundItems = soundItems; }
/// <summary> /// Draw a SoundItem /// </summary> /// <param name="item">SoundItem data</param> /// <param name="index">SoundItem's index</param> /// <param name="items">The array of SoundItems</param> private void DrawSoundItem(Model.SoundItem item, int index, Model.SoundItem[] items) { EditorGUILayout.BeginVertical(EditorStyles.helpBox); item.name = EditorGUILayout.TextField("Name", item.name); string[] names = _ac._database.soundTags.ToArrayNames(); int[] ids = _ac._database.soundTags.ToArrayIDs(); if (ids.Length != 0) { int indexTag = System.Array.IndexOf(ids, item.tagID); indexTag = EditorGUILayout.Popup("Tag", indexTag, names); if (indexTag != -1) { item.tagID = ids[indexTag]; } } else { item.tagID = -1; } item.mixer = (AudioMixerGroup)EditorGUILayout.ObjectField("Mixer", item.mixer, typeof(AudioMixerGroup), false); if (item.clips == null) { item.clips = new AudioClip[1]; } int size = item.clips.Length; size = EditorGUILayout.IntField("Size", size); if (size != item.clips.Length) { var newClips = new AudioClip[size]; for (int i = 0; i < item.clips.Length; i++) { if (i >= size) { break; } newClips[i] = item.clips[i]; } item.clips = newClips; } for (int i = 0; i < item.clips.Length; i++) { item.clips[i] = (AudioClip)EditorGUILayout.ObjectField(item.clips[i], typeof(AudioClip), false); } item.isRandomVolume = EditorGUILayout.ToggleLeft("Use Random Volume", item.isRandomVolume, EditorStyles.boldLabel); if (!item.isRandomVolume) { item.volume = EditorGUILayout.Slider("Volume", item.volume, 0f, 1f); } else { EditorGUILayout.LabelField("Min Volume:", item.volumeRange.min.ToString(), EditorStyles.largeLabel); EditorGUILayout.LabelField("Max Volume:", item.volumeRange.max.ToString(), EditorStyles.largeLabel); EditorGUILayout.MinMaxSlider("Volume Range", ref item.volumeRange.min, ref item.volumeRange.max, 0f, 1f); } item.isRandomPitch = EditorGUILayout.ToggleLeft("Use Random Pitch", item.isRandomPitch, EditorStyles.boldLabel); if (item.isRandomPitch) { EditorGUILayout.LabelField("Min Pitch:", item.pitchRange.min.ToString(), EditorStyles.largeLabel); EditorGUILayout.LabelField("Max Pitch:", item.pitchRange.max.ToString(), EditorStyles.largeLabel); EditorGUILayout.MinMaxSlider("Pitch Range", ref item.pitchRange.min, ref item.pitchRange.max, PITCH_RANGE_MIN, PITCH_RANGE_MAX); } string nameAbv = ""; if (string.IsNullOrEmpty(item.name) == false) { nameAbv = item.name.Length > NAME_ABV_LEN?item.name.Substring(0, NAME_ABV_LEN) : item.name; } if (GUILayout.Button("Delete Item " + nameAbv)) { DeleteSoundItem(index, items); } EditorGUILayout.EndVertical(); }