void DrawCategories()

in RealityMaterialExplorer/Assets/Oculus/AudioManager/Scripts/Audio/Editor/AudioManagerInspector.cs [147:319]


	void DrawCategories( Event e ) {

		// do any housework before we start drawing
		if ( moveQueued ) {
			// make a temp copy
			List<SoundFX> origSoundList = new List<SoundFX>( audioManager.soundGroupings[origGroup].soundList );
			SoundFX temp = origSoundList[origIndex];
			List<SoundFX> moveToSoundList = new List<SoundFX>( audioManager.soundGroupings[moveToGroup].soundList );
			// add it to the move to group
			moveToSoundList.Add( temp );
			audioManager.soundGroupings[moveToGroup].soundList = moveToSoundList.ToArray();
			// and finally, remove it from the original group
			origSoundList.RemoveAt( origIndex );
			audioManager.soundGroupings[origGroup].soundList = origSoundList.ToArray();
			Debug.Log( "> Moved '" + temp.name + "' from " + "'" + audioManager.soundGroupings[origGroup].name + "' to '" + audioManager.soundGroupings[moveToGroup].name );
			MarkDirty();
			moveQueued = false;
		}
		// switch to the next group
		if ( nextGroup > -1 ) {
			selectedGroup = nextGroup;
			nextGroup = -1;
		}
		// add a sound
		if ( addSound ) {
			List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
			SoundFX soundFX = new SoundFX();
			soundFX.name = audioManager.soundGroupings[selectedGroup].name.ToLower() + "_new_unnamed_sound_fx";
			soundList.Add( soundFX );
			audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
			MarkDirty();
			addSound = false;
		}
		// sort the sounds
		if ( sortSounds ) {
			List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
			soundList.Sort( delegate ( SoundFX sfx1, SoundFX sfx2 ) { return string.Compare( sfx1.name, sfx2.name ); } );
			audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
			MarkDirty();
			sortSounds = false;
		}
		// delete a sound
		if ( deleteSoundIdx > -1 ) {
			List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
			soundList.RemoveAt( deleteSoundIdx );
			audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
			MarkDirty();
			deleteSoundIdx = -1;
		}
		// duplicate a sound
		if ( dupeSoundIdx > -1 ) {
			List<SoundFX> soundList = new List<SoundFX>( audioManager.soundGroupings[selectedGroup].soundList );
			SoundFX origSoundFX = soundList[dupeSoundIdx];
			// clone this soundFX
			string json = JsonUtility.ToJson( origSoundFX );
			SoundFX soundFX = JsonUtility.FromJson<SoundFX>( json );
			soundFX.name += "_duplicated";
			soundList.Insert( dupeSoundIdx + 1, soundFX );
			audioManager.soundGroupings[selectedGroup].soundList = soundList.ToArray();
			MarkDirty();
			dupeSoundIdx = -1;
		}

		if ( e.type == EventType.Repaint ) {
			groups.Clear();
		}

		GUILayout.Space( 6f );
		
		Color defaultColor = GUI.contentColor;
		BeginContents();

		if ( DrawHeader( "Sound FX Groups", true ) ) {
			EditorGUILayout.BeginVertical( GUI.skin.box );
			soundGroups.Clear();
			for ( int i = 0; i < audioManager.soundGroupings.Length; i++ ) {
				soundGroups.Add( audioManager.soundGroupings[i] );
			}
			for ( int i = 0; i < soundGroups.size; i++ ) {
				EditorGUILayout.BeginHorizontal();
				{
					if ( i == selectedGroup ) {
						GUI.contentColor = ( i == editGroup ) ? Color.white : Color.yellow;
					} else {
						GUI.contentColor = defaultColor;
					}
					if ( ( e.type == EventType.KeyDown ) && ( ( e.keyCode == KeyCode.Return ) || ( e.keyCode == KeyCode.KeypadEnter ) ) ) {
						// toggle editing
						if ( editGroup >= 0 ) {
							editGroup = -1;
						}
						Event.current.Use();
					}
					if ( i == editGroup ) {
						soundGroups[i].name = GUILayout.TextField( soundGroups[i].name, GUILayout.MinWidth( Screen.width - 80f ) );
					} else {
						GUILayout.Label( soundGroups[i].name, ( i == selectedGroup ) ? EditorStyles.whiteLabel : EditorStyles.label, GUILayout.ExpandWidth( true ) );
					}
					GUILayout.FlexibleSpace();
					if ( GUILayout.Button( GUIContent.none, "OL Minus", GUILayout.Width(17f) ) ) {	// minus button
						if ( EditorUtility.DisplayDialog( "Delete '" + soundGroups[i].name + "'", "Are you sure you want to delete the selected sound group?", "Continue", "Cancel" ) ) {
							soundGroups.RemoveAt( i );
							MarkDirty();
						}
					}
				}
				EditorGUILayout.EndHorizontal();
				// build a list of items
				Rect lastRect = GUILayoutUtility.GetLastRect();
				if ( e.type == EventType.Repaint ) {
					groups.Add ( new ItemRect( i, lastRect, null ) );
				}
				if ( ( e.type == EventType.MouseDown ) && lastRect.Contains( e.mousePosition ) ) {
					if ( ( i != selectedGroup ) || ( e.clickCount == 2 ) ) {
						nextGroup = i;
						if ( e.clickCount == 2 ) {
							editGroup = i;
						} else if ( editGroup != nextGroup ) {
							editGroup = -1;
						}
						Repaint();
					}
				}
			}
			// add the final plus button
			EditorGUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();
			if ( GUILayout.Button( GUIContent.none, "OL Plus", GUILayout.Width(17f) ) ) {	// plus button
				soundGroups.Add( new SoundGroup( "unnamed sound group" ) );
				selectedGroup = editGroup = soundGroups.size - 1;
				MarkDirty();
			}
			EditorGUILayout.EndHorizontal();
			EditorGUILayout.EndVertical();

			// reset the color
			GUI.contentColor = defaultColor;

			// the sort and import buttons
			EditorGUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();
			if ( GUILayout.Button( "Sort", GUILayout.Width( 70f ) ) ) {
				soundGroups.Sort( delegate( SoundGroup sg1, SoundGroup sg2 ) { return string.Compare( sg1.name, sg2.name ); } );
				MarkDirty();
			}
			EditorGUILayout.EndHorizontal();

			// draw a rect around the selected item
			if ( ( selectedGroup >= 0 ) && ( selectedGroup < groups.size ) ) {
				EditorGUI.DrawRect( groups[selectedGroup].rect, new Color( 1f, 1f, 1f, 0.06f ) );      
			}

			// finally move the sound groups back into the audio manager
			if ( soundGroups.size > 0 ) {
				audioManager.soundGroupings = soundGroups.ToArray();
			}

			// calculate the drop area rect
			if ( ( e.type == EventType.Repaint ) && ( groups.size > 0 ) ) {
				dropArea.x = groups[0].rect.x;
				dropArea.y = groups[0].rect.y;
				dropArea.width = groups[0].rect.width;
				dropArea.height = ( groups[groups.size-1].rect.y - groups[0].rect.y ) + groups[groups.size-1].rect.height;
			}
		}
		// draw the sound group properties now
		DrawSoundGroupProperties();

		EndContents();

		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);

	}