Fix project cache in editor to use invariant culture when converting numbers

This commit is contained in:
Wojtek Figat
2024-05-30 17:22:30 +02:00
parent 3f3df090f4
commit 5c23f4ac09
11 changed files with 122 additions and 78 deletions

View File

@@ -38,15 +38,15 @@ namespace FlaxEditor.CustomEditors.Dedicated
_gizmoMode = new ClothPaintingGizmoMode(); _gizmoMode = new ClothPaintingGizmoMode();
var projectCache = Editor.Instance.ProjectCache; var projectCache = Editor.Instance.ProjectCache;
if (projectCache.TryGetCustomData("ClothGizmoPaintValue", out var cachedPaintValue)) if (projectCache.TryGetCustomData("ClothGizmoPaintValue", out string cachedPaintValue))
_gizmoMode.PaintValue = JsonSerializer.Deserialize<float>(cachedPaintValue); _gizmoMode.PaintValue = JsonSerializer.Deserialize<float>(cachedPaintValue);
if (projectCache.TryGetCustomData("ClothGizmoContinuousPaint", out var cachedContinuousPaint)) if (projectCache.TryGetCustomData("ClothGizmoContinuousPaint", out string cachedContinuousPaint))
_gizmoMode.ContinuousPaint = JsonSerializer.Deserialize<bool>(cachedContinuousPaint); _gizmoMode.ContinuousPaint = JsonSerializer.Deserialize<bool>(cachedContinuousPaint);
if (projectCache.TryGetCustomData("ClothGizmoBrushFalloff", out var cachedBrushFalloff)) if (projectCache.TryGetCustomData("ClothGizmoBrushFalloff", out string cachedBrushFalloff))
_gizmoMode.BrushFalloff = JsonSerializer.Deserialize<float>(cachedBrushFalloff); _gizmoMode.BrushFalloff = JsonSerializer.Deserialize<float>(cachedBrushFalloff);
if (projectCache.TryGetCustomData("ClothGizmoBrushSize", out var cachedBrushSize)) if (projectCache.TryGetCustomData("ClothGizmoBrushSize", out string cachedBrushSize))
_gizmoMode.BrushSize = JsonSerializer.Deserialize<float>(cachedBrushSize); _gizmoMode.BrushSize = JsonSerializer.Deserialize<float>(cachedBrushSize);
if (projectCache.TryGetCustomData("ClothGizmoBrushStrength", out var cachedBrushStrength)) if (projectCache.TryGetCustomData("ClothGizmoBrushStrength", out string cachedBrushStrength))
_gizmoMode.BrushStrength = JsonSerializer.Deserialize<float>(cachedBrushStrength); _gizmoMode.BrushStrength = JsonSerializer.Deserialize<float>(cachedBrushStrength);
gizmos.AddMode(_gizmoMode); gizmos.AddMode(_gizmoMode);

View File

@@ -330,7 +330,7 @@ namespace FlaxEditor
} }
case GeneralOptions.StartupSceneModes.LastOpened: case GeneralOptions.StartupSceneModes.LastOpened:
{ {
if (ProjectCache.TryGetCustomData(ProjectDataLastScene, out var lastSceneIdName)) if (ProjectCache.TryGetCustomData(ProjectDataLastScene, out string lastSceneIdName))
{ {
var lastScenes = JsonSerializer.Deserialize<Guid[]>(lastSceneIdName); var lastScenes = JsonSerializer.Deserialize<Guid[]>(lastSceneIdName);
foreach (var scene in lastScenes) foreach (var scene in lastScenes)
@@ -442,7 +442,7 @@ namespace FlaxEditor
} }
case GeneralOptions.StartupSceneModes.LastOpened: case GeneralOptions.StartupSceneModes.LastOpened:
{ {
if (ProjectCache.TryGetCustomData(ProjectDataLastScene, out var lastSceneIdName)) if (ProjectCache.TryGetCustomData(ProjectDataLastScene, out string lastSceneIdName))
{ {
var lastScenes = JsonSerializer.Deserialize<Guid[]>(lastSceneIdName); var lastScenes = JsonSerializer.Deserialize<Guid[]>(lastSceneIdName);
foreach (var sceneId in lastScenes) foreach (var sceneId in lastScenes)
@@ -459,7 +459,7 @@ namespace FlaxEditor
} }
// Restore view // Restore view
if (ProjectCache.TryGetCustomData(ProjectDataLastSceneSpawn, out var lastSceneSpawnName)) if (ProjectCache.TryGetCustomData(ProjectDataLastSceneSpawn, out string lastSceneSpawnName))
Windows.EditWin.Viewport.ViewRay = JsonSerializer.Deserialize<Ray>(lastSceneSpawnName); Windows.EditWin.Viewport.ViewRay = JsonSerializer.Deserialize<Ray>(lastSceneSpawnName);
} }
break; break;

View File

@@ -119,10 +119,8 @@ namespace FlaxEditor.GUI.Dialogs
_onClosed = pickerClosed; _onClosed = pickerClosed;
// Get saved colors if they exist // Get saved colors if they exist
if (Editor.Instance.ProjectCache.TryGetCustomData("ColorPickerSavedColors", out var savedColors)) if (Editor.Instance.ProjectCache.TryGetCustomData("ColorPickerSavedColors", out string savedColors))
{
_savedColors = JsonSerializer.Deserialize<List<Color>>(savedColors); _savedColors = JsonSerializer.Deserialize<List<Color>>(savedColors);
}
// Selector // Selector
_cSelector = new ColorSelectorWithSliders(180, 18) _cSelector = new ColorSelectorWithSliders(180, 18)

View File

@@ -2,7 +2,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.IO; using System.IO;
using System.Runtime.CompilerServices;
using FlaxEngine; using FlaxEngine;
namespace FlaxEditor.Modules namespace FlaxEditor.Modules
@@ -119,6 +121,30 @@ namespace FlaxEditor.Modules
return _customData.TryGetValue(key, out value); return _customData.TryGetValue(key, out value);
} }
/// <summary>
/// Tries to get the custom data by the key.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value" /> parameter. This parameter is passed uninitialized.</param>
/// <returns>The custom data.</returns>
public bool TryGetCustomData(string key, out bool value)
{
value = false;
return _customData.TryGetValue(key, out var valueStr) && bool.TryParse(valueStr, out value);
}
/// <summary>
/// Tries to get the custom data by the key.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">When this method returns, contains the value associated with the specified key, if the key is found; otherwise, the default value for the type of the <paramref name="value" /> parameter. This parameter is passed uninitialized.</param>
/// <returns>The custom data.</returns>
public bool TryGetCustomData(string key, out float value)
{
value = 0.0f;
return _customData.TryGetValue(key, out var valueStr) && float.TryParse(valueStr, out value);
}
/// <summary> /// <summary>
/// Sets the custom data. /// Sets the custom data.
/// </summary> /// </summary>
@@ -130,6 +156,28 @@ namespace FlaxEditor.Modules
_isDirty = true; _isDirty = true;
} }
/// <summary>
/// Sets the custom data.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetCustomData(string key, bool value)
{
SetCustomData(key, value.ToString());
}
/// <summary>
/// Sets the custom data.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="value">The value.</param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetCustomData(string key, float value)
{
SetCustomData(key, value.ToString(CultureInfo.InvariantCulture));
}
/// <summary> /// <summary>
/// Removes the custom data. /// Removes the custom data.
/// </summary> /// </summary>

View File

@@ -511,11 +511,11 @@ namespace FlaxEditor.Modules
{ {
var bounds = node["Bounds"]; var bounds = node["Bounds"];
var isMaximizedText = bounds.GetAttribute("IsMaximized"); var isMaximizedText = bounds.GetAttribute("IsMaximized");
if (!string.IsNullOrEmpty(isMaximizedText)) if (!string.IsNullOrEmpty(isMaximizedText) && bool.TryParse(isMaximizedText, out var tmpBool))
isMaximized = bool.Parse(isMaximizedText); isMaximized = tmpBool;
var isMinimizedText = bounds.GetAttribute("IsMinimized"); var isMinimizedText = bounds.GetAttribute("IsMinimized");
if (!string.IsNullOrEmpty(isMinimizedText)) if (!string.IsNullOrEmpty(isMinimizedText) && bool.TryParse(isMinimizedText, out tmpBool))
isMinimized = bool.Parse(isMinimizedText); isMinimized = tmpBool;
float x = float.Parse(bounds.GetAttribute("X"), CultureInfo.InvariantCulture); float x = float.Parse(bounds.GetAttribute("X"), CultureInfo.InvariantCulture);
float y = float.Parse(bounds.GetAttribute("Y"), CultureInfo.InvariantCulture); float y = float.Parse(bounds.GetAttribute("Y"), CultureInfo.InvariantCulture);
float width = float.Parse(bounds.GetAttribute("Width"), CultureInfo.InvariantCulture); float width = float.Parse(bounds.GetAttribute("Width"), CultureInfo.InvariantCulture);

View File

@@ -137,19 +137,19 @@ namespace FlaxEditor.Viewport
if (useProjectCache) if (useProjectCache)
{ {
// Initialize snapping enabled from cached values // Initialize snapping enabled from cached values
if (editor.ProjectCache.TryGetCustomData("TranslateSnapState", out var cachedState)) if (editor.ProjectCache.TryGetCustomData("TranslateSnapState", out bool cachedBool))
transformGizmo.TranslationSnapEnable = bool.Parse(cachedState); transformGizmo.TranslationSnapEnable = cachedBool;
if (editor.ProjectCache.TryGetCustomData("RotationSnapState", out cachedState)) if (editor.ProjectCache.TryGetCustomData("RotationSnapState", out cachedBool))
transformGizmo.RotationSnapEnabled = bool.Parse(cachedState); transformGizmo.RotationSnapEnabled = cachedBool;
if (editor.ProjectCache.TryGetCustomData("ScaleSnapState", out cachedState)) if (editor.ProjectCache.TryGetCustomData("ScaleSnapState", out cachedBool))
transformGizmo.ScaleSnapEnabled = bool.Parse(cachedState); transformGizmo.ScaleSnapEnabled = cachedBool;
if (editor.ProjectCache.TryGetCustomData("TranslateSnapValue", out cachedState)) if (editor.ProjectCache.TryGetCustomData("TranslateSnapValue", out float cachedFloat))
transformGizmo.TranslationSnapValue = float.Parse(cachedState); transformGizmo.TranslationSnapValue = cachedFloat;
if (editor.ProjectCache.TryGetCustomData("RotationSnapValue", out cachedState)) if (editor.ProjectCache.TryGetCustomData("RotationSnapValue", out cachedFloat))
transformGizmo.RotationSnapValue = float.Parse(cachedState); transformGizmo.RotationSnapValue = cachedFloat;
if (editor.ProjectCache.TryGetCustomData("ScaleSnapValue", out cachedState)) if (editor.ProjectCache.TryGetCustomData("ScaleSnapValue", out cachedFloat))
transformGizmo.ScaleSnapValue = float.Parse(cachedState); transformGizmo.ScaleSnapValue = cachedFloat;
if (editor.ProjectCache.TryGetCustomData("TransformSpaceState", out cachedState) && Enum.TryParse(cachedState, out TransformGizmoBase.TransformSpace space)) if (editor.ProjectCache.TryGetCustomData("TransformSpaceState", out string cachedText) && Enum.TryParse(cachedText, out TransformGizmoBase.TransformSpace space))
transformGizmo.ActiveTransformSpace = space; transformGizmo.ActiveTransformSpace = space;
} }
@@ -181,7 +181,7 @@ namespace FlaxEditor.Viewport
{ {
transformGizmo.ScaleSnapEnabled = !transformGizmo.ScaleSnapEnabled; transformGizmo.ScaleSnapEnabled = !transformGizmo.ScaleSnapEnabled;
if (useProjectCache) if (useProjectCache)
editor.ProjectCache.SetCustomData("ScaleSnapState", transformGizmo.ScaleSnapEnabled.ToString()); editor.ProjectCache.SetCustomData("ScaleSnapState", transformGizmo.ScaleSnapEnabled);
}; };
var scaleSnappingCM = new ContextMenu(); var scaleSnappingCM = new ContextMenu();
var scaleSnapping = new ViewportWidgetButton(transformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM) var scaleSnapping = new ViewportWidgetButton(transformGizmo.ScaleSnapValue.ToString(), SpriteHandle.Invalid, scaleSnappingCM)
@@ -200,7 +200,7 @@ namespace FlaxEditor.Viewport
transformGizmo.ScaleSnapValue = v; transformGizmo.ScaleSnapValue = v;
scaleSnapping.Text = v.ToString(); scaleSnapping.Text = v.ToString();
if (useProjectCache) if (useProjectCache)
editor.ProjectCache.SetCustomData("ScaleSnapValue", transformGizmo.ScaleSnapValue.ToString("N")); editor.ProjectCache.SetCustomData("ScaleSnapValue", transformGizmo.ScaleSnapValue);
}; };
scaleSnappingCM.VisibleChanged += control => scaleSnappingCM.VisibleChanged += control =>
{ {
@@ -231,7 +231,7 @@ namespace FlaxEditor.Viewport
{ {
transformGizmo.RotationSnapEnabled = !transformGizmo.RotationSnapEnabled; transformGizmo.RotationSnapEnabled = !transformGizmo.RotationSnapEnabled;
if (useProjectCache) if (useProjectCache)
editor.ProjectCache.SetCustomData("RotationSnapState", transformGizmo.RotationSnapEnabled.ToString()); editor.ProjectCache.SetCustomData("RotationSnapState", transformGizmo.RotationSnapEnabled);
}; };
var rotateSnappingCM = new ContextMenu(); var rotateSnappingCM = new ContextMenu();
var rotateSnapping = new ViewportWidgetButton(transformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM) var rotateSnapping = new ViewportWidgetButton(transformGizmo.RotationSnapValue.ToString(), SpriteHandle.Invalid, rotateSnappingCM)
@@ -250,7 +250,7 @@ namespace FlaxEditor.Viewport
transformGizmo.RotationSnapValue = v; transformGizmo.RotationSnapValue = v;
rotateSnapping.Text = v.ToString(); rotateSnapping.Text = v.ToString();
if (useProjectCache) if (useProjectCache)
editor.ProjectCache.SetCustomData("RotationSnapValue", transformGizmo.RotationSnapValue.ToString("N")); editor.ProjectCache.SetCustomData("RotationSnapValue", transformGizmo.RotationSnapValue);
}; };
rotateSnappingCM.VisibleChanged += control => rotateSnappingCM.VisibleChanged += control =>
{ {
@@ -281,7 +281,7 @@ namespace FlaxEditor.Viewport
{ {
transformGizmo.TranslationSnapEnable = !transformGizmo.TranslationSnapEnable; transformGizmo.TranslationSnapEnable = !transformGizmo.TranslationSnapEnable;
if (useProjectCache) if (useProjectCache)
editor.ProjectCache.SetCustomData("TranslateSnapState", transformGizmo.TranslationSnapEnable.ToString()); editor.ProjectCache.SetCustomData("TranslateSnapState", transformGizmo.TranslationSnapEnable);
}; };
var translateSnappingCM = new ContextMenu(); var translateSnappingCM = new ContextMenu();
var translateSnapping = new ViewportWidgetButton(transformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM) var translateSnapping = new ViewportWidgetButton(transformGizmo.TranslationSnapValue.ToString(), SpriteHandle.Invalid, translateSnappingCM)
@@ -307,7 +307,7 @@ namespace FlaxEditor.Viewport
else else
translateSnapping.Text = v.ToString(); translateSnapping.Text = v.ToString();
if (useProjectCache) if (useProjectCache)
editor.ProjectCache.SetCustomData("TranslateSnapValue", transformGizmo.TranslationSnapValue.ToString("N")); editor.ProjectCache.SetCustomData("TranslateSnapValue", transformGizmo.TranslationSnapValue);
}; };
translateSnappingCM.VisibleChanged += control => translateSnappingCM.VisibleChanged += control =>
{ {

View File

@@ -540,30 +540,30 @@ namespace FlaxEditor.Viewport
} }
// Initialize camera values from cache // Initialize camera values from cache
if (_editor.ProjectCache.TryGetCustomData("CameraMovementSpeedValue", out var cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraMovementSpeedValue", out float cachedFloat))
MovementSpeed = float.Parse(cachedState); MovementSpeed = cachedFloat;
if (_editor.ProjectCache.TryGetCustomData("CameraMinMovementSpeedValue", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraMinMovementSpeedValue", out cachedFloat))
_minMovementSpeed = float.Parse(cachedState); _minMovementSpeed = cachedFloat;
if (_editor.ProjectCache.TryGetCustomData("CameraMaxMovementSpeedValue", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraMaxMovementSpeedValue", out cachedFloat))
_maxMovementSpeed = float.Parse(cachedState); _maxMovementSpeed = cachedFloat;
if (_editor.ProjectCache.TryGetCustomData("UseCameraEasingState", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("UseCameraEasingState", out bool cachedBool))
_useCameraEasing = bool.Parse(cachedState); _useCameraEasing = cachedBool;
if (_editor.ProjectCache.TryGetCustomData("CameraPanningSpeedValue", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraPanningSpeedValue", out cachedFloat))
_panningSpeed = float.Parse(cachedState); _panningSpeed = cachedFloat;
if (_editor.ProjectCache.TryGetCustomData("CameraInvertPanningState", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraInvertPanningState", out cachedBool))
_invertPanning = bool.Parse(cachedState); _invertPanning = cachedBool;
if (_editor.ProjectCache.TryGetCustomData("CameraRelativePanningState", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraRelativePanningState", out cachedBool))
_relativePanning = bool.Parse(cachedState); _relativePanning = cachedBool;
if (_editor.ProjectCache.TryGetCustomData("CameraOrthographicState", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraOrthographicState", out cachedBool))
_isOrtho = bool.Parse(cachedState); _isOrtho = cachedBool;
if (_editor.ProjectCache.TryGetCustomData("CameraOrthographicSizeValue", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraOrthographicSizeValue", out cachedFloat))
_orthoSize = float.Parse(cachedState); _orthoSize = cachedFloat;
if (_editor.ProjectCache.TryGetCustomData("CameraFieldOfViewValue", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraFieldOfViewValue", out cachedFloat))
_fieldOfView = float.Parse(cachedState); _fieldOfView = cachedFloat;
if (_editor.ProjectCache.TryGetCustomData("CameraNearPlaneValue", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraNearPlaneValue", out cachedFloat))
_nearPlane = float.Parse(cachedState); _nearPlane = cachedFloat;
if (_editor.ProjectCache.TryGetCustomData("CameraFarPlaneValue", out cachedState)) if (_editor.ProjectCache.TryGetCustomData("CameraFarPlaneValue", out cachedFloat))
_farPlane = float.Parse(cachedState); _farPlane = cachedFloat;
OnCameraMovementProgressChanged(); OnCameraMovementProgressChanged();
@@ -1041,7 +1041,7 @@ namespace FlaxEditor.Viewport
MovementSpeed = value; MovementSpeed = value;
OnCameraMovementProgressChanged(); OnCameraMovementProgressChanged();
_editor.ProjectCache.SetCustomData("CameraMovementSpeedValue", _movementSpeed.ToString()); _editor.ProjectCache.SetCustomData("CameraMovementSpeedValue", _movementSpeed);
} }
private void OnMinMovementSpeedChanged(FloatValueBox control) private void OnMinMovementSpeedChanged(FloatValueBox control)
@@ -1053,7 +1053,7 @@ namespace FlaxEditor.Viewport
MovementSpeed = value; MovementSpeed = value;
OnCameraMovementProgressChanged(); OnCameraMovementProgressChanged();
_editor.ProjectCache.SetCustomData("CameraMinMovementSpeedValue", _minMovementSpeed.ToString()); _editor.ProjectCache.SetCustomData("CameraMinMovementSpeedValue", _minMovementSpeed);
} }
private void OnMaxMovementSpeedChanged(FloatValueBox control) private void OnMaxMovementSpeedChanged(FloatValueBox control)
@@ -1065,7 +1065,7 @@ namespace FlaxEditor.Viewport
MovementSpeed = value; MovementSpeed = value;
OnCameraMovementProgressChanged(); OnCameraMovementProgressChanged();
_editor.ProjectCache.SetCustomData("CameraMaxMovementSpeedValue", _maxMovementSpeed.ToString()); _editor.ProjectCache.SetCustomData("CameraMaxMovementSpeedValue", _maxMovementSpeed);
} }
private void OnCameraEasingToggled(Control control) private void OnCameraEasingToggled(Control control)
@@ -1073,25 +1073,25 @@ namespace FlaxEditor.Viewport
_useCameraEasing = !_useCameraEasing; _useCameraEasing = !_useCameraEasing;
OnCameraMovementProgressChanged(); OnCameraMovementProgressChanged();
_editor.ProjectCache.SetCustomData("UseCameraEasingState", _useCameraEasing.ToString()); _editor.ProjectCache.SetCustomData("UseCameraEasingState", _useCameraEasing);
} }
private void OnPanningSpeedChanged(FloatValueBox control) private void OnPanningSpeedChanged(FloatValueBox control)
{ {
_panningSpeed = control.Value; _panningSpeed = control.Value;
_editor.ProjectCache.SetCustomData("CameraPanningSpeedValue", _panningSpeed.ToString()); _editor.ProjectCache.SetCustomData("CameraPanningSpeedValue", _panningSpeed);
} }
private void OnRelativePanningToggled(Control control) private void OnRelativePanningToggled(Control control)
{ {
_relativePanning = !_relativePanning; _relativePanning = !_relativePanning;
_editor.ProjectCache.SetCustomData("CameraRelativePanningState", _relativePanning.ToString()); _editor.ProjectCache.SetCustomData("CameraRelativePanningState", _relativePanning);
} }
private void OnInvertPanningToggled(Control control) private void OnInvertPanningToggled(Control control)
{ {
_invertPanning = !_invertPanning; _invertPanning = !_invertPanning;
_editor.ProjectCache.SetCustomData("CameraInvertPanningState", _invertPanning.ToString()); _editor.ProjectCache.SetCustomData("CameraInvertPanningState", _invertPanning);
} }
@@ -1104,7 +1104,7 @@ namespace FlaxEditor.Viewport
private void OnFieldOfViewChanged(FloatValueBox control) private void OnFieldOfViewChanged(FloatValueBox control)
{ {
_fieldOfView = control.Value; _fieldOfView = control.Value;
_editor.ProjectCache.SetCustomData("CameraFieldOfViewValue", _fieldOfView.ToString()); _editor.ProjectCache.SetCustomData("CameraFieldOfViewValue", _fieldOfView);
} }
private void OnOrthographicModeToggled(Control control) private void OnOrthographicModeToggled(Control control)
@@ -1120,25 +1120,25 @@ namespace FlaxEditor.Viewport
OrientViewport(ref orient); OrientViewport(ref orient);
} }
_editor.ProjectCache.SetCustomData("CameraOrthographicState", _isOrtho.ToString()); _editor.ProjectCache.SetCustomData("CameraOrthographicState", _isOrtho);
} }
private void OnOrthographicSizeChanged(FloatValueBox control) private void OnOrthographicSizeChanged(FloatValueBox control)
{ {
_orthoSize = control.Value; _orthoSize = control.Value;
_editor.ProjectCache.SetCustomData("CameraOrthographicSizeValue", _orthoSize.ToString()); _editor.ProjectCache.SetCustomData("CameraOrthographicSizeValue", _orthoSize);
} }
private void OnNearPlaneChanged(FloatValueBox control) private void OnNearPlaneChanged(FloatValueBox control)
{ {
_nearPlane = control.Value; _nearPlane = control.Value;
_editor.ProjectCache.SetCustomData("CameraNearPlaneValue", _nearPlane.ToString()); _editor.ProjectCache.SetCustomData("CameraNearPlaneValue", _nearPlane);
} }
private void OnFarPlaneChanged(FloatValueBox control) private void OnFarPlaneChanged(FloatValueBox control)
{ {
_farPlane = control.Value; _farPlane = control.Value;
_editor.ProjectCache.SetCustomData("CameraFarPlaneValue", _farPlane.ToString()); _editor.ProjectCache.SetCustomData("CameraFarPlaneValue", _farPlane);
} }
/// <summary> /// <summary>
@@ -1217,7 +1217,7 @@ namespace FlaxEditor.Viewport
var speed = Mathf.Lerp(_minMovementSpeed, _maxMovementSpeed, progress); var speed = Mathf.Lerp(_minMovementSpeed, _maxMovementSpeed, progress);
MovementSpeed = (float)Math.Round(speed, 3); MovementSpeed = (float)Math.Round(speed, 3);
_editor.ProjectCache.SetCustomData("CameraMovementSpeedValue", _movementSpeed.ToString()); _editor.ProjectCache.SetCustomData("CameraMovementSpeedValue", _movementSpeed);
} }
private void OnEditorOptionsChanged(EditorOptions options) private void OnEditorOptionsChanged(EditorOptions options)

View File

@@ -1027,7 +1027,7 @@ namespace FlaxEditor.Windows.Assets
try try
{ {
// Try to restore the cached breakpoints from the last session // Try to restore the cached breakpoints from the last session
if (Editor.ProjectCache.TryGetCustomData(_asset.ScriptTypeName + ".Breakpoints", out var breakpointsData)) if (Editor.ProjectCache.TryGetCustomData(_asset.ScriptTypeName + ".Breakpoints", out string breakpointsData))
{ {
var data = JsonSerializer.Deserialize<BreakpointData[]>(breakpointsData); var data = JsonSerializer.Deserialize<BreakpointData[]>(breakpointsData);
if (data != null) if (data != null)

View File

@@ -1068,7 +1068,7 @@ namespace FlaxEditor.Windows
PerformLayout(); PerformLayout();
// Load last viewed folder // Load last viewed folder
if (Editor.ProjectCache.TryGetCustomData(ProjectDataLastViewedFolder, out var lastViewedFolder)) if (Editor.ProjectCache.TryGetCustomData(ProjectDataLastViewedFolder, out string lastViewedFolder))
{ {
if (Editor.ContentDatabase.Find(lastViewedFolder) is ContentFolder folder) if (Editor.ContentDatabase.Find(lastViewedFolder) is ContentFolder folder)
_tree.Select(folder.Node); _tree.Select(folder.Node);

View File

@@ -329,9 +329,8 @@ namespace FlaxEditor.Windows
toolstrip.AddButton("Clear", Clear).LinkTooltip("Clears all log entries"); toolstrip.AddButton("Clear", Clear).LinkTooltip("Clears all log entries");
_clearOnPlayButton = (ToolStripButton)toolstrip.AddButton("Clear on Play").SetAutoCheck(true).SetChecked(true).LinkTooltip("Clears all log entries on enter playmode"); _clearOnPlayButton = (ToolStripButton)toolstrip.AddButton("Clear on Play").SetAutoCheck(true).SetChecked(true).LinkTooltip("Clears all log entries on enter playmode");
bool collapse = true; bool collapse = true;
if (Editor.ProjectCache.TryGetCustomData("DebugLogCollapse", out var collapseString)) if (Editor.ProjectCache.TryGetCustomData("DebugLogCollapse", out bool setCollapse))
if (bool.TryParse(collapseString, out var setCollapse)) collapse = setCollapse;
collapse = setCollapse;
_collapseLogsButton = (ToolStripButton)toolstrip.AddButton("Collapse", () => Editor.ProjectCache.SetCustomData("DebugLogCollapse", _collapseLogsButton.Checked.ToString())).SetAutoCheck(true).SetChecked(collapse).LinkTooltip("Collapses similar logs."); _collapseLogsButton = (ToolStripButton)toolstrip.AddButton("Collapse", () => Editor.ProjectCache.SetCustomData("DebugLogCollapse", _collapseLogsButton.Checked.ToString())).SetAutoCheck(true).SetChecked(collapse).LinkTooltip("Collapses similar logs.");
_pauseOnErrorButton = (ToolStripButton)toolstrip.AddButton("Pause on Error").SetAutoCheck(true).LinkTooltip("Performs auto pause on error"); _pauseOnErrorButton = (ToolStripButton)toolstrip.AddButton("Pause on Error").SetAutoCheck(true).LinkTooltip("Performs auto pause on error");
toolstrip.AddSeparator(); toolstrip.AddSeparator();

View File

@@ -1,6 +1,5 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using FlaxEditor.CustomEditors; using FlaxEditor.CustomEditors;
using FlaxEngine; using FlaxEngine;
@@ -177,7 +176,7 @@ namespace FlaxEditor.Windows
/// <inheritdoc /> /// <inheritdoc />
public override void OnInit() public override void OnInit()
{ {
if (Editor.ProjectCache.TryGetCustomData(_optionsName, out var options) && !string.IsNullOrEmpty(options)) if (Editor.ProjectCache.TryGetCustomData(_optionsName, out string options) && !string.IsNullOrEmpty(options))
{ {
// Load cached settings // Load cached settings
JsonSerializer.Deserialize(_viewModel, options); JsonSerializer.Deserialize(_viewModel, options);