using UnityEngine; using UnityEngine.UI; namespace TowerDevil { // Fractures are registered to the stone faces and the central seal of the basalt gate. [RequireComponent(typeof(CanvasRenderer))] public sealed class GateFractures : MaskableGraphic { static readonly Vector2[][] Seams = { new[] { new Vector2(.155f, .47f), new Vector2(.19f, .53f), new Vector2(.182f, .57f), new Vector2(.204f, .62f), new Vector2(.199f, .68f), new Vector2(.227f, .73f) }, new[] { new Vector2(.182f, .57f), new Vector2(.154f, .59f), new Vector2(.132f, .63f) }, new[] { new Vector2(.704f, .46f), new Vector2(.688f, .50f), new Vector2(.699f, .54f), new Vector2(.673f, .60f), new Vector2(.674f, .66f), new Vector2(.644f, .70f) }, new[] { new Vector2(.699f, .54f), new Vector2(.729f, .56f), new Vector2(.744f, .60f) }, new[] { new Vector2(.480f, .728f), new Vector2(.497f, .772f), new Vector2(.488f, .797f), new Vector2(.508f, .821f), new Vector2(.502f, .866f) }, new[] { new Vector2(.77f, .69f), new Vector2(.793f, .71f), new Vector2(.79f, .76f), new Vector2(.824f, .81f), new Vector2(.831f, .86f) } }; float severity; internal void SetDamage(int plates, int maximum) { severity = 1f - (float)plates / maximum; enabled = plates * 2 <= maximum; if (enabled) SetVerticesDirty(); } protected override void OnPopulateMesh(VertexHelper mesh) { mesh.Clear(); Rect r = rectTransform.rect; for (int i = 0; i < Seams.Length; i++) { if (i == Seams.Length - 1 && severity < .75f) break; var seam = Seams[i]; for (int j = 1; j < seam.Length; j++) { Vector2 a = Rect.NormalizedToPoint(r, new Vector2(seam[j - 1].x, 1 - seam[j - 1].y)); Vector2 b = Rect.NormalizedToPoint(r, new Vector2(seam[j].x, 1 - seam[j].y)); float width = r.width * .006f * (1 - .42f * j / seam.Length); BattleEffects.Line(mesh, a, b, width * 2.1f, new Color(.98f, .19f, .045f, .24f * severity)); BattleEffects.Line(mesh, a, b, width, new Color(.08f, .025f, .018f, .95f)); BattleEffects.Line(mesh, a, b, width * .4f, new Color(1, .54f, .12f, .4f + .6f * severity)); } } } } }