/// <summary> /// Draw a variable setting field depending on the passed in category. /// </summary> private void DrawAreaSetting(SerializedProperty inAreaSettingsProperty, EditorHelper.VariableRect inSettingsRect, AreaSettingsCategory inCategory) { switch (inCategory) { case AreaSettingsCategory.Speed: DrawSpeedSetting(inAreaSettingsProperty, inSettingsRect); break; case AreaSettingsCategory.AnimationTriggerName: DrawAnimationTriggerNameSetting(inAreaSettingsProperty, inSettingsRect); break; default: break; } }
/// <summary> /// Draw a speed setting field in the passed in rect. /// </summary> private void DrawSpeedSetting(SerializedProperty inAreaSettingsProperty, EditorHelper.VariableRect inSettingsRect) { SerializedProperty speedProperty = inAreaSettingsProperty.FindPropertyRelative(nameof(NavTileAgent.AreaSettings.Speed)); // Draw speed override checkbox. bool useCustomSpeed = EditorGUI.Toggle(inSettingsRect.MiniPrefix, speedProperty.floatValue != -1); if (useCustomSpeed && speedProperty.floatValue == -1) { speedProperty.floatValue = Target.Speed; } // Draw speed input field. using (new EditorGUI.DisabledScope(!useCustomSpeed)) { float inputSpeed = EditorGUI.FloatField(inSettingsRect.FlexibleSuffix, useCustomSpeed ? speedProperty.floatValue : Target.Speed); speedProperty.floatValue = useCustomSpeed ? Mathf.Max(0, inputSpeed) : -1; } }
/// <summary> /// Initialize the rects required to display the reorderable list of areas in the area mask, along with a rect for a variable setting. /// </summary> private void GetAreaSettingsListRects(Rect inRect, out Rect outMaskIDRect, out Rect outColorRect, out Rect outAreaNameRect, out EditorHelper.VariableRect outSettingsRect) { // ID & color rect. float maskIDWidth = inRect.height * 1.25f; float colorWidth = inRect.height; // Settings rect. float settingsWidth = inRect.width - EditorGUIUtility.labelWidth + 6; // perfect align :^) // Flexible area name label. float remainingWidth = inRect.width - maskIDWidth - colorWidth - settingsWidth; float padding = 4; float areaNameWidth = remainingWidth - padding; float x = inRect.x; outMaskIDRect = new Rect(x, inRect.y, maskIDWidth, inRect.height); x += maskIDWidth; outColorRect = new Rect(x, inRect.y, colorWidth, inRect.height); x += colorWidth; outAreaNameRect = new Rect(x + padding, inRect.y, areaNameWidth, inRect.height); x += areaNameWidth + padding; outSettingsRect = new EditorHelper.VariableRect(new Rect(x, inRect.y, settingsWidth, inRect.height)); }
/// <summary> /// Draw an animation setting field in the passed in rect. /// </summary> private void DrawAnimationTriggerNameSetting(SerializedProperty inAreaSettingsProperty, EditorHelper.VariableRect inSettingsRect) { SerializedProperty animationTriggerNameProperty = inAreaSettingsProperty.FindPropertyRelative(nameof(NavTileAgent.AreaSettings.AnimationTriggerName)); int selectedIndex = Mathf.Max(0, Array.FindIndex(_animationTriggers, x => string.Equals(x.text, animationTriggerNameProperty.stringValue))); if (selectedIndex == 0 && !string.IsNullOrEmpty(animationTriggerNameProperty.stringValue)) { animationTriggerNameProperty.stringValue = string.Empty; } EditorGUI.BeginChangeCheck(); int newIndex = 0; using (new EditorGUI.DisabledScope(_animatorProperty.objectReferenceValue == null)) { newIndex = EditorGUI.Popup(inSettingsRect.Full, GUIContent.none, selectedIndex, _animationTriggers); } if (EditorGUI.EndChangeCheck()) { animationTriggerNameProperty.stringValue = _animationTriggers[newIndex].text; } }