Skip to main content
Glama

Union Unity MCP Server

by nurture-tech
Texture2DExtensions.cs1.68 kB
using System; using UnityEngine; namespace Nurture.MCP.Editor { public static class Texture2DExtensions { public static string GetPngBase64(this Texture2D texture) { // Create a temporary RenderTexture and copy the texture content to it RenderTexture tempRT = RenderTexture.GetTemporary( texture.width, texture.height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear ); // Copy the source texture to the temporary RenderTexture Graphics.Blit(texture, tempRT); // Store the active RenderTexture RenderTexture previousRT = RenderTexture.active; // Set the temporary RenderTexture as active RenderTexture.active = tempRT; // Create a new readable texture Texture2D readableTexture = new Texture2D(texture.width, texture.height); // Read pixels from the active RenderTexture (tempRT) into the readable texture readableTexture.ReadPixels(new Rect(0, 0, tempRT.width, tempRT.height), 0, 0); readableTexture.Apply(); // Restore the previously active RenderTexture RenderTexture.active = previousRT; // Release the temporary RenderTexture RenderTexture.ReleaseTemporary(tempRT); // Use the readable texture to create the base64 string string base64 = Convert.ToBase64String(readableTexture.EncodeToPNG()); UnityEngine.Object.DestroyImmediate(readableTexture); return base64; } } }

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/nurture-tech/unity-mcp-server'

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