| 123456789101112131415161718192021222324252627282930313233343536373839 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Sprites;
- namespace DevilLink2.UI
- {
- // Sliced Image with an extra fixed-width center column for the two central gems.
- // Uses the original sprite/UVs: no extracted textures and no duplicated overlays.
- public sealed class DailyPanelImage : Image
- {
- protected override void OnPopulateMesh(VertexHelper mesh)
- {
- if (!sprite || type != Type.Sliced) { base.OnPopulateMesh(mesh); return; }
- mesh.Clear();
- var rect = GetPixelAdjustedRect(); var border = sprite.border;
- float sourceWidth = sprite.rect.width, sourceHeight = sprite.rect.height;
- float unit = pixelsPerUnit * pixelsPerUnitMultiplier; // Includes pixelsPerUnitMultiplier and Canvas reference PPU.
- float center = 160f; // Source x432..592 contains both complete central gems.
- float fixedScale = Mathf.Min(1f, Mathf.Min(rect.width * unit / (border.x + border.z + center), rect.height * unit / (border.y + border.w)));
- float left=border.x/unit*fixedScale, right=border.z/unit*fixedScale;
- float bottom=border.y/unit*fixedScale, top=border.w/unit*fixedScale;
- float half=center/unit*fixedScale*.5f;
- var xs = new[]{rect.xMin,rect.xMin+left,rect.center.x-half,rect.center.x+half,rect.xMax-right,rect.xMax};
- var ys = new[]{rect.yMin,rect.yMin+bottom,rect.yMax-top,rect.yMax};
- var sx = new[]{0f,border.x,sourceWidth*.5f-center*.5f,sourceWidth*.5f+center*.5f,sourceWidth-border.z,sourceWidth};
- var sy = new[]{0f,border.y,sourceHeight-border.w,sourceHeight};
- var uv=DataUtility.GetOuterUV(sprite);
- for(int y=0;y<3;y++)for(int x=0;x<5;x++)
- {
- if(!fillCenter && y==1 && x>0 && x<4)continue;
- int first=mesh.currentVertCount;
- mesh.AddVert(new Vector3(xs[x],ys[y]),color,new Vector2(Mathf.Lerp(uv.x,uv.z,sx[x]/sourceWidth),Mathf.Lerp(uv.y,uv.w,sy[y]/sourceHeight)));
- mesh.AddVert(new Vector3(xs[x],ys[y+1]),color,new Vector2(Mathf.Lerp(uv.x,uv.z,sx[x]/sourceWidth),Mathf.Lerp(uv.y,uv.w,sy[y+1]/sourceHeight)));
- mesh.AddVert(new Vector3(xs[x+1],ys[y+1]),color,new Vector2(Mathf.Lerp(uv.x,uv.z,sx[x+1]/sourceWidth),Mathf.Lerp(uv.y,uv.w,sy[y+1]/sourceHeight)));
- mesh.AddVert(new Vector3(xs[x+1],ys[y]),color,new Vector2(Mathf.Lerp(uv.x,uv.z,sx[x+1]/sourceWidth),Mathf.Lerp(uv.y,uv.w,sy[y]/sourceHeight)));
- mesh.AddTriangle(first,first+1,first+2);mesh.AddTriangle(first,first+2,first+3);
- }
- }
- }
- }
|