Add UI Widget to new asset creation for quick UI setup

This commit is contained in:
Wojtek Figat
2024-03-22 11:59:04 +01:00
parent 93d82f761a
commit 4cd788cedc
2 changed files with 62 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
// 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.Thumbnails; using FlaxEditor.Content.Thumbnails;
using FlaxEditor.Viewport.Previews; using FlaxEditor.Viewport.Previews;
using FlaxEditor.Windows; using FlaxEditor.Windows;
@@ -194,4 +195,64 @@ namespace FlaxEditor.Content
base.Dispose(); base.Dispose();
} }
} }
/// <summary>
/// Content proxy for quick UI Control prefab creation as widget.
/// </summary>
[ContentContextMenu("New/Widget")]
internal sealed class WidgetProxy : AssetProxy
{
/// <inheritdoc />
public override string Name => "UI Widget";
/// <inheritdoc />
public override bool IsProxyFor(ContentItem item)
{
return false;
}
/// <inheritdoc />
public override string FileExtension => PrefabProxy.Extension;
/// <inheritdoc />
public override EditorWindow Open(Editor editor, ContentItem item)
{
return null;
}
/// <inheritdoc />
public override Color AccentColor => Color.Transparent;
/// <inheritdoc />
public override string TypeName => PrefabProxy.AssetTypename;
/// <inheritdoc />
public override AssetItem ConstructItem(string path, string typeName, ref Guid id)
{
return null;
}
/// <inheritdoc />
public override bool CanCreate(ContentFolder targetLocation)
{
return targetLocation.CanHaveAssets;
}
/// <inheritdoc />
public override void Create(string outputPath, object arg)
{
// Create prefab with UI Control
var actor = new UIControl
{
Name = Path.GetFileNameWithoutExtension(outputPath),
StaticFlags = StaticFlags.None,
};
actor.Control = new Button
{
Text = "Button",
};
PrefabManager.CreatePrefab(actor, outputPath, false);
Object.Destroy(actor, 20.0f);
}
}
} }

View File

@@ -1106,6 +1106,7 @@ namespace FlaxEditor.Modules
Proxy.Add(new VisualScriptProxy()); Proxy.Add(new VisualScriptProxy());
Proxy.Add(new BehaviorTreeProxy()); Proxy.Add(new BehaviorTreeProxy());
Proxy.Add(new LocalizedStringTableProxy()); Proxy.Add(new LocalizedStringTableProxy());
Proxy.Add(new WidgetProxy());
Proxy.Add(new FileProxy()); Proxy.Add(new FileProxy());
Proxy.Add(new SpawnableJsonAssetProxy<PhysicalMaterial>()); Proxy.Add(new SpawnableJsonAssetProxy<PhysicalMaterial>());