Add UseAssetImportPathRelative to Editor options and use it by default to store imported asset path relative to the project folder

This commit is contained in:
Wojtek Figat
2023-01-01 18:55:09 +01:00
parent 9554636971
commit 084fe6f063
8 changed files with 38 additions and 3 deletions

View File

@@ -1199,6 +1199,7 @@ namespace FlaxEditor
{
public byte AutoReloadScriptsOnMainWindowFocus;
public byte ForceScriptCompilationOnStartup;
public byte UseAssetImportPathRelative;
public byte AutoRebuildCSG;
public float AutoRebuildCSGTimeoutMs;
public byte AutoRebuildNavMesh;

View File

@@ -794,6 +794,9 @@ public:
static void SetOptions(ManagedEditor::InternalOptions* options)
{
ManagedEditor::ManagedEditorOptions = *options;
// Apply options
AssetsImportingManager::UseImportPathRelative = ManagedEditor::ManagedEditorOptions.UseAssetImportPathRelative != 0;
}
static void DrawNavMesh()

View File

@@ -26,6 +26,7 @@ public:
{
byte AutoReloadScriptsOnMainWindowFocus = 1;
byte ForceScriptCompilationOnStartup = 1;
byte UseAssetImportPathRelative = 1;
byte AutoRebuildCSG = 1;
float AutoRebuildCSGTimeoutMs = 50;
byte AutoRebuildNavMesh = 1;

View File

@@ -148,6 +148,13 @@ namespace FlaxEditor.Options
[EditorDisplay("Scripting", "Auto Save Visual Script On Play Start"), EditorOrder(505), Tooltip("Determines whether automatically save the Visual Script asset editors when starting the play mode in editor.")]
public bool AutoSaveVisualScriptOnPlayStart { get; set; } = true;
/// <summary>
/// If checked, imported file path will be stored relative to the project folder within imported asset metadata. Otherwise will use absolute path.
/// </summary>
[DefaultValue(true)]
[EditorDisplay("Content"), EditorOrder(550)]
public bool UseAssetImportPathRelative { get; set; } = true;
/// <summary>
/// Gets or sets a value indicating whether perform automatic CSG rebuild on brush change.
/// </summary>

View File

@@ -186,6 +186,7 @@ namespace FlaxEditor.Options
Editor.InternalOptions internalOptions;
internalOptions.AutoReloadScriptsOnMainWindowFocus = (byte)(Options.General.AutoReloadScriptsOnMainWindowFocus ? 1 : 0);
internalOptions.ForceScriptCompilationOnStartup = (byte)(Options.General.ForceScriptCompilationOnStartup ? 1 : 0);
internalOptions.UseAssetImportPathRelative = (byte)(Options.General.UseAssetImportPathRelative ? 1 : 0);
internalOptions.AutoRebuildCSG = (byte)(Options.General.AutoRebuildCSG ? 1 : 0);
internalOptions.AutoRebuildCSGTimeoutMs = Options.General.AutoRebuildCSGTimeoutMs;
internalOptions.AutoRebuildNavMesh = (byte)(Options.General.AutoRebuildNavMesh ? 1 : 0);

View File

@@ -4,15 +4,16 @@
#include "Cache/AssetsCache.h"
#include "Storage/ContentStorageManager.h"
#include "Loading/Tasks/LoadAssetDataTask.h"
#include "Factories/BinaryAssetFactory.h"
#include "Engine/ContentImporters/AssetsImportingManager.h"
#include "Engine/Content/Content.h"
#include "Engine/Serialization/JsonTools.h"
#include "Engine/Debug/Exceptions/JsonParseException.h"
#include "Factories/BinaryAssetFactory.h"
#include "Engine/Threading/ThreadPoolTask.h"
#if USE_EDITOR
#include "Engine/Platform/FileSystem.h"
#include "Engine/Threading/Threading.h"
#include "Engine/Engine/Globals.h"
#endif
REGISTER_BINARY_ASSET_ABSTRACT(BinaryAsset, "FlaxEngine.BinaryAsset");
@@ -123,6 +124,12 @@ void BinaryAsset::GetImportMetadata(String& path, String& username) const
{
path = JsonTools::GetString(document, "ImportPath");
username = JsonTools::GetString(document, "ImportUsername");
if (path.HasChars() && FileSystem::IsRelative(path))
{
// Convert path back to thr absolute (eg. if stored in relative format)
path = Globals::ProjectFolder / path;
StringUtils::PathRemoveRelativeParts(path);
}
}
else
{

View File

@@ -3,6 +3,7 @@
#if COMPILE_WITH_ASSETS_IMPORTER
#include "AssetsImportingManager.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Utilities.h"
#include "Engine/Serialization/JsonWriters.h"
#include "Engine/Threading/MainThreadTask.h"
@@ -10,9 +11,9 @@
#include "Engine/Content/Content.h"
#include "Engine/Content/Cache/AssetsCache.h"
#include "Engine/Engine/EngineService.h"
#include "Engine/Core/Log.h"
#include "Engine/Platform/FileSystem.h"
#include "Engine/Platform/Platform.h"
#include "Engine/Engine/Globals.h"
#include "ImportTexture.h"
#include "ImportModelFile.h"
#include "ImportAudio.h"
@@ -71,6 +72,7 @@ AssetsImportingManagerService AssetsImportingManagerServiceInstance;
Array<AssetImporter> AssetsImportingManager::Importers;
Array<AssetCreator> AssetsImportingManager::Creators;
bool AssetsImportingManager::UseImportPathRelative = false;
CreateAssetContext::CreateAssetContext(const StringView& inputPath, const StringView& outputPath, const Guid& id, void* arg)
{
@@ -161,7 +163,15 @@ bool CreateAssetContext::AllocateChunk(int32 index)
void CreateAssetContext::AddMeta(JsonWriter& writer) const
{
writer.JKEY("ImportPath");
writer.String(InputPath);
if (AssetsImportingManager::UseImportPathRelative && !FileSystem::IsRelative(InputPath))
{
const String relativePath = FileSystem::ConvertAbsolutePathToRelative(Globals::ProjectFolder, InputPath);
writer.String(relativePath);
}
else
{
writer.String(InputPath);
}
writer.JKEY("ImportUsername");
writer.String(Platform::GetUserName());
}

View File

@@ -22,6 +22,11 @@ public:
/// </summary>
static Array<AssetCreator> Creators;
/// <summary>
/// If true store asset import path relative to the current workspace, otherwise will store absolute path.
/// </summary>
static bool UseImportPathRelative;
public:
/// <summary>
/// The create texture tag (using internal import pipeline to crate texture asset from custom image source).