Editor utility class that provides helper methods for creating or inspecting simple asset files for sprites, shader graphs, and hotspot rect definitions. Each method optionally creates directories, writes minimal JSON/text templates to the given path, and returns a ToolOutcome with metadata.
#nullable enable
using System;
using System.IO;
using Sandbox;
namespace Editor.Mcp
{
internal static class SpecializedAssetDriver
{
public static ToolOutcome<object> ManageSprite( string spritePath, string action = "inspect", int frameCount = 1, float frameRate = 12f )
{
var normAction = action.ToLowerInvariant();
if ( normAction == "create" )
{
var dir = Path.GetDirectoryName( spritePath );
if ( !string.IsNullOrWhiteSpace( dir ) ) Directory.CreateDirectory( dir );
var json = $"{{\n \"FrameCount\": {frameCount},\n \"FrameRate\": {frameRate},\n \"Animations\": [\"default\"]\n}}";
File.WriteAllText( spritePath, json );
return ToolOutcome<object>.Ready( new { SpritePath = spritePath, Created = true, FrameCount = frameCount } );
}
return ToolOutcome<object>.Ready( new { SpritePath = spritePath, Action = action, Exists = File.Exists( spritePath ) } );
}
public static ToolOutcome<object> ManageShaderGraph( string shaderPath, string action = "inspect", string templateType = "lit" )
{
var normAction = action.ToLowerInvariant();
if ( normAction == "create_template" )
{
var dir = Path.GetDirectoryName( shaderPath );
if ( !string.IsNullOrWhiteSpace( dir ) ) Directory.CreateDirectory( dir );
var content = $"// ShaderGraph template ({templateType})\n// Target: {shaderPath}\n";
File.WriteAllText( shaderPath, content );
return ToolOutcome<object>.Ready( new { ShaderPath = shaderPath, Template = templateType, Created = true } );
}
return ToolOutcome<object>.Ready( new { ShaderPath = shaderPath, Action = action, Exists = File.Exists( shaderPath ) } );
}
public static ToolOutcome<object> ManageHotspot( string rectPath, string action = "inspect", string? targetMesh = null )
{
var normAction = action.ToLowerInvariant();
if ( normAction == "create_rect" )
{
var dir = Path.GetDirectoryName( rectPath );
if ( !string.IsNullOrWhiteSpace( dir ) ) Directory.CreateDirectory( dir );
var content = "{\n \"Subrects\": []\n}";
File.WriteAllText( rectPath, content );
return ToolOutcome<object>.Ready( new { RectPath = rectPath, Created = true } );
}
return ToolOutcome<object>.Ready( new { RectPath = rectPath, Action = action, TargetMesh = targetMesh } );
}
}
}