GateFractures.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace TowerDevil
  4. {
  5. // Fractures are registered to the stone faces and the central seal of the basalt gate.
  6. [RequireComponent(typeof(CanvasRenderer))]
  7. public sealed class GateFractures : MaskableGraphic
  8. {
  9. static readonly Vector2[][] Seams = {
  10. new[] { new Vector2(.155f, .47f), new Vector2(.19f, .53f), new Vector2(.182f, .57f),
  11. new Vector2(.204f, .62f), new Vector2(.199f, .68f), new Vector2(.227f, .73f) },
  12. new[] { new Vector2(.182f, .57f), new Vector2(.154f, .59f), new Vector2(.132f, .63f) },
  13. new[] { new Vector2(.704f, .46f), new Vector2(.688f, .50f), new Vector2(.699f, .54f),
  14. new Vector2(.673f, .60f), new Vector2(.674f, .66f), new Vector2(.644f, .70f) },
  15. new[] { new Vector2(.699f, .54f), new Vector2(.729f, .56f), new Vector2(.744f, .60f) },
  16. new[] { new Vector2(.480f, .728f), new Vector2(.497f, .772f), new Vector2(.488f, .797f),
  17. new Vector2(.508f, .821f), new Vector2(.502f, .866f) },
  18. new[] { new Vector2(.77f, .69f), new Vector2(.793f, .71f), new Vector2(.79f, .76f),
  19. new Vector2(.824f, .81f), new Vector2(.831f, .86f) }
  20. };
  21. float severity;
  22. internal void SetDamage(int plates, int maximum)
  23. {
  24. severity = 1f - (float)plates / maximum;
  25. enabled = plates * 2 <= maximum;
  26. if (enabled)
  27. SetVerticesDirty();
  28. }
  29. protected override void OnPopulateMesh(VertexHelper mesh)
  30. {
  31. mesh.Clear();
  32. Rect r = rectTransform.rect;
  33. for (int i = 0; i < Seams.Length; i++)
  34. {
  35. if (i == Seams.Length - 1 && severity < .75f)
  36. break;
  37. var seam = Seams[i];
  38. for (int j = 1; j < seam.Length; j++)
  39. {
  40. Vector2 a = Rect.NormalizedToPoint(r, new Vector2(seam[j - 1].x, 1 - seam[j - 1].y));
  41. Vector2 b = Rect.NormalizedToPoint(r, new Vector2(seam[j].x, 1 - seam[j].y));
  42. float width = r.width * .006f * (1 - .42f * j / seam.Length);
  43. BattleEffects.Line(mesh, a, b, width * 2.1f, new Color(.98f, .19f, .045f, .24f * severity));
  44. BattleEffects.Line(mesh, a, b, width, new Color(.08f, .025f, .018f, .95f));
  45. BattleEffects.Line(mesh, a, b, width * .4f, new Color(1, .54f, .12f, .4f + .6f * severity));
  46. }
  47. }
  48. }
  49. }
  50. }