@@ -49,12 +49,8 @@ namespace FlaxEditor.Content.Create
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override bool Create()
|
public override bool Create()
|
||||||
{
|
{
|
||||||
if (_options.RootActorType == null)
|
var actorType = new ScriptType(_options.RootActorType ?? typeof(EmptyActor));
|
||||||
_options.RootActorType = typeof(EmptyActor);
|
Actor actor;
|
||||||
|
|
||||||
ScriptType actorType = new ScriptType(_options.RootActorType);
|
|
||||||
|
|
||||||
Actor actor = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
actor = actorType.CreateInstance() as Actor;
|
actor = actorType.CreateInstance() as Actor;
|
||||||
@@ -102,7 +98,7 @@ namespace FlaxEditor.Content.Create
|
|||||||
/// The mode used to initialize the widget.
|
/// The mode used to initialize the widget.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Tooltip("Whether to initialize the widget with a canvas or a control.")]
|
[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;
|
bool ShowRoot => WidgetInitializationMode == WidgetMode.Control;
|
||||||
|
|
||||||
@@ -111,7 +107,7 @@ namespace FlaxEditor.Content.Create
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[TypeReference(typeof(Control), nameof(IsValid))]
|
[TypeReference(typeof(Control), nameof(IsValid))]
|
||||||
[Tooltip("The control type of the root of the new Widget's root control."), VisibleIf(nameof(ShowRoot))]
|
[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)
|
private static bool IsValid(Type type)
|
||||||
{
|
{
|
||||||
@@ -140,12 +136,8 @@ namespace FlaxEditor.Content.Create
|
|||||||
|
|
||||||
if (_options.WidgetInitializationMode == Options.WidgetMode.Control)
|
if (_options.WidgetInitializationMode == Options.WidgetMode.Control)
|
||||||
{
|
{
|
||||||
if (_options.RootControlType == null)
|
var controlType = new ScriptType(_options.RootControlType ?? typeof(Control));
|
||||||
_options.RootControlType = typeof(Control);
|
Control control;
|
||||||
|
|
||||||
ScriptType controlType = new ScriptType(_options.RootControlType);
|
|
||||||
|
|
||||||
Control control = null;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
control = controlType.CreateInstance() as Control;
|
control = controlType.CreateInstance() as Control;
|
||||||
@@ -157,10 +149,11 @@ namespace FlaxEditor.Content.Create
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIControl newControl = new UIControl();
|
actor = new UIControl
|
||||||
newControl.Control = control;
|
{
|
||||||
|
Control = control,
|
||||||
actor = newControl;
|
Name = controlType.Name
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else if (_options.WidgetInitializationMode == Options.WidgetMode.Canvas)
|
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.");
|
Editor.LogError("Failed to create widget. Final actor was null.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.Destroy(actor, 20.0f);
|
Object.Destroy(actor, 20.0f);
|
||||||
|
|
||||||
return PrefabManager.CreatePrefab(actor, ResultUrl, true);
|
return PrefabManager.CreatePrefab(actor, ResultUrl, true);
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ namespace FlaxEditor.Content
|
|||||||
/// <seealso cref="FlaxEditor.Content.JsonAssetItem" />
|
/// <seealso cref="FlaxEditor.Content.JsonAssetItem" />
|
||||||
public sealed class PrefabItem : JsonAssetItem
|
public sealed class PrefabItem : JsonAssetItem
|
||||||
{
|
{
|
||||||
|
private string _cachedTypeDescription = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PrefabItem"/> class.
|
/// Initializes a new instance of the <see cref="PrefabItem"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -42,28 +44,22 @@ namespace FlaxEditor.Content
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override SpriteHandle DefaultThumbnail => SpriteHandle.Invalid;
|
public override SpriteHandle DefaultThumbnail => SpriteHandle.Invalid;
|
||||||
|
|
||||||
private string _cachedTypeDescription = null;
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string TypeDescription
|
public override string TypeDescription
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (_cachedTypeDescription != null)
|
if (_cachedTypeDescription == null)
|
||||||
return _cachedTypeDescription;
|
|
||||||
|
|
||||||
Prefab prefab = FlaxEngine.Content.LoadAsync<Prefab>(ID);
|
|
||||||
if (prefab.WaitForLoaded(5000))
|
|
||||||
{
|
{
|
||||||
_cachedTypeDescription = "Prefab";
|
_cachedTypeDescription = "Prefab";
|
||||||
|
var prefab = FlaxEngine.Content.Load<Prefab>(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;
|
return _cachedTypeDescription;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
|
||||||
using FlaxEditor.Content.Create;
|
using FlaxEditor.Content.Create;
|
||||||
using FlaxEditor.Content.Thumbnails;
|
using FlaxEditor.Content.Thumbnails;
|
||||||
using FlaxEditor.Viewport.Previews;
|
using FlaxEditor.Viewport.Previews;
|
||||||
@@ -9,7 +8,6 @@ using FlaxEditor.Windows;
|
|||||||
using FlaxEditor.Windows.Assets;
|
using FlaxEditor.Windows.Assets;
|
||||||
using FlaxEngine;
|
using FlaxEngine;
|
||||||
using FlaxEngine.GUI;
|
using FlaxEngine.GUI;
|
||||||
using Object = FlaxEngine.Object;
|
|
||||||
|
|
||||||
namespace FlaxEditor.Content
|
namespace FlaxEditor.Content
|
||||||
{
|
{
|
||||||
@@ -87,6 +85,7 @@ namespace FlaxEditor.Content
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Create(string outputPath, object arg)
|
public override void Create(string outputPath, object arg)
|
||||||
{
|
{
|
||||||
|
bool resetTransform = false;
|
||||||
var transform = Transform.Identity;
|
var transform = Transform.Identity;
|
||||||
if (!(arg is Actor actor))
|
if (!(arg is Actor actor))
|
||||||
{
|
{
|
||||||
@@ -96,12 +95,14 @@ namespace FlaxEditor.Content
|
|||||||
else if (actor.HasScene)
|
else if (actor.HasScene)
|
||||||
{
|
{
|
||||||
// Create prefab with identity transform so the actor instance on a level will have it customized
|
// Create prefab with identity transform so the actor instance on a level will have it customized
|
||||||
|
resetTransform = true;
|
||||||
transform = actor.LocalTransform;
|
transform = actor.LocalTransform;
|
||||||
actor.LocalTransform = Transform.Identity;
|
actor.LocalTransform = Transform.Identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
PrefabManager.CreatePrefab(actor, outputPath, true);
|
PrefabManager.CreatePrefab(actor, outputPath, true);
|
||||||
actor.LocalTransform = transform;
|
if (resetTransform)
|
||||||
|
actor.LocalTransform = transform;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|||||||
@@ -71,13 +71,15 @@ namespace FlaxEditor.Content
|
|||||||
|
|
||||||
private static void OnAnimationGraphCreated(ContentItem item, BinaryAssetItem skinnedModelItem)
|
private static void OnAnimationGraphCreated(ContentItem item, BinaryAssetItem skinnedModelItem)
|
||||||
{
|
{
|
||||||
var skinnedModel = FlaxEngine.Content.LoadAsync<SkinnedModel>(skinnedModelItem.ID);
|
var skinnedModel = FlaxEngine.Content.Load<SkinnedModel>(skinnedModelItem.ID);
|
||||||
if (skinnedModel == null || skinnedModel.WaitForLoaded())
|
if (skinnedModel == null)
|
||||||
{
|
{
|
||||||
Editor.LogError("Failed to load base skinned model.");
|
Editor.LogError("Failed to load base skinned model.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hack the animation graph window to modify the base model of the animation graph.
|
// 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);
|
AnimationGraphWindow win = new AnimationGraphWindow(Editor.Instance, item as AssetItem);
|
||||||
win.Show();
|
win.Show();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user