Small codestyle tweaks

#2415
This commit is contained in:
Wojtek Figat
2024-09-11 13:38:31 +02:00
parent 1bc09fb962
commit 4683262cf3
4 changed files with 29 additions and 38 deletions

View File

@@ -49,12 +49,8 @@ namespace FlaxEditor.Content.Create
/// <inheritdoc />
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.
/// </summary>
[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
/// </summary>
[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);

View File

@@ -11,6 +11,8 @@ namespace FlaxEditor.Content
/// <seealso cref="FlaxEditor.Content.JsonAssetItem" />
public sealed class PrefabItem : JsonAssetItem
{
private string _cachedTypeDescription = null;
/// <summary>
/// Initializes a new instance of the <see cref="PrefabItem"/> class.
/// </summary>
@@ -42,28 +44,22 @@ namespace FlaxEditor.Content
/// <inheritdoc />
public override SpriteHandle DefaultThumbnail => SpriteHandle.Invalid;
private string _cachedTypeDescription = null;
/// <inheritdoc />
public override string TypeDescription
{
get
{
if (_cachedTypeDescription != null)
return _cachedTypeDescription;
Prefab prefab = FlaxEngine.Content.LoadAsync<Prefab>(ID);
if (prefab.WaitForLoaded(5000))
if (_cachedTypeDescription == null)
{
_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;
}
}

View File

@@ -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
/// <inheritdoc />
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;
}
/// <inheritdoc />

View File

@@ -71,13 +71,15 @@ namespace FlaxEditor.Content
private static void OnAnimationGraphCreated(ContentItem item, BinaryAssetItem skinnedModelItem)
{
var skinnedModel = FlaxEngine.Content.LoadAsync<SkinnedModel>(skinnedModelItem.ID);
if (skinnedModel == null || skinnedModel.WaitForLoaded())
var skinnedModel = FlaxEngine.Content.Load<SkinnedModel>(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();