1 #pragma warning disable 0168 6 using System.Collections.Generic;
8 namespace HKI.Core.Audio.Editor
13 [CustomEditor(typeof(Playlist))]
17 const string playlistPlayTypeSPName =
"PlaylistPlayType";
18 const string clipsSPName =
"Clips";
20 const string clipSPName =
"Clip";
21 const string volumeSPName =
"Volume";
22 const string pitchSPName =
"Pitch";
24 SerializedProperty playlistPlayTypeSP = null;
25 SerializedProperty clipsSP = null;
27 ReorderableList clipsRL = null;
28 List<float> clipsRLHeights =
new List<float>();
29 Texture2D highlightTextureRL = null;
39 playlistPlayTypeSP = serializedObject.FindProperty(playlistPlayTypeSPName);
40 clipsSP = serializedObject.FindProperty(clipsSPName);
42 clipsRL =
new ReorderableList(serializedObject, clipsSP,
true,
true,
false,
false);
43 clipsRL.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect,
"Sound Clips"); };
44 clipsRL.drawElementCallback = OnDrawElement_ClipsRL;
45 clipsRL.elementHeightCallback = OnElementHeight_ClipsRL;
46 clipsRL.drawElementBackgroundCallback = OnDrawElementBackground_ClipsRL;
48 float heightSize = EditorGUIUtility.singleLineHeight * 1.25f;
49 for (
int i = 0; i < clipsSP.arraySize; i++)
50 clipsRLHeights.Add(heightSize);
52 OnHeightsChanged_ClipsRL();
54 highlightTextureRL =
new Texture2D(1, 1);
55 highlightTextureRL.SetPixel(0, 0,
new Color(0.2f, 0.2f, 0.2f, 1.0f));
56 highlightTextureRL.Apply();
62 serializedObject.Update();
66 EditorGUILayout.Space();
72 serializedObject.ApplyModifiedProperties();
78 EditorGUILayout.LabelField(
"Settings", EditorStyles.boldLabel);
80 EditorGUILayout.PropertyField(playlistPlayTypeSP);
85 if (GUILayout.Button(
"Add New Sound Clip", GUILayout.Height(30.0f)))
88 soundClip.name =
"New Sound Clip";
90 AssetDatabase.AddObjectToAsset(soundClip, target);
91 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(soundClip));
93 clipsSP.InsertArrayElementAtIndex(clipsSP.arraySize);
94 SerializedProperty elementSP = clipsSP.GetArrayElementAtIndex(clipsSP.arraySize - 1);
96 elementSP.objectReferenceValue = soundClip;
102 EditorGUILayout.LabelField(
"Sound clips", EditorStyles.boldLabel);
107 updateDeleteObject = null;
109 if (clipsSP.arraySize > 0)
110 clipsRL.DoLayoutList();
112 EditorGUILayout.LabelField(
"Currently there is no data in this container.");
117 string newName = element.name;
119 AssetDatabase.SetLabels(element,
new string[] { newName });
120 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(element));
125 if (clipsSP.GetArrayElementAtIndex(deleteIndex) != null)
126 clipsSP.DeleteArrayElementAtIndex(deleteIndex);
128 clipsSP.DeleteArrayElementAtIndex(deleteIndex);
129 UnityEngine.Object.DestroyImmediate(updateDeleteObject,
true);
130 AssetDatabase.SaveAssets();
131 AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target));
139 float height = EditorGUIUtility.singleLineHeight * 1.25f;
140 SerializedProperty elementSP = clipsSP.GetArrayElementAtIndex(index);
141 float totalLineHeight = EditorGUIUtility.singleLineHeight * 1.25f;
144 Rect mainLabelRect =
new Rect(rect);
145 mainLabelRect.height = EditorGUIUtility.singleLineHeight;
146 mainLabelRect.y += 2;
147 EditorGUI.LabelField(mainLabelRect, elementSP.objectReferenceValue.name, EditorStyles.boldLabel);
152 height = 7.5f * totalLineHeight;
154 float moveToLeft = 15.0f;
155 float adjustedStartX = rect.x - moveToLeft;
156 float adjustedWidth = rect.width + moveToLeft;
158 Rect guiRect =
new Rect(adjustedStartX, rect.y + totalLineHeight, adjustedWidth, EditorGUIUtility.singleLineHeight);
161 EditorGUI.LabelField(guiRect,
"General", EditorStyles.boldLabel);
162 guiRect.y += totalLineHeight;
164 float nameLabelWidth = 50.0f;
165 guiRect.width = nameLabelWidth;
166 EditorGUI.LabelField(guiRect,
"Name:");
167 guiRect.x += nameLabelWidth;
168 float updateButtonWidth = 120.0f;
169 float deleteButtonWidth = 60.0f;
170 guiRect.width = adjustedWidth - nameLabelWidth - updateButtonWidth - deleteButtonWidth;
171 elementSP.objectReferenceValue.name = EditorGUI.TextField(guiRect, elementSP.objectReferenceValue.name);
173 guiRect.x = rect.x + rect.width - updateButtonWidth - deleteButtonWidth;
174 guiRect.width = updateButtonWidth;
175 if (GUI.Button(guiRect,
"Update File Name"))
178 updateDeleteObject = elementSP.objectReferenceValue;
181 guiRect.x = rect.x + rect.width - deleteButtonWidth;
182 guiRect.width = deleteButtonWidth;
183 if (GUI.Button(guiRect,
"Delete"))
186 this.deleteIndex = index;
187 updateDeleteObject = elementSP.objectReferenceValue;
190 guiRect.x = adjustedStartX;
191 guiRect.y += 1.5f * totalLineHeight;
192 guiRect.width = adjustedWidth;
194 EditorGUI.LabelField(guiRect,
"Sound Clip Data", EditorStyles.boldLabel);
195 guiRect.y += totalLineHeight;
198 SerializedObject elementSO =
new SerializedObject(elementSP.objectReferenceValue);
202 EditorGUI.PropertyField(guiRect, elementSO.FindProperty(clipSPName));
203 guiRect.y += totalLineHeight;
206 EditorGUI.PropertyField(guiRect, elementSO.FindProperty(volumeSPName));
207 guiRect.y += totalLineHeight;
210 EditorGUI.PropertyField(guiRect, elementSO.FindProperty(pitchSPName));
212 elementSO.ApplyModifiedProperties();
218 clipsRLHeights[index] = height;
220 catch(ArgumentOutOfRangeException e)
222 Debug.LogWarning(e.Message);
226 OnHeightsChanged_ClipsRL();
237 height = clipsRLHeights[index];
239 catch(ArgumentOutOfRangeException e)
245 OnHeightsChanged_ClipsRL();
253 float[] floats = clipsRLHeights.ToArray();
254 Array.Resize(ref floats, clipsSP.arraySize);
255 clipsRLHeights.Clear();
256 clipsRLHeights.AddRange(floats);
263 rect.height = clipsRLHeights[index];
265 GUI.DrawTexture(rect, highlightTextureRL as Texture);
void OnHeightsChanged_ClipsRL()
void OnDrawElementBackground_ClipsRL(Rect rect, int index, bool isActive, bool isFocused)
Custom inspector for the Playlist class.
float OnElementHeight_ClipsRL(int index)
void OnDrawElement_ClipsRL(Rect rect, int index, bool isActive, bool isFocused)
override void OnInspectorGUI()
This is a container ScriptableObject that holds all data required to play a AudioClip.