Improve Json Asset development workflow
This commit is contained in:
@@ -88,7 +88,6 @@ namespace FlaxEditor.CustomEditors
|
||||
/// <seealso cref="FlaxEditor.CustomEditors.SyncPointEditor" />
|
||||
protected class RootEditor : SyncPointEditor
|
||||
{
|
||||
private readonly string _noSelectionText;
|
||||
private CustomEditor _overrideEditor;
|
||||
|
||||
/// <summary>
|
||||
@@ -109,13 +108,18 @@ namespace FlaxEditor.CustomEditors
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The text to show when no object is selected.
|
||||
/// </summary>
|
||||
public string NoSelectionText;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="RootEditor"/> class.
|
||||
/// </summary>
|
||||
/// <param name="noSelectionText">The text to show when no item is selected.</param>
|
||||
public RootEditor(string noSelectionText)
|
||||
{
|
||||
_noSelectionText = noSelectionText ?? "No selection";
|
||||
NoSelectionText = noSelectionText ?? "No selection";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -154,7 +158,7 @@ namespace FlaxEditor.CustomEditors
|
||||
}
|
||||
else
|
||||
{
|
||||
var label = layout.Label(_noSelectionText, TextAlignment.Center);
|
||||
var label = layout.Label(NoSelectionText, TextAlignment.Center);
|
||||
label.Label.Height = 20.0f;
|
||||
}
|
||||
|
||||
@@ -251,6 +255,20 @@ namespace FlaxEditor.CustomEditors
|
||||
/// </summary>
|
||||
public object Owner;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the text to show when no object is selected.
|
||||
/// </summary>
|
||||
public string NoSelectionText
|
||||
{
|
||||
get => Editor.NoSelectionText;
|
||||
set
|
||||
{
|
||||
Editor.NoSelectionText = value;
|
||||
if (SelectionCount == 0)
|
||||
BuildLayoutOnUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
private bool _buildOnUpdate;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using FlaxEditor.Content;
|
||||
using FlaxEditor.CustomEditors;
|
||||
using FlaxEditor.GUI;
|
||||
@@ -106,13 +107,36 @@ namespace FlaxEditor.Windows.Assets
|
||||
/// <inheritdoc />
|
||||
protected override void OnAssetLoaded()
|
||||
{
|
||||
_object = Asset.CreateInstance();
|
||||
_object = Asset.Instance;
|
||||
if (_object == null)
|
||||
{
|
||||
// Hint developer about cause of failure
|
||||
var dataTypeName = Asset.DataTypeName;
|
||||
var type = Type.GetType(dataTypeName);
|
||||
if (type != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var obj = Activator.CreateInstance(type);
|
||||
var data = Asset.Data;
|
||||
FlaxEngine.Json.JsonSerializer.Deserialize(obj, data);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_presenter.NoSelectionText = "Failed to load asset. See log for more. " + ex.Message.Replace('\n', ' ');
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_presenter.NoSelectionText = string.Format("Missing type '{0}'.", dataTypeName);
|
||||
}
|
||||
}
|
||||
_presenter.Select(_object);
|
||||
_undo.Clear();
|
||||
ClearEditedFlag();
|
||||
|
||||
// Auto-close on scripting reload if json asset is from game scripts (it might be reloaded)
|
||||
if (_object != null && FlaxEngine.Scripting.IsTypeFromGameScripts(_object.GetType()) && !_isRegisteredForScriptsReload)
|
||||
if ((_object == null || FlaxEngine.Scripting.IsTypeFromGameScripts(_object.GetType())) && !_isRegisteredForScriptsReload)
|
||||
{
|
||||
_isRegisteredForScriptsReload = true;
|
||||
ScriptsBuilder.ScriptsReloadBegin += OnScriptsReloadBegin;
|
||||
@@ -121,6 +145,14 @@ namespace FlaxEditor.Windows.Assets
|
||||
base.OnAssetLoaded();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnAssetLoadFailed()
|
||||
{
|
||||
_presenter.NoSelectionText = "Failed to load the asset.";
|
||||
|
||||
base.OnAssetLoadFailed();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnItemReimported(ContentItem item)
|
||||
{
|
||||
|
||||
@@ -202,7 +202,7 @@ namespace FlaxEditor.Content.Settings
|
||||
var asset = FlaxEngine.Content.LoadAsync<JsonAsset>(GameSettingsAssetPath);
|
||||
if (asset && !asset.WaitForLoaded())
|
||||
{
|
||||
if (asset.CreateInstance() is GameSettings result)
|
||||
if (asset.Instance is GameSettings result)
|
||||
return result;
|
||||
}
|
||||
return new GameSettings();
|
||||
@@ -212,7 +212,7 @@ namespace FlaxEditor.Content.Settings
|
||||
{
|
||||
if (asset && !asset.WaitForLoaded())
|
||||
{
|
||||
if (asset.CreateInstance() is T result)
|
||||
if (asset.Instance is T result)
|
||||
return result;
|
||||
}
|
||||
return new T();
|
||||
@@ -222,7 +222,7 @@ namespace FlaxEditor.Content.Settings
|
||||
{
|
||||
if (asset && !asset.WaitForLoaded() && asset.DataTypeName == typename)
|
||||
{
|
||||
if (asset.CreateInstance() is SettingsBase result)
|
||||
if (asset.Instance is SettingsBase result)
|
||||
return result;
|
||||
}
|
||||
return null;
|
||||
@@ -314,7 +314,7 @@ namespace FlaxEditor.Content.Settings
|
||||
{
|
||||
if (e.Value && !e.Value.WaitForLoaded() && e.Value.DataTypeName == type.FullName)
|
||||
{
|
||||
var custom = e.Value.CreateInstance();
|
||||
var custom = e.Value.Instance;
|
||||
if (custom is T result)
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user