SkillOrb.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. namespace Fateforge
  4. {
  5. public sealed class SkillOrb : MonoBehaviour
  6. {
  7. Image resting;
  8. RectTransform activeParts,sphere,halo;
  9. public void Build(Sprite sprite,UiTheme theme)
  10. {
  11. Image Crystal(Transform parent,float y)
  12. {
  13. var image=Ui.Image(Ui.Rect(parent,"Crystal",0,y,104,125),sprite,Color.white);
  14. image.preserveAspect=true;return image;
  15. }
  16. resting=Crystal(transform,0);
  17. activeParts=Ui.Rect(transform,"Activated",0,0,105,125);
  18. var stand=Crystal(activeParts,0);
  19. stand.type=Image.Type.Filled;stand.fillMethod=Image.FillMethod.Vertical;
  20. stand.fillOrigin=(int)Image.OriginVertical.Bottom;stand.fillAmount=.32f;
  21. var seat=Ui.Glyph(activeParts,"Socket",UiGlyph.Shape.Disc,0,80,69,69,new Color(.24f,.11f,.035f));
  22. seat.rectTransform.localScale=new Vector3(1,.22f,1);
  23. halo=Ui.Glyph(activeParts,"EnergyRing",UiGlyph.Shape.Orbit,0,0,111,111,theme.cyan).rectTransform;
  24. halo.pivot=Vector2.one*.5f;
  25. for(int i=0;i<4;i++)
  26. {
  27. float angle=(20+i*90)*Mathf.Deg2Rad;
  28. var star=Ui.Glyph(halo,"Spark",UiGlyph.Shape.Glint,Mathf.Cos(angle)*51,55-Mathf.Sin(angle)*51,10,16,theme.text);
  29. star.rectTransform.pivot=Vector2.one*.5f;
  30. }
  31. sphere=Ui.Rect(activeParts,"LevitatingOrb",0,0,92,92);
  32. var disc=Ui.Glyph(sphere,"Mask",UiGlyph.Shape.Disc,0,0,92,92,Color.white);
  33. disc.gameObject.AddComponent<Mask>().showMaskGraphic=false;
  34. Crystal(disc.transform,0);
  35. activeParts.gameObject.SetActive(false);
  36. }
  37. public void Show(bool active,bool available,float time)
  38. {
  39. resting.gameObject.SetActive(!active);
  40. resting.color=available?Color.white:new Color(.47f,.43f,.49f);
  41. activeParts.gameObject.SetActive(active);
  42. if(!active)return;
  43. float lift=Mathf.SmoothStep(0,1,time/.28f);
  44. float bounce=Mathf.Sin(Mathf.Clamp01(time/.42f)*Mathf.PI*2);
  45. float y=2+lift*(19+2*Mathf.Sin(time*3.5f));
  46. sphere.anchoredPosition=new Vector2(0,y);
  47. sphere.localScale=Vector3.one*(1-.08f*bounce);
  48. halo.anchoredPosition=new Vector2(0,y-46);
  49. halo.localRotation=Quaternion.Euler(0,0,time*23);
  50. halo.localScale=Vector3.one*(.88f+.12f*lift+.025f*Mathf.Sin(time*4));
  51. }
  52. }
  53. }