diff --git a/Source/Editor/Content/Create/PrefabCreateEntry.cs b/Source/Editor/Content/Create/PrefabCreateEntry.cs
index e207343a5..06d0c94d4 100644
--- a/Source/Editor/Content/Create/PrefabCreateEntry.cs
+++ b/Source/Editor/Content/Create/PrefabCreateEntry.cs
@@ -49,12 +49,8 @@ namespace FlaxEditor.Content.Create
///
public override bool Create()
{
- if (_options.RootActorType == null)
- _options.RootActorType = typeof(EmptyActor);
-
- ScriptType actorType = new ScriptType(_options.RootActorType);
-
- Actor actor = null;
+ var actorType = new ScriptType(_options.RootActorType ?? typeof(EmptyActor));
+ Actor actor;
try
{
actor = actorType.CreateInstance() as Actor;
@@ -102,7 +98,7 @@ namespace FlaxEditor.Content.Create
/// The mode used to initialize the widget.
///
[Tooltip("Whether to initialize the widget with a canvas or a control.")]
- public WidgetMode WidgetInitializationMode = WidgetMode.Canvas;
+ public WidgetMode WidgetInitializationMode = WidgetMode.Control;
bool ShowRoot => WidgetInitializationMode == WidgetMode.Control;
@@ -111,7 +107,7 @@ namespace FlaxEditor.Content.Create
///
[TypeReference(typeof(Control), nameof(IsValid))]
[Tooltip("The control type of the root of the new Widget's root control."), VisibleIf(nameof(ShowRoot))]
- public Type RootControlType = typeof(Panel);
+ public Type RootControlType = typeof(Button);
private static bool IsValid(Type type)
{
@@ -140,12 +136,8 @@ namespace FlaxEditor.Content.Create
if (_options.WidgetInitializationMode == Options.WidgetMode.Control)
{
- if (_options.RootControlType == null)
- _options.RootControlType = typeof(Control);
-
- ScriptType controlType = new ScriptType(_options.RootControlType);
-
- Control control = null;
+ var controlType = new ScriptType(_options.RootControlType ?? typeof(Control));
+ Control control;
try
{
control = controlType.CreateInstance() as Control;
@@ -157,10 +149,11 @@ namespace FlaxEditor.Content.Create
return true;
}
- UIControl newControl = new UIControl();
- newControl.Control = control;
-
- actor = newControl;
+ actor = new UIControl
+ {
+ Control = control,
+ Name = controlType.Name
+ };
}
else if (_options.WidgetInitializationMode == Options.WidgetMode.Canvas)
{
@@ -172,7 +165,6 @@ namespace FlaxEditor.Content.Create
Editor.LogError("Failed to create widget. Final actor was null.");
return true;
}
-
Object.Destroy(actor, 20.0f);
return PrefabManager.CreatePrefab(actor, ResultUrl, true);
diff --git a/Source/Editor/Content/Items/PrefabItem.cs b/Source/Editor/Content/Items/PrefabItem.cs
index 6394ed52c..3638f274f 100644
--- a/Source/Editor/Content/Items/PrefabItem.cs
+++ b/Source/Editor/Content/Items/PrefabItem.cs
@@ -11,6 +11,8 @@ namespace FlaxEditor.Content
///
public sealed class PrefabItem : JsonAssetItem
{
+ private string _cachedTypeDescription = null;
+
///
/// Initializes a new instance of the class.
///
@@ -42,28 +44,22 @@ namespace FlaxEditor.Content
///
public override SpriteHandle DefaultThumbnail => SpriteHandle.Invalid;
- private string _cachedTypeDescription = null;
-
///
public override string TypeDescription
{
get
{
- if (_cachedTypeDescription != null)
- return _cachedTypeDescription;
-
- Prefab prefab = FlaxEngine.Content.LoadAsync(ID);
- if (prefab.WaitForLoaded(5000))
+ if (_cachedTypeDescription == null)
{
_cachedTypeDescription = "Prefab";
+ var prefab = FlaxEngine.Content.Load(ID);
+ if (prefab)
+ {
+ Actor root = prefab.GetDefaultInstance();
+ if (root is UIControl or UICanvas)
+ _cachedTypeDescription = "Widget";
+ }
}
-
- Actor root = prefab.GetDefaultInstance();
- if (root is UIControl or UICanvas)
- _cachedTypeDescription = "Widget";
- else
- _cachedTypeDescription = "Prefab";
-
return _cachedTypeDescription;
}
}
diff --git a/Source/Editor/Content/Proxy/PrefabProxy.cs b/Source/Editor/Content/Proxy/PrefabProxy.cs
index 5f5a782b8..27bece29c 100644
--- a/Source/Editor/Content/Proxy/PrefabProxy.cs
+++ b/Source/Editor/Content/Proxy/PrefabProxy.cs
@@ -1,7 +1,6 @@
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
using System;
-using System.IO;
using FlaxEditor.Content.Create;
using FlaxEditor.Content.Thumbnails;
using FlaxEditor.Viewport.Previews;
@@ -9,7 +8,6 @@ using FlaxEditor.Windows;
using FlaxEditor.Windows.Assets;
using FlaxEngine;
using FlaxEngine.GUI;
-using Object = FlaxEngine.Object;
namespace FlaxEditor.Content
{
@@ -87,6 +85,7 @@ namespace FlaxEditor.Content
///
public override void Create(string outputPath, object arg)
{
+ bool resetTransform = false;
var transform = Transform.Identity;
if (!(arg is Actor actor))
{
@@ -96,12 +95,14 @@ namespace FlaxEditor.Content
else if (actor.HasScene)
{
// Create prefab with identity transform so the actor instance on a level will have it customized
+ resetTransform = true;
transform = actor.LocalTransform;
actor.LocalTransform = Transform.Identity;
}
PrefabManager.CreatePrefab(actor, outputPath, true);
- actor.LocalTransform = transform;
+ if (resetTransform)
+ actor.LocalTransform = transform;
}
///
diff --git a/Source/Editor/Content/Proxy/SkinnedModelProxy.cs b/Source/Editor/Content/Proxy/SkinnedModelProxy.cs
index 163df87da..551dd1beb 100644
--- a/Source/Editor/Content/Proxy/SkinnedModelProxy.cs
+++ b/Source/Editor/Content/Proxy/SkinnedModelProxy.cs
@@ -71,13 +71,15 @@ namespace FlaxEditor.Content
private static void OnAnimationGraphCreated(ContentItem item, BinaryAssetItem skinnedModelItem)
{
- var skinnedModel = FlaxEngine.Content.LoadAsync(skinnedModelItem.ID);
- if (skinnedModel == null || skinnedModel.WaitForLoaded())
+ var skinnedModel = FlaxEngine.Content.Load(skinnedModelItem.ID);
+ if (skinnedModel == null)
{
Editor.LogError("Failed to load base skinned model.");
+ return;
}
// Hack the animation graph window to modify the base model of the animation graph.
+ // TODO: implement it without window logic (load AnimGraphSurface and set AnimationGraphWindow.BaseModelId to model)
AnimationGraphWindow win = new AnimationGraphWindow(Editor.Instance, item as AssetItem);
win.Show();