add circle mask to icons
This commit is contained in:
63
Class1.cs
63
Class1.cs
@@ -58,7 +58,8 @@ namespace StrategicMapPlus
|
||||
if (textureLookup.ContainsKey(texName))
|
||||
{
|
||||
Texture2D tex = textureLookup[texName];
|
||||
Sprite s = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
|
||||
Texture2D roundTex = MakeTextureTransparent(tex);
|
||||
Sprite s = Sprite.Create(roundTex, new Rect(0, 0, roundTex.width, roundTex.height), new Vector2(0.5f, 0.5f));
|
||||
SpriteCache[logicKey] = s;
|
||||
loadedCount++;
|
||||
}
|
||||
@@ -174,6 +175,66 @@ namespace StrategicMapPlus
|
||||
visualizer.ShowText(generatedKey);
|
||||
}
|
||||
}
|
||||
|
||||
// Función auxiliar que podrías llamar desde tu parche de Harmony
|
||||
public static Texture2D MakeTextureTransparent(Texture originalTexture)
|
||||
{
|
||||
if (originalTexture == null) return null;
|
||||
|
||||
// 1. Crear una RenderTexture temporal para poder leer la textura original
|
||||
RenderTexture tmp = RenderTexture.GetTemporary(
|
||||
originalTexture.width,
|
||||
originalTexture.height,
|
||||
0,
|
||||
RenderTextureFormat.Default,
|
||||
RenderTextureReadWrite.Linear);
|
||||
|
||||
// 2. Copiar la textura original a la RenderTexture (esto "desbloquea" los píxeles)
|
||||
Graphics.Blit(originalTexture, tmp);
|
||||
|
||||
// 3. Activar la RenderTexture para leerla
|
||||
RenderTexture previous = RenderTexture.active;
|
||||
RenderTexture.active = tmp;
|
||||
|
||||
// 4. Crear una nueva Texture2D leíble
|
||||
Texture2D newTexture = new Texture2D(originalTexture.width, originalTexture.height);
|
||||
newTexture.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
|
||||
|
||||
// 5. MODIFICAR LOS PÍXELES (Aquí ocurre la magia)
|
||||
Color[] pixels = newTexture.GetPixels();
|
||||
float width = newTexture.width;
|
||||
float height = newTexture.height;
|
||||
Vector2 center = new Vector2(width / 2f, height / 2f);
|
||||
float radius = (Mathf.Min(width, height) / 2f); // Radio máximo
|
||||
|
||||
for (int i = 0; i < pixels.Length; i++)
|
||||
{
|
||||
// --- Opción A: Máscara Redonda (Matemática) ---
|
||||
int x = i % newTexture.width;
|
||||
int y = i / newTexture.width;
|
||||
float dist = Vector2.Distance(new Vector2(x, y), center);
|
||||
|
||||
if (dist > radius)
|
||||
{
|
||||
pixels[i] = Color.clear; // Hacemos transparente lo que esté fuera del círculo
|
||||
}
|
||||
|
||||
// --- Opción B: Quitar el negro (Si prefieres por color) ---
|
||||
// if (pixels[i].r < 0.1f && pixels[i].g < 0.1f && pixels[i].b < 0.1f)
|
||||
// {
|
||||
// pixels[i] = Color.clear;
|
||||
// }
|
||||
}
|
||||
|
||||
newTexture.SetPixels(pixels);
|
||||
newTexture.Apply();
|
||||
|
||||
// 6. Limpieza
|
||||
RenderTexture.active = previous;
|
||||
RenderTexture.ReleaseTemporary(tmp);
|
||||
|
||||
return newTexture;
|
||||
}
|
||||
}
|
||||
|
||||
// --- VISUALIZADOR ---
|
||||
|
||||
Reference in New Issue
Block a user