using UnityEngine; using UnityEngine.UI; namespace Fateforge { // Presentation only. The application supplies the animation clock and match membership. [DisallowMultipleComponent] public sealed class CardMatchEffects : MonoBehaviour { CardView card; UiTheme theme; Image tile,flash; RectTransform layer; readonly RectTransform[] clips=new RectTransform[3]; readonly UiGlyph[] borders=new UiGlyph[3]; readonly Image[] sparks=new Image[3]; readonly Color[] familyColors={new Color(.25f,.96f,1),new Color(.62f,.94f,.25f),new Color(1,.64f,.12f)}; Color tileColor,symbolColor,valueColor,frameColor; Vector3 symbolScale; Vector2 lastSize; int families; float lastPulse,lastDim=1; bool configured; public void Configure(CardView target,UiTheme palette,Sprite spark) { if(target==null||palette==null)return; if(configured){ if(card!=target)return; theme=palette; for(int i=0;i(); tileColor=tile?tile.color:Color.white;symbolColor=card.symbol.color;valueColor=card.value.color;frameColor=card.frame?card.frame.color:Color.clear;symbolScale=card.symbol.rectTransform.localScale; layer=Ui.Rect(card.transform,"MatchEffects",0,0,100,100);Ui.Stretch(layer); flash=Ui.Image(Ui.Rect(layer,"GlassFlash",0,0,100,100),theme.panelSprite,Color.clear);Ui.Stretch(flash.rectTransform,4,4,4,4);flash.type=Image.Type.Sliced;flash.pixelsPerUnitMultiplier=2.4f; for(int i=0;i<3;i++){ clips[i]=Ui.Rect(layer,"FamilyBand_"+i,0,0,100,100);clips[i].gameObject.AddComponent(); borders[i]=Ui.Glyph(clips[i],"FamilyBorder_"+i,UiGlyph.Shape.CardOutline,0,0,96,96,familyColors[i]); } for(int i=0;i0)tint/=count; if(card.frame)card.frame.color=pulse>0?WithAlpha(tint,Mathf.Max(frameColor.a,.10f*pulse)*dim):WithAlpha(frameColor,frameColor.a*dim); flash.enabled=pulse>.001f;flash.color=WithAlpha(Color.Lerp(Color.white,tint,.22f),.42f*pulse*dim); float sparkSize=Mathf.Clamp(Mathf.Min(lastSize.x,lastSize.y)*.30f,12,38)*(1+.35f*pulse); for(int i=0;i.001f&&i<(count>1?3:2); image.color=WithAlpha(Color.Lerp(Color.white,tint,.18f),pulse*.88f*dim); float x=i==0?.39f:i==1?-.38f:.37f,y=i==0?.11f:i==1?.84f:.77f; Ui.Place(image.rectTransform,lastSize.x*x,lastSize.y*y-sparkSize*.5f,sparkSize,sparkSize); image.rectTransform.localRotation=Quaternion.Euler(0,0,(i%2==0?1:-1)*18*pulse); } } public void ResetVisuals() {families=0;if(configured){LayoutBands();Sample(0,1);}} void OnDisable() { // Children may already have been destroyed when a scene or Play Mode closes. families=0;lastPulse=0;lastDim=1; foreach(var clip in clips)if(clip)clip.gameObject.SetActive(false); foreach(var spark in sparks)if(spark)spark.enabled=false; if(flash)flash.enabled=false;if(tile)tile.color=tileColor; if(card){if(card.symbol){card.symbol.color=symbolColor;card.symbol.rectTransform.localScale=symbolScale;}if(card.value)card.value.color=valueColor;if(card.frame)card.frame.color=frameColor;if(card.outline)card.outline.enabled=true;} } void LayoutBands() { if(!configured||card==null)return; lastSize=card.Rect.rect.size;int count=0;for(int i=0;i<3;i++)if((families&(1<