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))
|
if (textureLookup.ContainsKey(texName))
|
||||||
{
|
{
|
||||||
Texture2D tex = textureLookup[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;
|
SpriteCache[logicKey] = s;
|
||||||
loadedCount++;
|
loadedCount++;
|
||||||
}
|
}
|
||||||
@@ -174,6 +175,66 @@ namespace StrategicMapPlus
|
|||||||
visualizer.ShowText(generatedKey);
|
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 ---
|
// --- VISUALIZADOR ---
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ using System.Reflection;
|
|||||||
[assembly: System.Reflection.AssemblyCompanyAttribute("StrategicView-Plus")]
|
[assembly: System.Reflection.AssemblyCompanyAttribute("StrategicView-Plus")]
|
||||||
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
|
||||||
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
|
||||||
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+d80451ab557736862ecd10b3de84a3d0ffed09f9")]
|
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+132b1baedc3e76f674b00252e91ab05982ba6455")]
|
||||||
[assembly: System.Reflection.AssemblyProductAttribute("StrategicView-Plus")]
|
[assembly: System.Reflection.AssemblyProductAttribute("StrategicView-Plus")]
|
||||||
[assembly: System.Reflection.AssemblyTitleAttribute("StrategicView-Plus")]
|
[assembly: System.Reflection.AssemblyTitleAttribute("StrategicView-Plus")]
|
||||||
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
207ad408a2be3c5f741941664ffdcb40acdf9f0e328efffdc24c02513f1b6213
|
6324d5e6ed883eb594c7f064c6899c6620ec3f6f4b54e50bf9c693a1c9798e38
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user