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