Add shader header proxy for easy .hlsl files creation within Editor

This commit is contained in:
Wojtek Figat
2025-06-04 00:12:43 +02:00
parent e97d683545
commit 496856d12e
2 changed files with 47 additions and 11 deletions

View File

@@ -10,11 +10,9 @@ using FlaxEngine;
namespace FlaxEditor.Content namespace FlaxEditor.Content
{ {
/// <summary> /// <summary>
/// Context proxy object for shader source files (represented by <see cref="ShaderSourceItem"/>). /// Base class for shader source files.
/// </summary> /// </summary>
/// <seealso cref="FlaxEditor.Content.ContentProxy" /> public abstract class ShaderBaseProxy : ContentProxy
[ContentContextMenu("New/Shader Source")]
public class ShaderSourceProxy : ContentProxy
{ {
/// <inheritdoc /> /// <inheritdoc />
public override bool CanCreate(ContentFolder targetLocation) public override bool CanCreate(ContentFolder targetLocation)
@@ -29,6 +27,21 @@ namespace FlaxEditor.Content
return targetLocation.ShortName == "Source" && prevTargetLocation.ShortName == "Shaders"; return targetLocation.ShortName == "Source" && prevTargetLocation.ShortName == "Shaders";
} }
/// <inheritdoc />
public override EditorWindow Open(Editor editor, ContentItem item)
{
Editor.Instance.CodeEditing.OpenFile(item.Path);
return null;
}
}
/// <summary>
/// Context proxy object for shader source files (represented by <see cref="ShaderSourceItem"/>).
/// </summary>
/// <seealso cref="FlaxEditor.Content.ContentProxy" />
[ContentContextMenu("New/Shader Source (.shader)")]
public class ShaderSourceProxy : ShaderBaseProxy
{
/// <inheritdoc /> /// <inheritdoc />
public override void Create(string outputPath, object arg) public override void Create(string outputPath, object arg)
{ {
@@ -44,13 +57,6 @@ namespace FlaxEditor.Content
File.WriteAllText(outputPath, shaderTemplate, Encoding.UTF8); File.WriteAllText(outputPath, shaderTemplate, Encoding.UTF8);
} }
/// <inheritdoc />
public override EditorWindow Open(Editor editor, ContentItem item)
{
Editor.Instance.CodeEditing.OpenFile(item.Path);
return null;
}
/// <inheritdoc /> /// <inheritdoc />
public override Color AccentColor => Color.FromRGB(0x7542f5); public override Color AccentColor => Color.FromRGB(0x7542f5);
@@ -66,4 +72,33 @@ namespace FlaxEditor.Content
return item is ShaderSourceItem; return item is ShaderSourceItem;
} }
} }
/// <summary>
/// Context proxy object for shader header files.
/// </summary>
/// <seealso cref="FlaxEditor.Content.ContentProxy" />
[ContentContextMenu("New/Shader Header (.hlsl)")]
public class ShaderHeaderProxy : ShaderBaseProxy
{
/// <inheritdoc />
public override void Create(string outputPath, object arg)
{
File.WriteAllText(outputPath, "\n", Encoding.UTF8);
}
/// <inheritdoc />
public override Color AccentColor => Color.FromRGB(0x2545a5);
/// <inheritdoc />
public override string FileExtension => "hlsl";
/// <inheritdoc />
public override string Name => "Shader Header";
/// <inheritdoc />
public override bool IsProxyFor(ContentItem item)
{
return false;
}
}
} }

View File

@@ -1135,6 +1135,7 @@ namespace FlaxEditor.Modules
Proxy.Add(new FontProxy()); Proxy.Add(new FontProxy());
Proxy.Add(new ShaderProxy()); Proxy.Add(new ShaderProxy());
Proxy.Add(new ShaderSourceProxy()); Proxy.Add(new ShaderSourceProxy());
Proxy.Add(new ShaderHeaderProxy());
Proxy.Add(new ParticleEmitterProxy()); Proxy.Add(new ParticleEmitterProxy());
Proxy.Add(new ParticleEmitterFunctionProxy()); Proxy.Add(new ParticleEmitterFunctionProxy());
Proxy.Add(new ParticleSystemProxy()); Proxy.Add(new ParticleSystemProxy());