/// <summary>Draws the sub-inspector for an Edition.</summary> /// <param name="DrawRect">The rect in the list display that this Edition has to be drawn in.</param> /// <param name="Index">The index of this Edition in the Track.</param> /// <param name="IsActive">If the Edition is actively selected.</param> /// <param name="IsFocused">If the Edition is in focus.</param> private void DrawEditionInspector(Rect DrawRect, int Index, bool IsActive, bool IsFocused) { //Shifts rect to create border DrawRect.y += 2; //Calculates commonly used spacings float Spacing = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; float LabelWidth = EditorGUIUtility.labelWidth - 20; float FieldPadding = 20f; //Starts counter for current displayed property int PropertyIndex = 0; //Caches serialised properties SerializedProperty CurrentEdition = EditionListDisplay.serializedProperty.GetArrayElementAtIndex(Index); SerializedProperty NameProperty = CurrentEdition.FindPropertyRelative("Name"); SerializedProperty SoundtrackProperty = CurrentEdition.FindPropertyRelative("Soundtrack"); SerializedProperty SoundtrackVolumeProperty = CurrentEdition.FindPropertyRelative("SoundtrackVolume"); SerializedProperty TransitionSoundProperty = CurrentEdition.FindPropertyRelative("TransitionSound"); SerializedProperty TransitionVolumeProperty = CurrentEdition.FindPropertyRelative("TransitionVolume"); SerializedProperty PlaybackProperty = CurrentEdition.FindPropertyRelative("KeepPlaybackTime"); SerializedProperty FadeProperty = CurrentEdition.FindPropertyRelative("FadeLength"); //Draws a property with a custom style Action <SerializedProperty, string, string, GUIStyle> DrawPropertyStyled = (SerializedProperty Property, string PropertyName, string Tooltip, GUIStyle TextStyle) => { //Draws label EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip), TextStyle); //Draws property field EditorGUI.PropertyField(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property, GUIContent.none); //Increments property counter PropertyIndex++; }; //Draws a slider for a volume property Action <SerializedProperty, string, string> DrawVolumeSlider = (SerializedProperty Property, string PropertyName, string Tooltip) => { //Draws label EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip)); //Draws the slider Property.floatValue = EditorGUI.Slider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property.floatValue, 0, 1f); //Increments property counter PropertyIndex++; }; //Draws a property Action <SerializedProperty, string, string> DrawProperty = (SerializedProperty Property, string PropertyName, string Tooltip) => { DrawPropertyStyled(Property, PropertyName, Tooltip, EditorStyles.label); }; //Gets and draws edition name string Name = NameProperty.stringValue; if (string.IsNullOrEmpty(Name.Trim())) { Name = "Untitled"; } EditorGUI.LabelField(new Rect(DrawRect.x, DrawRect.y, DrawRect.width - 90, EditorGUIUtility.singleLineHeight), Name, (TrackInstance.Editions[Index].Soundtrack == null && TrackInstance.CollapseEditions ? InvalidBoldStyle : EditorStyles.boldLabel)); //Draws main edition if it is the first edition if (Index == 0) { EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - 90, DrawRect.y, 70, EditorGUIUtility.singleLineHeight), "Main Edition", EditorStyles.miniLabel); } //Draws sountrack length if (TrackInstance.Editions[Index].Soundtrack != null) { EditorGUI.LabelField(new Rect((DrawRect.x + DrawRect.width) / 2 - 40, DrawRect.y, 80, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(TrackInstance.Editions[Index].Soundtrack.length), CenteredMiniLabel); } //Displays basic properties if uncollapsed if (!TrackInstance.CollapseEditions) { DrawProperty(NameProperty, "Edition Name", "(Optional) The name of the Edition."); DrawPropertyStyled(SoundtrackProperty, "Soundtrack", "The AudioClip containing the soundtrack for this Edition.", (TrackInstance.Editions[Index].Soundtrack == null ? InvalidStyle : EditorStyles.label)); //Shows full properties if the sountrack is not null if (TrackInstance.Editions[Index].Soundtrack != null) { DrawVolumeSlider(SoundtrackVolumeProperty, "Soundtrack Volume", "The volume of the soundtrack in this Edition."); DrawProperty(TransitionSoundProperty, "Transition Sound", "(Optional) The AudioClip for the transition sound to be played when switching to this Edition of the Track."); //Displays transiton sound properties if (TrackInstance.Editions[Index].TransitionSound != null) { EditorGUI.LabelField(new Rect(DrawRect.x + 96, PropertyIndex * Spacing + DrawRect.y, LabelWidth - 96, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(TrackInstance.Editions[Index].TransitionSound.length), CenteredMiniLabel); DrawVolumeSlider(TransitionVolumeProperty, "Transition Volume", "The volume of the transition sound to this Edition."); } DrawProperty(PlaybackProperty, "Keep Playback Time", "Whether to play the soundtrack from the beginning when switching to this Edition or whether to retain the playback time from the previous Edition."); DrawProperty(FadeProperty, "Fade Duration", "The duration of the cross-fade when switching to this Edition."); FadeProperty.floatValue = Mathf.Max(0, FadeProperty.floatValue); } else { //Displays error if no soundtrack is selected EditorGUI.HelpBox(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y + 2f, DrawRect.width - FieldPadding, 30), "Soundtrack required. Please assign an AudioClip to this Edition.", MessageType.Error); } } }
/// <summary>Draws the sub-inspector for an SFXLayer.</summary> /// <param name="DrawRect">The rect in the list display that this SFXLayer has to be drawn in.</param> /// <param name="Index">The index of this SFXLayer in the Track.</param> /// <param name="IsActive">If the SFXLayer is actively selected.</param> /// <param name="IsFocused">If the SFXLayer is in focus.</param> private void DrawSFXLayerInspector(Rect DrawRect, int Index, bool IsActive, bool IsFocused) { //Shifts rect to create border DrawRect.y += 2; //Calculates commonly used spacings float Spacing = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; float LabelWidth = EditorGUIUtility.labelWidth - 20; float FieldPadding = 20f; //Starts counter for current displayed property int PropertyIndex = 0; //Caches serialised properties SerializedProperty CurrentSFXLayer = SFXLayerListDisplay.serializedProperty.GetArrayElementAtIndex(Index); SerializedProperty NameProperty = CurrentSFXLayer.FindPropertyRelative("LayerName"); SerializedProperty SFXProperty = CurrentSFXLayer.FindPropertyRelative("SFX"); SerializedProperty RandomizeVolumeProperty = CurrentSFXLayer.FindPropertyRelative("RandomizeVolume"); SerializedProperty FixedVolumeProperty = CurrentSFXLayer.FindPropertyRelative("FixedVolume"); SerializedProperty MinVolumeProperty = CurrentSFXLayer.FindPropertyRelative("MinVolume"); SerializedProperty MaxVolumeProperty = CurrentSFXLayer.FindPropertyRelative("MaxVolume"); SerializedProperty RandomizePitchProperty = CurrentSFXLayer.FindPropertyRelative("RandomizePitch"); SerializedProperty FixedPitchProperty = CurrentSFXLayer.FindPropertyRelative("FixedPitch"); SerializedProperty MinPitchProperty = CurrentSFXLayer.FindPropertyRelative("MinPitch"); SerializedProperty MaxPitchProperty = CurrentSFXLayer.FindPropertyRelative("MaxPitch"); SerializedProperty DelayProperty = CurrentSFXLayer.FindPropertyRelative("DelaySFX"); SerializedProperty RandomizeDelayProperty = CurrentSFXLayer.FindPropertyRelative("RandomizeDelay"); SerializedProperty FixedDelayProperty = CurrentSFXLayer.FindPropertyRelative("FixedDelayTime"); SerializedProperty MinDelayProperty = CurrentSFXLayer.FindPropertyRelative("MinDelayTime"); SerializedProperty MaxDelayProperty = CurrentSFXLayer.FindPropertyRelative("MaxDelayTime"); SerializedProperty PriorityProperty = CurrentSFXLayer.FindPropertyRelative("Priority"); SerializedProperty StereoProperty = CurrentSFXLayer.FindPropertyRelative("StereoPan"); SerializedProperty SpatialProperty = CurrentSFXLayer.FindPropertyRelative("SpatialBlend"); SerializedProperty ReverbProperty = CurrentSFXLayer.FindPropertyRelative("ReverbZoneMix"); SerializedProperty BypassEffectsProperty = CurrentSFXLayer.FindPropertyRelative("BypassEffects"); SerializedProperty BypassReverbProperty = CurrentSFXLayer.FindPropertyRelative("BypassReverbZones"); SerializedProperty MuteProperty = CurrentSFXLayer.FindPropertyRelative("Mute"); //Draws a property with a custom style Action <SerializedProperty, string, string, GUIStyle> DrawPropertyStyled = (SerializedProperty Property, string PropertyName, string Tooltip, GUIStyle TextStyle) => { //Draws label EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip), TextStyle); //Draws property field EditorGUI.PropertyField(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property, GUIContent.none); //Increments property counter PropertyIndex++; }; //Draws a slider for a property Action <SerializedProperty, string, string, float, float> DrawSlider = (SerializedProperty Property, string PropertyName, string Tooltip, float MinLim, float MaxLim) => { //Draws label EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip)); //Draws the slider Property.floatValue = EditorGUI.Slider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property.floatValue, MinLim, MaxLim); //Increments property counter PropertyIndex++; }; //Draws an int slider for a property Action <SerializedProperty, string, string, int, int> DrawIntSlider = (SerializedProperty Property, string PropertyName, string Tooltip, int MinLim, int MaxLim) => { //Draws label EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip)); //Draws the slider Property.intValue = (int)EditorGUI.Slider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), Property.intValue, MinLim, MaxLim); //Increments property counter PropertyIndex++; }; //Draws a min max slider for a property Action <SerializedProperty, SerializedProperty, string, string, float, float> DrawMinMaxSlider = (SerializedProperty PropertyLeft, SerializedProperty PropertyRight, string PropertyName, string Tooltip, float MinLim, float MaxLim) => { //Draws label EditorGUI.LabelField(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y, LabelWidth, EditorGUIUtility.singleLineHeight), new GUIContent(PropertyName, Tooltip)); //Draws the slider AMPEditorFields.MinMaxSlider(new Rect(DrawRect.x + LabelWidth, (PropertyIndex + 1) * Spacing + DrawRect.y, DrawRect.width - LabelWidth - FieldPadding, EditorGUIUtility.singleLineHeight), GUIContent.none, PropertyLeft, PropertyRight, MinLim, MaxLim); //Increments property counter PropertyIndex++; }; //Draws a property Action <SerializedProperty, string, string> DrawProperty = (SerializedProperty Property, string PropertyName, string Tooltip) => { DrawPropertyStyled(Property, PropertyName, Tooltip, EditorStyles.label); }; //Gets and draws SFXLayer name string Name = NameProperty.stringValue; if (string.IsNullOrEmpty(Name.Trim())) { Name = "Untitled"; } EditorGUI.LabelField(new Rect(DrawRect.x, DrawRect.y, DrawRect.width - 90, EditorGUIUtility.singleLineHeight), Name, (SFXObjectInstance.SFXLayers[Index].SFX == null && SFXObjectInstance.CollapseEditions ? InvalidBoldStyle : EditorStyles.boldLabel)); //Draws SFX length if (SFXObjectInstance.SFXLayers[Index].SFX != null) { EditorGUI.LabelField(new Rect((DrawRect.x + DrawRect.width) / 2 - 40, DrawRect.y, 80, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(SFXObjectInstance.SFXLayers[Index].SFX.length), CenteredMiniLabel); } //Displays basic properties if uncollapsed if (!SFXObjectInstance.CollapseEditions) { DrawProperty(NameProperty, "Layer Name", "(Optional) The name of the Edition."); DrawPropertyStyled(SFXProperty, "SFX", "The audio to be played in this SFXLayer.", (SFXObjectInstance.SFXLayers[Index].SFX == null ? InvalidStyle : EditorStyles.label)); //Shows full properties if the SFX is not null if (SFXObjectInstance.SFXLayers[Index].SFX != null) { //Volume properties DrawProperty(RandomizeVolumeProperty, "Randomize Volume", "If the volume of the sound should be randomised."); if (SFXObjectInstance.SFXLayers[Index].RandomizeVolume) { DrawMinMaxSlider(MinVolumeProperty, MaxVolumeProperty, "Volume", "The range of values that the volume of the SFXLayer can be.", 0, 1); EditorGUI.LabelField(new Rect(DrawRect.x + 82, PropertyIndex * Spacing + DrawRect.y, LabelWidth - 82, EditorGUIUtility.singleLineHeight), NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MinVolume, 2).ToString() + " - " + NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MaxVolume, 2).ToString(), CenteredMiniLabel); } else { DrawSlider(FixedVolumeProperty, "Volume", "The volume of the SFXLayer.", 0, 1); } //Pitch properties DrawProperty(RandomizePitchProperty, "Randomize Pitch", "If the pitch of the sound should be randomised."); if (SFXObjectInstance.SFXLayers[Index].RandomizePitch) { DrawMinMaxSlider(MinPitchProperty, MaxPitchProperty, "Pitch", "The range of values that the pitch of the SFXLayer can be.", 0, 3); EditorGUI.LabelField(new Rect(DrawRect.x + 82, PropertyIndex * Spacing + DrawRect.y, LabelWidth - 82, EditorGUIUtility.singleLineHeight), NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MinPitch, 2).ToString() + " - " + NumberManipulation.DecimalPlaces(SFXObjectInstance.SFXLayers[Index].MaxPitch, 2).ToString(), CenteredMiniLabel); } else { DrawSlider(FixedPitchProperty, "Pitch", "The pitch of the SFXLayer.", 0, 3); } //Delay properties DrawProperty(DelayProperty, "Delay", "If there should be a delay before playing this SFXLayer."); if (SFXObjectInstance.SFXLayers[Index].DelaySFX) { DrawProperty(RandomizeDelayProperty, "Randomize Delay", "If the delay time should be randomized."); if (SFXObjectInstance.SFXLayers[Index].RandomizeDelay) { DrawProperty(MinDelayProperty, "Minimum Delay", "Minimum duration of the delay."); DrawProperty(MaxDelayProperty, "Maximum Delay", "Maximum duration of the delay."); MinDelayProperty.floatValue = Mathf.Max(0, MinDelayProperty.floatValue); MaxDelayProperty.floatValue = Mathf.Max(SFXObjectInstance.SFXLayers[Index].MinDelayTime, MaxDelayProperty.floatValue); } else { DrawProperty(FixedDelayProperty, "Delay Duration", "Duration of the delay."); FixedDelayProperty.floatValue = Mathf.Max(0, FixedDelayProperty.floatValue); } } //Other properties DrawProperty(MuteProperty, "Mute", "Mutes the sound."); DrawProperty(BypassEffectsProperty, "Bypass Effects", "Bypass any applied effects on the SFXLayer."); DrawProperty(BypassReverbProperty, "Bypass Reverb Zones", "Bypasses any reverb zones"); DrawIntSlider(PriorityProperty, "Priority", "The priority of the SFXLayer.", 0, 256); EditorGUI.LabelField(new Rect(DrawRect.x + LabelWidth, PropertyIndex * Spacing + DrawRect.y + 8, 30, EditorGUIUtility.singleLineHeight), "High", LeftMiniLabel); EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - FieldPadding - 95, PropertyIndex * Spacing + DrawRect.y + 8, 40, EditorGUIUtility.singleLineHeight), "Low", RightMiniLabel); DrawSlider(StereoProperty, "Stero Pan", "Pans a playing sound in a stereo way (left or right). This only applies to sounds that are Mono or Stereo.", -1, 1); EditorGUI.LabelField(new Rect(DrawRect.x + LabelWidth, PropertyIndex * Spacing + DrawRect.y + 8, 25, EditorGUIUtility.singleLineHeight), "Left", LeftMiniLabel); EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - FieldPadding - 95, PropertyIndex * Spacing + DrawRect.y + 8, 40, EditorGUIUtility.singleLineHeight), "Right", RightMiniLabel); DrawSlider(SpatialProperty, "Spatial Blend", "Sets how much this SFXLayer is affected by 3D spatialisation calculations. 0.0 makes the sound full 2D, 1.0 makes it full 3D.", 0, 1); EditorGUI.LabelField(new Rect(DrawRect.x + LabelWidth, PropertyIndex * Spacing + DrawRect.y + 8, 25, EditorGUIUtility.singleLineHeight), "2D", LeftMiniLabel); EditorGUI.LabelField(new Rect(DrawRect.x + DrawRect.width - FieldPadding - 95, PropertyIndex * Spacing + DrawRect.y + 8, 40, EditorGUIUtility.singleLineHeight), "3D", RightMiniLabel); DrawSlider(ReverbProperty, "Reverb Zone Mix", "The amount by which the signal from the AudioSource will be mixed into the global reverb associated with the Reverb Zones.", 0, 1.1f); } else { //Displays error if no SFX is selected EditorGUI.HelpBox(new Rect(DrawRect.x, (PropertyIndex + 1) * Spacing + DrawRect.y + 2f, DrawRect.width - FieldPadding, 30), "SFX required. Please assign an AudioClip to this SFXLayer.", MessageType.Error); } } }
//Draws Track inspector public override void OnInspectorGUI() { //Updates the Track object serializedObject.Update(); CreateStyles(); //Banner display Rect BannerRect = GUILayoutUtility.GetRect(0.0f, 0.0f); BannerRect.height = Screen.width * 250 / 1600; GUILayout.Space(BannerRect.height); GUI.Label(BannerRect, Banner); //Displays Track name GUILayout.BeginVertical(BackgroundStyles[0], GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.PropertyField(TrackName, new GUIContent("Track Name", "(Optional) The name of the Track.")); GUILayout.EndVertical(); //Draws Intro field GUILayout.BeginVertical(BackgroundStyles[1], GUILayout.Height((TrackInstance.Intro != null ? 3 : 1) * EditorGUIUtility.singleLineHeight)); Rect IntroRect = EditorGUILayout.GetControlRect(); EditorGUI.LabelField(new Rect(IntroRect.x, IntroRect.y, EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight), new GUIContent("Intro Audio", "(Optional) The intro audio to be played before looping the main Edition.")); EditorGUI.PropertyField(new Rect(IntroRect.x + EditorGUIUtility.labelWidth, IntroRect.y, IntroRect.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight), Intro, GUIContent.none); //Full intro details if (TrackInstance.Intro != null) { //Draws intro duration EditorGUI.LabelField(new Rect(IntroRect.x + 82, IntroRect.y, EditorGUIUtility.labelWidth - 20 - 82, EditorGUIUtility.singleLineHeight), StringFormatting.FormatTime(TrackInstance.Intro.length), CenteredMiniLabel); //Draws Volume slider EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Intro Volume", "The volume of the intro audio."), GUILayout.Width(EditorGUIUtility.labelWidth - 4)); IntroVolume.floatValue = EditorGUILayout.Slider(IntroVolume.floatValue, 0, 1); EditorGUILayout.EndHorizontal(); //Draws overlap slider EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Intro Overlap Duration", "Duration of the overlap between the end of the intro and the start of the first Edition."), GUILayout.Width(EditorGUIUtility.labelWidth - 4)); IntroOverlap.floatValue = EditorGUILayout.Slider(IntroOverlap.floatValue, 0, TrackInstance.Intro.length); EditorGUILayout.EndHorizontal(); } GUILayout.EndVertical(); //Preview GUILayout.BeginVertical(BackgroundStyles[0], GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.BeginHorizontal(); GUI.enabled = MusicManager.Main; EditorGUILayout.LabelField(new GUIContent("Preview", "Preview options for the Track. Only available at runtime.")); if (GUILayout.Button(new GUIContent("Play", "Plays the Track."))) { MusicManager.Main.Play(TrackInstance); } GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); //Adds new Edition if the list is empty if (TrackInstance.Editions.Length == 0) { TrackInstance.Editions = new Edition[1]; TrackInstance.Editions[0].SoundtrackVolume = 1f; TrackInstance.Editions[0].TransitionVolume = 1f; } //Enables Edition removal button if more than one is present EditionListDisplay.displayRemove = TrackInstance.Editions.Length > 1; //Draws list and updates Track EditionListDisplay.DoLayoutList(); serializedObject.ApplyModifiedProperties(); }