Skip to main content
Glama
CommandBase.cs1.99 kB
using System; using UnityEngine; namespace UnityMCP.Client.Editor.Commands { /// <summary> /// Base class for all commands /// </summary> public abstract class CommandBase : ICommand { private readonly string _resultVariableName; /// <summary> /// Create a new CommandBase /// </summary> /// <param name="resultVariableName">The variable name to store the result in, if any</param> protected CommandBase(string resultVariableName = null) { _resultVariableName = resultVariableName; } /// <summary> /// Get the variable name to store the result in, if any /// </summary> public string ResultVariableName => _resultVariableName; /// <summary> /// Execute the command and return the result /// </summary> /// <param name="context">The command context</param> /// <returns>The result of the command execution</returns> public abstract object Execute(CommandContext context); /// <summary> /// Convert the result to a string representation /// </summary> /// <param name="result">The result to convert</param> /// <returns>A string representation of the result</returns> protected string ResultToString(object result) { if (result == null) { return "null"; } return result.ToString(); } /// <summary> /// Store the result in the context if a variable name was provided /// </summary> /// <param name="context">The command context</param> /// <param name="result">The result to store</param> protected void StoreResult(CommandContext context, object result) { if (!string.IsNullOrEmpty(_resultVariableName)) { context.SetVariable(_resultVariableName, result); } } } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TSavo/Unity-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server