117 lines
3.7 KiB
C#
117 lines
3.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace Vanguard.Board3D
|
|
{
|
|
/// <summary>Процедурная рубашка и запасное лицо карты без внешних ассетов.</summary>
|
|
internal static class BoardTextures
|
|
{
|
|
private const int BackWidth = 256;
|
|
private const int BackHeight = 356;
|
|
|
|
private static Texture2D _back;
|
|
private static Texture2D _white;
|
|
|
|
public static Texture2D White
|
|
{
|
|
get
|
|
{
|
|
if (_white == null)
|
|
{
|
|
_white = new Texture2D(2, 2, TextureFormat.RGBA32, false)
|
|
{
|
|
name = "Board White",
|
|
filterMode = FilterMode.Bilinear,
|
|
wrapMode = TextureWrapMode.Clamp,
|
|
hideFlags = HideFlags.DontSave,
|
|
};
|
|
_white.SetPixels(new[] { Color.white, Color.white, Color.white, Color.white });
|
|
_white.Apply(false, true);
|
|
}
|
|
|
|
return _white;
|
|
}
|
|
}
|
|
|
|
public static Texture2D Back
|
|
{
|
|
get
|
|
{
|
|
if (_back != null)
|
|
return _back;
|
|
|
|
_back = Resources.Load<Texture2D>("CardArt/vanguard_back");
|
|
if (_back == null)
|
|
_back = BuildBack();
|
|
return _back;
|
|
}
|
|
}
|
|
|
|
public static Color AccentFor(string printingId)
|
|
{
|
|
var hash = 2166136261u;
|
|
if (!string.IsNullOrEmpty(printingId))
|
|
{
|
|
foreach (var ch in printingId)
|
|
{
|
|
hash ^= ch;
|
|
hash *= 16777619u;
|
|
}
|
|
}
|
|
|
|
var hue = (hash % 360u) / 360f;
|
|
return Color.HSVToRGB(hue, 0.42f, 0.62f);
|
|
}
|
|
|
|
private static Texture2D BuildBack()
|
|
{
|
|
var texture = new Texture2D(
|
|
BackWidth,
|
|
BackHeight,
|
|
TextureFormat.RGBA32,
|
|
false)
|
|
{
|
|
name = "Board Card Back",
|
|
filterMode = FilterMode.Bilinear,
|
|
wrapMode = TextureWrapMode.Clamp,
|
|
hideFlags = HideFlags.DontSave,
|
|
};
|
|
|
|
var pixels = new Color[BackWidth * BackHeight];
|
|
var dark = new Color(0.035f, 0.055f, 0.11f);
|
|
var mid = new Color(0.10f, 0.18f, 0.36f);
|
|
var edge = new Color(0.72f, 0.56f, 0.22f);
|
|
|
|
for (var y = 0; y < BackHeight; y++)
|
|
{
|
|
for (var x = 0; x < BackWidth; x++)
|
|
{
|
|
var u = (x + 0.5f) / BackWidth;
|
|
var v = (y + 0.5f) / BackHeight;
|
|
var border = Mathf.Min(
|
|
Mathf.Min(u, 1f - u) * BackWidth,
|
|
Mathf.Min(v, 1f - v) * BackHeight);
|
|
|
|
var color = Color.Lerp(dark, mid, v * 0.55f + u * 0.15f);
|
|
var diagonal = Mathf.Abs(((u + v) % 0.5f) - 0.25f);
|
|
if (diagonal < 0.018f)
|
|
color = Color.Lerp(color, mid, 0.45f);
|
|
|
|
var dx = Mathf.Abs(u - 0.5f) * BackWidth;
|
|
var dy = Mathf.Abs(v - 0.5f) * BackHeight;
|
|
if (dx + dy < 34f)
|
|
color = Color.Lerp(color, edge, 0.65f);
|
|
|
|
if (border < 4f)
|
|
color = edge;
|
|
|
|
pixels[(y * BackWidth) + x] = color;
|
|
}
|
|
}
|
|
|
|
texture.SetPixels(pixels);
|
|
texture.Apply(false, true);
|
|
return texture;
|
|
}
|
|
}
|
|
}
|