AudioManagerInspector.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections.Generic;
  4. namespace OVR
  5. {
  6. /*
  7. -----------------------
  8. AudioManagerInspector
  9. -----------------------
  10. */
  11. [CustomEditor(typeof(AudioManager))]
  12. public class AudioManagerInspector : Editor {
  13. private AudioManager audioManager = null;
  14. private string dragDropIdentifier = "MoveSoundFX";
  15. private GUIStyle customDividerStyle = null;
  16. /*
  17. -----------------------
  18. OnInspectorGUI()
  19. -----------------------
  20. */
  21. public override void OnInspectorGUI() {
  22. audioManager = target as AudioManager;
  23. Event e = Event.current;
  24. // draw the default properties
  25. DrawDefaultProperties();
  26. // draw the categories section
  27. DrawCategories( e );
  28. serializedObject.Update();
  29. // draw the sound effects for the selected category
  30. DrawSoundEffects( e );
  31. serializedObject.ApplyModifiedProperties();
  32. CreateStyles();
  33. }
  34. /*
  35. -----------------------
  36. MarkDirty()
  37. -----------------------
  38. */
  39. void MarkDirty() {
  40. serializedObject.SetIsDifferentCacheDirty();
  41. EditorUtility.SetDirty( audioManager );
  42. }
  43. static private int selectedGroup = 0;
  44. private int nextGroup = -1;
  45. private int editGroup = -1;
  46. private FastList<SoundGroup> soundGroups = new FastList<SoundGroup>();
  47. private FastList<ItemRect> groups = new FastList<ItemRect>();
  48. private Rect dropArea = new Rect();
  49. private bool addSound = false;
  50. private int deleteSoundIdx = -1;
  51. private int dupeSoundIdx = -1;
  52. private bool sortSounds = false;
  53. private bool moveQueued = false;
  54. private int origGroup = -1;
  55. private int origIndex = -1;
  56. private int moveToGroup = -1;
  57. /*
  58. -----------------------
  59. DrawDefaultProperties()
  60. -----------------------
  61. */
  62. void DrawDefaultProperties() {
  63. BeginContents();
  64. if ( DrawHeader( "Default Properties", true ) ) {
  65. EditorGUILayout.BeginVertical( GUI.skin.box );
  66. EditorGUILayout.PropertyField( serializedObject.FindProperty( "makePersistent" ), new GUIContent( "Don't Destroy on Load" ) );
  67. EditorGUILayout.PropertyField( serializedObject.FindProperty( "enableSpatializedAudio" ), new GUIContent( "Enable Spatialized Audio" ) );
  68. EditorGUILayout.PropertyField( serializedObject.FindProperty( "enableSpatializedFastOverride" ), new GUIContent( "Force Disable Reflections" ) );
  69. EditorGUILayout.PropertyField( serializedObject.FindProperty( "audioMixer" ), new GUIContent( "Master Audio Mixer" ) );
  70. EditorGUILayout.PropertyField( serializedObject.FindProperty( "defaultMixerGroup" ), new GUIContent( "Pooled Emitter Mixer Group" ) );
  71. EditorGUILayout.PropertyField( serializedObject.FindProperty( "reservedMixerGroup" ), new GUIContent( "Reserved Emitter Mixer Group" ) );
  72. EditorGUILayout.PropertyField( serializedObject.FindProperty( "voiceChatMixerGroup" ), new GUIContent( "Voice Chat Mixer Group" ) );
  73. EditorGUILayout.PropertyField( serializedObject.FindProperty( "verboseLogging" ), new GUIContent( "Verbose Logging" ) );
  74. EditorGUILayout.PropertyField( serializedObject.FindProperty( "maxSoundEmitters" ), new GUIContent( "Max Sound Emitters" ) );
  75. EditorGUILayout.PropertyField( serializedObject.FindProperty( "volumeSoundFX" ), new GUIContent( "Default Volume" ) );
  76. EditorGUILayout.PropertyField( serializedObject.FindProperty( "soundFxFadeSecs" ), new GUIContent( "Sound FX Fade Secs" ) );
  77. EditorGUILayout.PropertyField( serializedObject.FindProperty( "audioMinFallOffDistance" ), new GUIContent( "Minimum Falloff Distance" ) );
  78. EditorGUILayout.PropertyField( serializedObject.FindProperty( "audioMaxFallOffDistance" ), new GUIContent( "Maximum Falloff Distance" ) );
  79. EditorGUILayout.EndVertical();
  80. serializedObject.ApplyModifiedProperties();
  81. }
  82. EndContents();
  83. }
  84. /*
  85. -----------------------
  86. DrawSoundGroupProperties()
  87. -----------------------
  88. */
  89. void DrawSoundGroupProperties() {
  90. if ( selectedGroup == -1 ) {
  91. return;
  92. }
  93. SerializedProperty soundGroupsArray = serializedObject.FindProperty( "soundGroupings" );
  94. if ( selectedGroup >= soundGroupsArray.arraySize ) {
  95. return;
  96. }
  97. SerializedProperty soundGroup = soundGroupsArray.GetArrayElementAtIndex( selectedGroup );
  98. string soundGroupName = soundGroup.FindPropertyRelative( "name" ).stringValue;
  99. if ( DrawHeader( string.Format( "{0} Properties", soundGroupName ), true ) ) {
  100. EditorGUILayout.BeginVertical( GUI.skin.box );
  101. EditorGUILayout.PropertyField( soundGroup.FindPropertyRelative( "mixerGroup" ), new GUIContent( "Override Mixer Group", "Leave empty to use the Audio Manager's default mixer group" ) );
  102. if ( !Application.isPlaying ) {
  103. EditorGUILayout.PropertyField( soundGroup.FindPropertyRelative( "maxPlayingSounds" ), new GUIContent( "Max Playing Sounds Limit", "Max playing sounds for this sound group, 0 = no limit" ) );
  104. } else {
  105. EditorGUILayout.BeginHorizontal();
  106. EditorGUILayout.PropertyField( soundGroup.FindPropertyRelative( "maxPlayingSounds" ), new GUIContent( "Max Playing Sounds Limit", "Max playing sounds for this sound group, 0 = no limit" ) );
  107. // cast to the actual object
  108. int playingSounds = soundGroup.FindPropertyRelative( "playingSoundCount" ).intValue;
  109. EditorGUILayout.LabelField( string.Format( "Playing: {0}", playingSounds ), GUILayout.Width( 80.0f ) );
  110. EditorGUILayout.EndHorizontal();
  111. }
  112. EditorGUILayout.PropertyField( soundGroup.FindPropertyRelative( "preloadAudio" ), new GUIContent( "Preload Audio Clips", "Default = No special preloading, Preload = Audio clips are set to 'Preload', Manual Preload = Audio clips are set to not 'Preload'" ) );
  113. EditorGUILayout.PropertyField( soundGroup.FindPropertyRelative( "volumeOverride" ), new GUIContent( "Volume Override", "All sounds played in this group will have volume scaled by this amount" ) );
  114. if ( soundGroup.FindPropertyRelative( "volumeOverride" ).floatValue == 0.0f ) {
  115. EditorGUILayout.HelpBox( "With a volumeOverride of 0.0, these sounds will not play!", MessageType.Warning );
  116. }
  117. EditorGUILayout.EndVertical();
  118. serializedObject.ApplyModifiedProperties();
  119. }
  120. }
  121. /*
  122. -----------------------
  123. DrawCategories()
  124. -----------------------
  125. */
  126. void DrawCategories( Event e ) {
  127. // do any housework before we start drawing
  128. if ( moveQueued ) {
  129. // make a temp copy
  130. List<SoundFX> origSoundList = new List<SoundFX>( audioManager.soundGroupings[origGroup].soundList );
  131. SoundFX temp = origSoundList[origIndex];
  132. List<SoundFX> moveToSoundList = new List<SoundFX>( audioManager.soundGroupings[moveToGroup].soundList );
  133. // add it to the move to group
  134. moveToSoundList.Add( temp );
  135. audioManager.soundGroupings[moveToGroup].soundList = moveToSoundList.ToArray();
  136. // and finally, remove it from the original group
  137. origSoundList.RemoveAt( origIndex );
  138. audioManager.soundGroupings[origGroup].soundList = origSoundList.ToArray();
  139. Debug.Log( "> Moved '" + temp.name + "' from " + "'" + audioManager.soundGroupings[origGroup].name + "' to '" + audioManager.soundGroupings[moveToGroup].name );
  140. MarkDirty();
  141. moveQueued = false;
  142. }
  143. // switch to the next group
  144. if ( nextGroup > -1 ) {
  145. selectedGroup = nextGroup;
  146. nextGroup = -1;
  147. }
  148. // add a sound
  149. if ( addSound ) {
  150. List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
  151. SoundFX soundFX = new SoundFX();
  152. soundFX.name = audioManager.soundGroupings[selectedGroup].name.ToLower() + "_new_unnamed_sound_fx";
  153. soundList.Add( soundFX );
  154. audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
  155. MarkDirty();
  156. addSound = false;
  157. }
  158. // sort the sounds
  159. if ( sortSounds ) {
  160. List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
  161. soundList.Sort( delegate ( SoundFX sfx1, SoundFX sfx2 ) { return string.Compare( sfx1.name, sfx2.name ); } );
  162. audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
  163. MarkDirty();
  164. sortSounds = false;
  165. }
  166. // delete a sound
  167. if ( deleteSoundIdx > -1 ) {
  168. List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
  169. soundList.RemoveAt( deleteSoundIdx );
  170. audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
  171. MarkDirty();
  172. deleteSoundIdx = -1;
  173. }
  174. // duplicate a sound
  175. if ( dupeSoundIdx > -1 ) {
  176. List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
  177. SoundFX origSoundFX = soundList[dupeSoundIdx];
  178. // clone this soundFX
  179. string json = JsonUtility.ToJson( origSoundFX );
  180. SoundFX soundFX = JsonUtility.FromJson<SoundFX>( json );
  181. soundFX.name += "_duplicated";
  182. soundList.Insert( dupeSoundIdx + 1, soundFX );
  183. audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
  184. MarkDirty();
  185. dupeSoundIdx = -1;
  186. }
  187. if ( e.type == EventType.Repaint ) {
  188. groups.Clear();
  189. }
  190. GUILayout.Space( 6f );
  191. Color defaultColor = GUI.contentColor;
  192. BeginContents();
  193. if ( DrawHeader( "Sound FX Groups", true ) ) {
  194. EditorGUILayout.BeginVertical( GUI.skin.box );
  195. soundGroups.Clear();
  196. for ( int i = 0; i < audioManager.soundGroupings.Length; i++ ) {
  197. soundGroups.Add( audioManager.soundGroupings[i] );
  198. }
  199. for ( int i = 0; i < soundGroups.size; i++ ) {
  200. EditorGUILayout.BeginHorizontal();
  201. {
  202. if ( i == selectedGroup ) {
  203. GUI.contentColor = ( i == editGroup ) ? Color.white : Color.yellow;
  204. } else {
  205. GUI.contentColor = defaultColor;
  206. }
  207. if ( ( e.type == EventType.KeyDown ) && ( ( e.keyCode == KeyCode.Return ) || ( e.keyCode == KeyCode.KeypadEnter ) ) ) {
  208. // toggle editing
  209. if ( editGroup >= 0 ) {
  210. editGroup = -1;
  211. }
  212. Event.current.Use();
  213. }
  214. if ( i == editGroup ) {
  215. soundGroups[i].name = GUILayout.TextField( soundGroups[i].name, GUILayout.MinWidth( Screen.width - 80f ) );
  216. } else {
  217. GUILayout.Label( soundGroups[i].name, ( i == selectedGroup ) ? EditorStyles.whiteLabel : EditorStyles.label, GUILayout.ExpandWidth( true ) );
  218. }
  219. GUILayout.FlexibleSpace();
  220. if ( GUILayout.Button( GUIContent.none, "OL Minus", GUILayout.Width(17f) ) ) { // minus button
  221. if ( EditorUtility.DisplayDialog( "Delete '" + soundGroups[i].name + "'", "Are you sure you want to delete the selected sound group?", "Continue", "Cancel" ) ) {
  222. soundGroups.RemoveAt( i );
  223. MarkDirty();
  224. }
  225. }
  226. }
  227. EditorGUILayout.EndHorizontal();
  228. // build a list of items
  229. Rect lastRect = GUILayoutUtility.GetLastRect();
  230. if ( e.type == EventType.Repaint ) {
  231. groups.Add ( new ItemRect( i, lastRect, null ) );
  232. }
  233. if ( ( e.type == EventType.MouseDown ) && lastRect.Contains( e.mousePosition ) ) {
  234. if ( ( i != selectedGroup ) || ( e.clickCount == 2 ) ) {
  235. nextGroup = i;
  236. if ( e.clickCount == 2 ) {
  237. editGroup = i;
  238. } else if ( editGroup != nextGroup ) {
  239. editGroup = -1;
  240. }
  241. Repaint();
  242. }
  243. }
  244. }
  245. // add the final plus button
  246. EditorGUILayout.BeginHorizontal();
  247. GUILayout.FlexibleSpace();
  248. if ( GUILayout.Button( GUIContent.none, "OL Plus", GUILayout.Width(17f) ) ) { // plus button
  249. soundGroups.Add( new SoundGroup( "unnamed sound group" ) );
  250. selectedGroup = editGroup = soundGroups.size - 1;
  251. MarkDirty();
  252. }
  253. EditorGUILayout.EndHorizontal();
  254. EditorGUILayout.EndVertical();
  255. // reset the color
  256. GUI.contentColor = defaultColor;
  257. // the sort and import buttons
  258. EditorGUILayout.BeginHorizontal();
  259. GUILayout.FlexibleSpace();
  260. if ( GUILayout.Button( "Sort", GUILayout.Width( 70f ) ) ) {
  261. soundGroups.Sort( delegate( SoundGroup sg1, SoundGroup sg2 ) { return string.Compare( sg1.name, sg2.name ); } );
  262. MarkDirty();
  263. }
  264. EditorGUILayout.EndHorizontal();
  265. // draw a rect around the selected item
  266. if ( ( selectedGroup >= 0 ) && ( selectedGroup < groups.size ) ) {
  267. EditorGUI.DrawRect( groups[selectedGroup].rect, new Color( 1f, 1f, 1f, 0.06f ) );
  268. }
  269. // finally move the sound groups back into the audio manager
  270. if ( soundGroups.size > 0 ) {
  271. audioManager.soundGroupings = soundGroups.ToArray();
  272. }
  273. // calculate the drop area rect
  274. if ( ( e.type == EventType.Repaint ) && ( groups.size > 0 ) ) {
  275. dropArea.x = groups[0].rect.x;
  276. dropArea.y = groups[0].rect.y;
  277. dropArea.width = groups[0].rect.width;
  278. dropArea.height = ( groups[groups.size-1].rect.y - groups[0].rect.y ) + groups[groups.size-1].rect.height;
  279. }
  280. }
  281. // draw the sound group properties now
  282. DrawSoundGroupProperties();
  283. EndContents();
  284. EditorGUILayout.HelpBox("Create and delete sound groups by clicking + and - respectively. Double click to rename sound groups. Drag and drop sounds from below to the groups above to move them.", MessageType.Info);
  285. }
  286. public class CustomDragData{
  287. public int originalGroupIndex;
  288. public int originalIndex;
  289. public SerializedProperty originalProperty;
  290. }
  291. public class ItemRect {
  292. public ItemRect( int index, Rect rect, SerializedProperty prop ) {
  293. this.index = index;
  294. this.rect = rect;
  295. this.prop = prop;
  296. }
  297. public int index;
  298. public Rect rect;
  299. public SerializedProperty prop;
  300. }
  301. private FastList<ItemRect> items = new FastList<ItemRect>();
  302. /*
  303. -----------------------
  304. CreateStyles()
  305. -----------------------
  306. */
  307. void CreateStyles() {
  308. if ( customDividerStyle == null ) {
  309. customDividerStyle = new GUIStyle( EditorStyles.label );
  310. customDividerStyle.normal.background = MakeTex( 4, 4, new Color( 0.5f, 0.5f, 0.5f, 0.25f ) );
  311. customDividerStyle.margin.right -= 16;
  312. }
  313. }
  314. /*
  315. -----------------------
  316. MakeTex()
  317. -----------------------
  318. */
  319. private Texture2D MakeTex( int width, int height, Color col ) {
  320. Color[] pix = new Color[width*height];
  321. for ( int i = 0; i < pix.Length; i++ )
  322. pix[i] = col;
  323. Texture2D result = new Texture2D(width, height);
  324. result.SetPixels( pix );
  325. result.Apply();
  326. return result;
  327. }
  328. /*
  329. -----------------------
  330. DrawSoundEffects()
  331. -----------------------
  332. */
  333. void DrawSoundEffects( Event e ) {
  334. if ( ( selectedGroup < 0 ) || ( audioManager.soundGroupings.Length == 0 ) || ( selectedGroup >= audioManager.soundGroupings.Length ) ) {
  335. return;
  336. }
  337. if ( e.type == EventType.Repaint ) {
  338. items.Clear();
  339. } else {
  340. CheckStartDrag( e );
  341. }
  342. BeginContents();
  343. if ( DrawHeader( "Sound Effects", true ) ) {
  344. GUILayout.Space(3f);
  345. GUILayout.BeginVertical( GUI.skin.box );
  346. SerializedProperty soundGroupsArray = serializedObject.FindProperty( "soundGroupings" );
  347. SerializedProperty soundGroup = soundGroupsArray.GetArrayElementAtIndex( selectedGroup );
  348. SerializedProperty soundList = soundGroup.FindPropertyRelative( "soundList" );
  349. CreateStyles();
  350. Rect prevRect = new Rect();
  351. if ( soundList.arraySize > 0 ) {
  352. // show all the sounds
  353. for ( int i = 0; i < soundList.arraySize; i++ ) {
  354. EditorGUI.indentLevel = 1;
  355. SerializedProperty soundFX = soundList.GetArrayElementAtIndex( i );
  356. SerializedProperty visToggle = soundFX.FindPropertyRelative( "visibilityToggle" );
  357. EditorGUILayout.BeginHorizontal( customDividerStyle );
  358. {
  359. string soundFXName = soundFX.FindPropertyRelative( "name" ).stringValue;
  360. // save the visibility state
  361. visToggle.boolValue = EditorGUILayout.Foldout( visToggle.boolValue, soundFXName );
  362. // play button
  363. if ( GUILayout.Button( "\u25BA", GUILayout.Width( 17f ), GUILayout.Height( 16f ) ) ) {
  364. if ( AudioManager.IsSoundPlaying( soundFXName ) ) {
  365. AudioManager.StopSound( soundFXName );
  366. } else {
  367. AudioManager.PlaySound( soundFXName );
  368. }
  369. }
  370. }
  371. EditorGUILayout.EndHorizontal();
  372. if ( visToggle.boolValue ) {
  373. EditorGUILayout.PropertyField( soundFX, true );
  374. EditorGUILayout.BeginHorizontal();
  375. GUILayout.FlexibleSpace();
  376. if ( GUILayout.Button( "Delete FX", GUILayout.Width( Screen.width / 3.0f ) ) ) {
  377. if ( EditorUtility.DisplayDialog( "Delete " + soundFX.displayName, "Are you sure?", "Yes", "No!" ) ) {
  378. deleteSoundIdx = i;
  379. }
  380. }
  381. if ( GUILayout.Button( "Duplicate FX", GUILayout.Width( Screen.width / 3.0f ) ) ) {
  382. dupeSoundIdx = i;
  383. }
  384. GUILayout.FlexibleSpace();
  385. EditorGUILayout.EndHorizontal();
  386. GUILayout.Space( 10.0f );
  387. }
  388. if ( e.type == EventType.Repaint ) {
  389. // GetLastRect() is now returning the last rect drawn in the property drawer,
  390. // not the rect used for the entire SoundFX
  391. Rect curRect = prevRect;
  392. curRect.y = prevRect.y + EditorGUIUtility.singleLineHeight;
  393. Rect lastRect = GUILayoutUtility.GetLastRect();
  394. curRect.height = ( lastRect.y + lastRect.height ) - curRect.y;
  395. curRect.width = Screen.width;
  396. items.Add( new ItemRect( i, curRect, soundFX ) );
  397. }
  398. prevRect = GUILayoutUtility.GetLastRect();
  399. }
  400. } else {
  401. EditorGUILayout.LabelField( " " );
  402. }
  403. GUILayout.EndVertical();
  404. GUILayout.Space(3f);
  405. EditorGUILayout.BeginHorizontal();
  406. GUILayout.FlexibleSpace();
  407. if ( GUILayout.Button( "Add FX", GUILayout.Width( 70f ) ) ) {
  408. //soundList.InsertArrayElementAtIndex( soundList.arraySize );
  409. //MarkDirty();
  410. addSound = true;
  411. }
  412. if ( GUILayout.Button( "Sort", GUILayout.Width( 70f ) ) ) {
  413. sortSounds = true;
  414. }
  415. EditorGUILayout.EndHorizontal();
  416. }
  417. EndContents();
  418. UpdateDrag( e );
  419. }
  420. /*
  421. -----------------------
  422. CheckStartDrag()
  423. -----------------------
  424. */
  425. void CheckStartDrag( Event e ) {
  426. if ( ( e.type == EventType.MouseDrag ) && ( e.button == 0 ) ) {
  427. for ( int i = 0; i < items.size; i++ ) {
  428. if ( items[i].rect.Contains( e.mousePosition ) ) {
  429. DragAndDrop.PrepareStartDrag();// reset data
  430. CustomDragData dragData = new CustomDragData();
  431. dragData.originalGroupIndex = selectedGroup;
  432. dragData.originalIndex = items[i].index;
  433. dragData.originalProperty = items[i].prop;
  434. DragAndDrop.SetGenericData( dragDropIdentifier, dragData );
  435. DragAndDrop.objectReferences = new Object[0];
  436. DragAndDrop.StartDrag( dragData.originalProperty.FindPropertyRelative( "name" ).stringValue );
  437. e.Use();
  438. }
  439. }
  440. }
  441. }
  442. /*
  443. -----------------------
  444. FindGroupIndex()
  445. -----------------------
  446. */
  447. int FindGroupIndex( Event e ) {
  448. for ( int i = 0; i < groups.size; i++ ) {
  449. if ( groups[i].rect.Contains( e.mousePosition ) ) {
  450. return i;
  451. }
  452. }
  453. return -1;
  454. }
  455. /*
  456. -----------------------
  457. UpdateDrag()
  458. -----------------------
  459. */
  460. void UpdateDrag( Event e ) {
  461. CustomDragData dragData = DragAndDrop.GetGenericData( dragDropIdentifier ) as CustomDragData;
  462. if ( dragData == null ) {
  463. return;
  464. }
  465. int groupIndex = FindGroupIndex( e );
  466. switch ( e.type ) {
  467. case EventType.DragUpdated:
  468. if ( ( groupIndex >= 0 ) && ( groupIndex != selectedGroup ) ) {
  469. DragAndDrop.visualMode = DragAndDropVisualMode.Move;
  470. } else {
  471. DragAndDrop.visualMode = DragAndDropVisualMode.Rejected;
  472. }
  473. e.Use();
  474. break;
  475. case EventType.Repaint:
  476. if ( ( DragAndDrop.visualMode == DragAndDropVisualMode.None ) ||
  477. ( DragAndDrop.visualMode == DragAndDropVisualMode.Rejected ) ) {
  478. break;
  479. }
  480. if ( groupIndex >= 0 && groupIndex < groups.size ) {
  481. EditorGUI.DrawRect( groups[groupIndex].rect, new Color( 0f, 1f, 0f, 0.1f ) );
  482. }
  483. break;
  484. case EventType.DragPerform:
  485. DragAndDrop.AcceptDrag();
  486. // queue the sound FX move
  487. QueueSoundFXMove( dragData.originalGroupIndex, dragData.originalIndex, groupIndex );
  488. e.Use();
  489. break;
  490. case EventType.MouseUp:
  491. // in case MouseDrag never occurred:
  492. DragAndDrop.PrepareStartDrag();
  493. break;
  494. }
  495. }
  496. /*
  497. -----------------------
  498. QueueSoundFXMove()
  499. -----------------------
  500. */
  501. void QueueSoundFXMove( int origGroupIndex, int origSoundIndex, int newGroupIndex ) {
  502. moveQueued = true;
  503. origGroup = origGroupIndex;
  504. origIndex = origSoundIndex;
  505. moveToGroup = newGroupIndex;
  506. }
  507. /*
  508. -----------------------
  509. DrawHeader()
  510. -----------------------
  511. */
  512. static public bool DrawHeader (string text) { return DrawHeader(text, text, false); }
  513. static public bool DrawHeader (string text, string key) { return DrawHeader(text, key, false); }
  514. static public bool DrawHeader (string text, bool forceOn) { return DrawHeader(text, text, forceOn); }
  515. static public bool DrawHeader( string text, string key, bool forceOn ) {
  516. bool state = EditorPrefs.GetBool(key, true);
  517. GUILayout.Space(3f);
  518. if (!forceOn && !state) GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f);
  519. GUILayout.BeginHorizontal();
  520. GUILayout.Space(3f);
  521. GUI.changed = false;
  522. text = "<b><size=11>" + text + "</size></b>";
  523. if (state) text = "\u25BC " + text;
  524. else text = "\u25B6 " + text;
  525. if (!GUILayout.Toggle(true, text, "dragtab", GUILayout.MinWidth(20f))) state = !state;
  526. if (GUI.changed) EditorPrefs.SetBool(key, state);
  527. GUILayout.Space(2f);
  528. GUILayout.EndHorizontal();
  529. GUI.backgroundColor = Color.white;
  530. if (!forceOn && !state) GUILayout.Space(3f);
  531. return state;
  532. }
  533. /*
  534. -----------------------
  535. BeginContents()
  536. -----------------------
  537. */
  538. static public void BeginContents() {
  539. GUILayout.BeginHorizontal();
  540. GUILayout.Space(4f);
  541. EditorGUILayout.BeginHorizontal(GUILayout.MinHeight(10f));
  542. GUILayout.BeginVertical();
  543. GUILayout.Space(2f);
  544. }
  545. /*
  546. -----------------------
  547. EndContents()
  548. -----------------------
  549. */
  550. static public void EndContents() {
  551. GUILayout.Space(3f);
  552. GUILayout.EndVertical();
  553. EditorGUILayout.EndHorizontal();
  554. GUILayout.Space(3f);
  555. GUILayout.EndHorizontal();
  556. GUILayout.Space(3f);
  557. }
  558. }
  559. } // namespace OVR