40. C#での色補間コード(透明部分を隣の色で塗りつぶす)
void UnitBorderFix(Texture2D texture)
{
int w = texture.width;
int h = texture.height;
var source = texture.GetPixels32();
var result = new Color32[source.Length];
for (int x = 2; x < w - 2; x++) {
for (int y = 2; y < h - 2; y++) {
result[y * w + x] = GetN(source, x, y, w, h);
}
}
texture.SetPixels32(result);
}
39
41. C#での色補間コード(透明部分を隣の色で塗りつぶす)
40
Color32 GetN(Color32[] source, int x, int y, int w, int h)
{
if (source[y * w + x].a != 0) {
return source[y * w + x];
}
foreach (int i in new[] {0, -1, 1, -2, 2}) {
foreach (int j in new[] {0, -1, 1, -2, 2}) {
var c = source[(y + j) * w + (x + i)];
if (c.a != 0) {
return new Color32 {r = c.r, g = c.g, b = c.b, a = 0};
}
}
}
return source[y * w + x];
}