4
4
using UnityEngine . Audio ;
5
5
using SoundSystem ;
6
6
7
+ //https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/Inspector/AudioClipInspector.cs
8
+
7
9
[ CustomEditor ( typeof ( Sound ) ) ]
8
10
public class SoundEditor : Editor {
9
11
private Sound _targetSound ;
@@ -27,7 +29,6 @@ private void OnDisable() {
27
29
}
28
30
29
31
// Passing in clip and importer separately as we're not completely done with the asset setup at the time we're asked to generate the preview.
30
- //https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/Inspector/AudioClipInspector.cs
31
32
private void DoRenderPreview ( AudioClip clip , Rect wantedRect , float scaleFactor ) {
32
33
// scaleFactor *= 0.95f; // Reduce amplitude slightly to make highly compressed signals fit.
33
34
float [ ] sampleData = new float [ _targetClip . samples * _targetClip . channels ] ;
@@ -62,6 +63,8 @@ private void DoRenderPreview(AudioClip clip, Rect wantedRect, float scaleFactor)
62
63
}
63
64
64
65
private void PlayPreview ( ) {
66
+ _targetClip = _targetSound . GetClip ( ) ;
67
+
65
68
_previewer . clip = _targetClip ;
66
69
_previewer . volume = _targetSound . Volume ;
67
70
_previewer . pitch = _targetSound . Pitch ;
@@ -71,9 +74,9 @@ private void PlayPreview() {
71
74
_previewer . Play ( ) ;
72
75
}
73
76
74
- private void PreviewNextClip ( ) {
77
+ private void GetNextClip ( ) {
78
+ _targetSound . ManualIncrementIndex ( ) ;
75
79
_targetClip = _targetSound . GetClip ( ) ;
76
- // PlayPreview();
77
80
}
78
81
79
82
private void StopPreview ( ) {
@@ -94,11 +97,7 @@ public override void OnPreviewGUI(Rect r, GUIStyle background) {
94
97
if ( Event . current . isMouse ) {
95
98
return ;
96
99
}
97
- //TODO replace this line
98
100
gameObjectEditor . DrawPreview ( r ) ;
99
- // gameObjectEditor.RenderStaticPreview();
100
- // Texture2D temp = AssetPreview.GetAssetPreview(_targetClip);
101
- // DoRenderPreview(_targetClip, r, 1.0f);
102
101
if ( _previewer . isPlaying ) {
103
102
float t = _previewer . time ;
104
103
@@ -115,76 +114,6 @@ public override void OnPreviewGUI(Rect r, GUIStyle background) {
115
114
}
116
115
}
117
116
118
- //TODO figure out how to override click events
119
- // public override void OnPreviewGUI(Rect r, GUIStyle background) {
120
- // if (s_DefaultIcon == null) Init();
121
-
122
- // Event evt = Event.current;
123
- // if (evt.type != EventType.Repaint && evt.type != EventType.Layout && evt.type != EventType.Used) {
124
- // switch (evt.type) {
125
- // case EventType.MouseDrag:
126
- // case EventType.MouseDown: {
127
- // if (r.Contains(evt.mousePosition)) {
128
- // var startSample = (int)(evt.mousePosition.x * (_targetClip.samples / (int)r.width));
129
- // if (!AudioUtil.IsPreviewClipPlaying() || _targetClip != m_Clip)
130
- // PlayClip(clip, startSample, s_Loop);
131
- // else
132
- // AudioUtil.SetPreviewClipSamplePosition(clip, startSample);
133
- // evt.Use();
134
- // }
135
- // }
136
- // break;
137
- // }
138
- // return;
139
- // }
140
-
141
- // if (Event.current.type == EventType.Repaint)
142
- // background.Draw(r, false, false, false, false);
143
-
144
- // int c = _targetClip.channels;
145
- // Rect s_WantedRect = new Rect(r.x, r.y, r.width, r.height);
146
- // float sec2px = ((float)s_WantedRect.width / _targetClip.length);
147
-
148
- // bool previewAble = AudioUtil.HasPreview(clip) || !(AudioUtil.IsTrackerFile(clip));
149
- // if (!previewAble) {
150
- // float labelY = (r.height > 150) ? r.y + (r.height / 2) - 10 : r.y + (r.height / 2) - 25;
151
- // if (r.width > 64) {
152
- // if (AudioUtil.IsTrackerFile(clip)) {
153
- // EditorGUI.DropShadowLabel(new Rect(r.x, labelY, r.width, 20), string.Format("Module file with " + AudioUtil.GetMusicChannelCount(clip) + " channels."));
154
- // } else
155
- // EditorGUI.DropShadowLabel(new Rect(r.x, labelY, r.width, 20), "Can not show PCM data for this file");
156
- // }
157
-
158
- // if (m_Clip == clip && playing) {
159
- // float t = AudioUtil.GetPreviewClipPosition();
160
-
161
- // System.TimeSpan ts = new System.TimeSpan(0, 0, 0, 0, (int)(t * 1000.0f));
162
-
163
- // EditorGUI.DropShadowLabel(new Rect(s_WantedRect.x, s_WantedRect.y, s_WantedRect.width, 20), string.Format("Playing - {0:00}:{1:00}.{2:000}", ts.Minutes, ts.Seconds, ts.Milliseconds));
164
- // }
165
- // } else {
166
- // PreviewGUI.BeginScrollView(s_WantedRect, m_Position, s_WantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
167
-
168
- // if (Event.current.type == EventType.Repaint) {
169
- // DoRenderPreview(_targetClip, r, 1.0f);
170
- // }
171
-
172
- // for (int i = 0; i < c; ++i) {
173
- // if (c > 1 && r.width > 64) {
174
- // var labelRect = new Rect(s_WantedRect.x + 5, s_WantedRect.y + (s_WantedRect.height / c) * i, 30, 20);
175
- // EditorGUI.DropShadowLabel(labelRect, "ch " + (i + 1));
176
- // }
177
- // }
178
-
179
-
180
- // PreviewGUI.EndScrollView();
181
- // }
182
-
183
- // // force update GUI
184
- // if (playing)
185
- // GUIView.current.Repaint();
186
- // }
187
-
188
117
public override void OnPreviewSettings ( ) {
189
118
if ( GUILayout . Button ( EditorGUIUtility . IconContent ( "PlayButton" ) , EditorStyles . toolbarButton ) ) {
190
119
if ( ! _previewer . isPlaying ) {
@@ -193,28 +122,6 @@ public override void OnPreviewSettings() {
193
122
StopPreview ( ) ;
194
123
}
195
124
} ;
196
- if ( GUILayout . Button ( EditorGUIUtility . IconContent ( "Animation.NextKey" ) , EditorStyles . toolbarButton ) ) PreviewNextClip ( ) ;
125
+ if ( GUILayout . Button ( EditorGUIUtility . IconContent ( "Animation.NextKey" ) , EditorStyles . toolbarButton ) ) GetNextClip ( ) ;
197
126
}
198
-
199
- //TODO
200
- // public override string GetInfoString() {
201
- // AudioClip clip = _targetClip;
202
- // int c = _targetClip.channels;
203
- // string ch = c == 1 ? "Mono" : c == 2 ? "Stereo" : (c - 1) + ".1";
204
- // // AudioCompressionFormat platformFormat = AudioUtil.GetTargetPlatformSoundCompressionFormat(clip);
205
- // // AudioCompressionFormat editorFormat = AudioUtil.GetSoundCompressionFormat(clip);
206
- // string s = "";
207
- // // if (platformFormat != editorFormat)
208
- // // s += " (" + editorFormat + " in editor" + ")";
209
- // s += ", " + _targetClip.frequency + " Hz, " + ch + ", ";
210
-
211
- // System.TimeSpan ts = new System.TimeSpan(0, 0, 0, 0, (int)_targetClip.length);
212
-
213
- // if ((uint)_targetClip.length == 0xffffffff)
214
- // s += "Unlimited";
215
- // else
216
- // s += String.Format("{0:00}:{1:00}.{2:000}", ts.Minutes, ts.Seconds, ts.Milliseconds);
217
-
218
- // return s;
219
- // }
220
127
}
0 commit comments