TempleGlyph.cs 4.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace Olympus
  4. {
  5. // Original vector symbols. Geometry stays editable and crisp at every Canvas scale.
  6. [RequireComponent(typeof(CanvasRenderer))]
  7. public sealed class TempleGlyph : MaskableGraphic
  8. {
  9. public enum Kind { Gear, Menu, Check, Cross, Plus, Book, Profile, Coin, Sound, Music, Hand, Brush, Letters, Reset, Trident, Laurel }
  10. public Kind kind;
  11. protected override void OnPopulateMesh(VertexHelper v)
  12. {
  13. v.Clear();
  14. switch(kind)
  15. {
  16. case Kind.Gear:
  17. Ring(v,.5f,.5f,.29f,.13f);for(int i=0;i<8;i++){float a=i*Mathf.PI/4;Line(v,.5f+Mathf.Cos(a)*.23f,.5f+Mathf.Sin(a)*.23f,.5f+Mathf.Cos(a)*.43f,.5f+Mathf.Sin(a)*.43f,.13f);}break;
  18. case Kind.Menu:for(int i=0;i<3;i++)Line(v,.18f,.28f+i*.22f,.82f,.28f+i*.22f,.08f);break;
  19. case Kind.Check:Line(v,.14f,.49f,.4f,.24f,.12f);Line(v,.4f,.24f,.87f,.79f,.12f);break;
  20. case Kind.Cross:Line(v,.24f,.24f,.76f,.76f,.1f);Line(v,.24f,.76f,.76f,.24f,.1f);break;
  21. case Kind.Plus:Line(v,.18f,.5f,.82f,.5f,.12f);Line(v,.5f,.18f,.5f,.82f,.12f);break;
  22. case Kind.Book:
  23. Quad(v,.12f,.2f,.47f,.8f);Quad(v,.53f,.2f,.88f,.8f);Line(v,.5f,.16f,.5f,.84f,.035f);break;
  24. case Kind.Profile:Disc(v,.5f,.68f,.19f);Poly(v,new[]{new Vector2(.18f,.16f),new Vector2(.2f,.3f),new Vector2(.32f,.43f),new Vector2(.68f,.43f),new Vector2(.8f,.3f),new Vector2(.82f,.16f)});break;
  25. case Kind.Coin:Ring(v,.5f,.5f,.45f,.37f);Ring(v,.5f,.5f,.31f,.29f);Line(v,.5f,.25f,.5f,.75f,.08f);Line(v,.31f,.58f,.68f,.42f,.08f);break;
  26. case Kind.Sound:Quad(v,.17f,.37f,.34f,.63f);Line(v,.34f,.5f,.56f,.7f,.17f);Line(v,.34f,.5f,.56f,.3f,.17f);Line(v,.75f,.3f,.83f,.5f,.05f);Line(v,.83f,.5f,.75f,.7f,.05f);break;
  27. case Kind.Music:Line(v,.4f,.24f,.4f,.78f,.07f);Line(v,.4f,.78f,.78f,.87f,.09f);Line(v,.78f,.87f,.78f,.33f,.07f);Disc(v,.29f,.24f,.13f);Disc(v,.67f,.33f,.13f);break;
  28. case Kind.Hand:Quad(v,.3f,.22f,.7f,.58f);for(int i=0;i<4;i++)Line(v,.31f+i*.11f,.5f,.31f+i*.11f,.8f- Mathf.Abs(i-1.5f)*.08f,.08f);Line(v,.3f,.35f,.16f,.52f,.09f);break;
  29. case Kind.Brush:Line(v,.28f,.25f,.72f,.8f,.13f);Disc(v,.23f,.2f,.13f);break;
  30. case Kind.Letters:Line(v,.2f,.22f,.5f,.8f,.09f);Line(v,.5f,.8f,.8f,.22f,.09f);Line(v,.32f,.43f,.68f,.43f,.06f);break;
  31. case Kind.Reset:Ring(v,.5f,.5f,.31f,.24f);Line(v,.15f,.56f,.14f,.83f,.07f);Line(v,.14f,.83f,.42f,.78f,.07f);break;
  32. case Kind.Trident:Line(v,.5f,.1f,.5f,.87f,.065f);Line(v,.25f,.7f,.25f,.45f,.06f);Line(v,.75f,.7f,.75f,.45f,.06f);Line(v,.25f,.45f,.5f,.35f,.06f);Line(v,.75f,.45f,.5f,.35f,.06f);for(int i=0;i<3;i++){float x=.25f+i*.25f,y=i==1?.92f:.78f;Line(v,x-.07f,y-.11f,x,y,.055f);Line(v,x+.07f,y-.11f,x,y,.055f);}break;
  33. case Kind.Laurel:
  34. float aspect=rectTransform.rect.height/Mathf.Max(1,rectTransform.rect.width);
  35. for(int side=-1;side<=1;side+=2)for(int i=0;i<7;i++)
  36. {
  37. float x=(side<0?.06f:.94f)+side*Mathf.Sin(i*.38f)*.09f*aspect,y=.1f+i*.105f;
  38. float tip=x-side*.14f*aspect;
  39. var leaf=new Vector2[18];
  40. for(int j=0;j<=8;j++)
  41. {
  42. float t=j/8f,bulge=Mathf.Sin(t*Mathf.PI)*.035f;var axis=new Vector2(Mathf.Lerp(x,tip,t),y+t*.14f);var normal=new Vector2(bulge*aspect,side*bulge);
  43. leaf[j]=axis+normal;leaf[17-j]=axis-normal;
  44. }
  45. Poly(v,leaf);
  46. }break;
  47. }
  48. }
  49. Vector2 P(float x,float y){var r=rectTransform.rect;return new Vector2(r.x+x*r.width,r.y+y*r.height);}
  50. Color Shade(float y)=>color*Color.Lerp(new Color(.64f,.39f,.16f,1),Color.white,Mathf.Clamp01(y+.2f));
  51. void Quad(VertexHelper v,float x,float y,float xx,float yy){Poly(v,new[]{new Vector2(x,y),new Vector2(x,yy),new Vector2(xx,yy),new Vector2(xx,y)});}
  52. void Poly(VertexHelper v,Vector2[] points){int n=v.currentVertCount;foreach(var p in points)v.AddVert(P(p.x,p.y),Shade(p.y),Vector2.zero);for(int i=1;i<points.Length-1;i++)v.AddTriangle(n,n+i,n+i+1);}
  53. void Line(VertexHelper v,float x,float y,float xx,float yy,float w){var a=new Vector2(x,y);var b=new Vector2(xx,yy);var d=(b-a).normalized;var n=new Vector2(-d.y,d.x)*w/2;Poly(v,new[]{a-n,a+n,b+n,b-n});}
  54. void Disc(VertexHelper v,float x,float y,float r){Ring(v,x,y,r,0);}
  55. void Ring(VertexHelper v,float x,float y,float r,float inner){for(int i=0;i<64;i++){float a=i*Mathf.PI/32,b=(i+1)*Mathf.PI/32;Poly(v,new[]{new Vector2(x+Mathf.Cos(a)*r,y+Mathf.Sin(a)*r),new Vector2(x+Mathf.Cos(b)*r,y+Mathf.Sin(b)*r),new Vector2(x+Mathf.Cos(b)*inner,y+Mathf.Sin(b)*inner),new Vector2(x+Mathf.Cos(a)*inner,y+Mathf.Sin(a)*inner)});}}
  56. }
  57. }