using System; using System.Collections.Generic; using UnityEngine; namespace Auralis { // U07-U12 only. No physical components, interaction, light or save writes. // Every piece is uniformly scaled; the final tile is cropped, never stretched. public sealed class LateDungeonPresentation : MonoBehaviour { public sealed class BankView { public Vector3 SourcePixels; public Vector2 Left,Right; public readonly List Pieces=new(); } public sealed class LadderView { public Vector3 SourcePixels; public Vector2 Bottom,Top; public float RungSpacing,Width; public readonly List Pieces=new(); } public sealed class PortalView {public string Target;public Vector2 Feet;public SpriteRenderer Renderer;public readonly List Pieces=new();} public sealed class Registration {public SpriteRenderer Renderer;public string ArtKey;public Rect SourceRect;public Vector2 SourceAnchor,WorldAnchor;public float WorldUnitsPerPixel;} sealed class Kit { public Rect Floor,Gallery,LadderBand,Door,Corbel,Bench; public Rect[] DoorPieces,CorbelPieces; public float DoorStand,BenchStand,RungPixels; public Kit(Rect floor,Rect gallery,Rect ladder,Rect door,float doorStand,Rect corbel,Rect bench,float benchStand,float rungs) {Floor=floor;Gallery=gallery;LadderBand=ladder;Door=door;DoorStand=doorStand;Corbel=corbel;Bench=bench;BenchStand=benchStand;RungPixels=rungs;DoorPieces=new[]{door};CorbelPieces=new[]{corbel};} } static readonly Dictionary<(string,Rect),Sprite> slices=new(); static readonly Dictionary textures=new(); static int instances; public const float PixelScale=.03f,MaterialScale=.01f; public string RoomId{get;private set;} public int Family=>Layout.Family; public LateDungeonLayout Layout{get;private set;} public Vector2 Origin{get;private set;} public SpriteRenderer Backdrop{get;private set;} public DungeonDepthBackdrop DepthBackdrop{get;private set;} public readonly List Banks=new(); public readonly List Ladders=new(); public readonly List Portals=new(); public readonly List Furniture=new(),Supports=new(),Foreground=new(),Shadows=new(); public readonly List ReplacedRoomPlates=new(); public readonly List Registrations=new(); DungeonRoomDefinition room;Kit kit;int variant;Material architectureMaterial; public Vector2 At(float x,float y)=>Origin+new Vector2((x-768)*PixelScale,(Layout.Baseline-y)*PixelScale); public static LateDungeonPresentation Replace(DungeonRoomDefinition room,Transform parent,Vector2 origin,int family) { if(!GraphicsRolloutMode.Enabled||family==12&&room.Id=="J")return null; var existing=parent.GetComponentInChildren(true);if(existing)return existing; var o=new GameObject("U"+family+" · getrennte Spielebenen · "+room.Id);o.transform.SetParent(parent,false); var p=o.AddComponent();instances++;p.room=room;p.RoomId=room.Id;p.Origin=origin;p.Layout=LateDungeonLayout.For(family,room.Art);p.variant=room.Id[0]-'A'; // Old Art.Build remains the sole geometry owner. Hide only its exact // full room plate; do not touch actors, portals, functional components // or their hierarchy. The original resource remains intact for baseline. foreach(var old in parent.GetComponentsInChildren(true)) if(old.sprite&&old.sprite.texture&&old.sprite.texture.name==room.Art&&!old.GetComponentInParent()) {p.ReplacedRoomPlates.Add(old);old.enabled=false;} p.Build();return p; } static Kit Definition(int family) { if(family<=8)return new(new Rect(85,100,1365,130),new Rect(85,303,1365,144),new Rect(97,540,148,69),new Rect(330,459,421,480),910,new Rect(785,580,226,278),new Rect(1025,743,483,189),930,69); if(family<=10) { var root=new Kit(new Rect(100,117,1330,181),new Rect(100,319,1330,143),new Rect(84,492,150,68),new Rect(286,471,571,443),882,new Rect(844,565,261,235),new Rect(1016,754,479,161),912,68); // Disjoint crops exclude neighboring atlas objects, while both // pieces retain the original full-object anchor and uniform scale. root.DoorPieces=new[]{new Rect(286,471,558,149),new Rect(286,620,571,294)}; root.CorbelPieces=new[]{new Rect(844,565,261,189),new Rect(844,754,172,46)};return root; } var crown=new Kit(new Rect(100,99,1330,126),new Rect(100,311,1330,138),new Rect(95,553,184,75),new Rect(399,451,360,486),908,new Rect(828,540,258,356),new Rect(1060,694,425,243),934,75); crown.CorbelPieces=new[]{new Rect(828,540,258,154),new Rect(828,694,232,202)};return crown; } void Build() { kit=Definition(Family); Backdrop=Piece("Eigener tiefer Hinterraum",Layout.Backdrop,new Rect(0,0,1536,1024),new Vector2(768,Layout.Baseline),Origin,PixelScale,WorldDepthComposition.Enabled?-60:3); // The native Crown rear is a pale monumental hall. Keep its exact // hue, source and registration, but recess it behind the worn lit // play architecture instead of outshining Lio and the torch fronts. if(Layout.Backdrop=="LateCrownDepthV1")Backdrop.color=new Color(.65f,.65f,.65f,1); else if(Layout.Backdrop=="LateVeinDepthV1")Backdrop.color=new Color(.78f,.78f,.78f,1); // A rear-wall flip varies the recess composition; gameplay is never flipped. Backdrop.flipX=(variant%3)==1; DepthBackdrop=DungeonDepthBackdrop.Attach(Backdrop,new Vector2(768,Layout.Baseline),Origin,PixelScale); for(int i=0;i0) { int count=Mathf.Max(1,Mathf.FloorToInt(width/5.8f)); for(int n=0;n=11)&&width>8) { // Tiny cloth is anchored below the bank, away from every ladder. float x=bank.Left.x+width*(variant%2==0?.72f:.3f); bool near=false;foreach(var a in Layout.Ladders)if(Mathf.Abs(At(a.x,a.z).x-x)<1.4f)near=true; if(!near)Foreground.Add(Piece("Kleines vorderes Tuch unter der Standkante","DungeonHearthPilotForegroundV1",new Rect(518,141,456,741),new Vector2(747,143),new Vector2(x,bank.Left.y-.17f),.00125f,16)); } } void TileHorizontal(string label,Rect source,Vector2 left,float width,int order,List output) { float remaining=width,x=left.x;int n=0; while(remaining>.0001f) { float pixels=Mathf.Min(source.width,remaining/MaterialScale);Rect cut=new(source.x,source.y,pixels,source.height); output.Add(Piece(label+" / "+n++,Layout.Kit,cut,new Vector2(cut.x,cut.y),new Vector2(x,left.y),MaterialScale,order)); float used=pixels*MaterialScale;x+=used;remaining-=used; } } void BuildLadder(Vector3 axis) { var view=new LadderView{SourcePixels=axis,Bottom=At(axis.x,axis.y),Top=At(axis.x,axis.z)};Ladders.Add(view); // Source band encloses one rung with half-interval on each side. Its // rails meet continuously, avoiding full-segment caps every six rungs. float scale=.72f/kit.LadderBand.width;view.RungSpacing=kit.RungPixels*scale;view.Width=.72f; float y=view.Bottom.y,remaining=view.Top.y-y;int n=0; while(remaining>.0001f) { float height=Mathf.Min(kit.LadderBand.height,remaining/scale); // Trim at the TOP of the last band, retaining the exact real foot. var cut=new Rect(kit.LadderBand.x,kit.LadderBand.yMax-height,kit.LadderBand.width,height); view.Pieces.Add(Piece("Maßstäbliche Rückleiter "+n++,Layout.Kit,cut,new Vector2(cut.center.x,cut.yMax),new Vector2(view.Bottom.x,y),scale,13)); y+=height*scale;remaining-=height*scale; } WallShadow((view.Bottom+view.Top)*.5f,new Vector2(view.Width*1.3f,view.Top.y-view.Bottom.y)); } void BuildPortal(DungeonLink link) { var feet=Origin+link.At;float scale=3f/(kit.DoorStand-kit.Door.y); float localX=feet.x-Origin.x; float clearance=room.Spatial!=null?Mathf.Min(localX-room.Spatial.Bounds.xMin,room.Spatial.Bounds.xMax-localX):23.04f-Mathf.Abs(localX); clearance=Mathf.Max(.7f,clearance);scale=Mathf.Min(scale,2*clearance/kit.Door.width); // Dark opening is recessed behind its own painted jambs. Rootwood's // atlas has an alpha opening, unlike the opaque stone arch openings. float h=(kit.DoorStand-kit.Door.y)*scale,w=kit.Door.width*scale; WallShadow(feet+Vector2.up*h*.48f,new Vector2(w*1.25f,h*1.1f)); if(Family==9||Family==10) { var shade=ArtLibrary.Sprite("Tiefe im wirklichen Wurzelbogen",ArtLibrary.Soft,feet+Vector2.up*h*.46f,5,transform,false); shade.color=new Color(.07f,.035f,.06f,.94f);shade.transform.localScale=new Vector3(w*.72f,h*1.1f,1);Shadows.Add(shade); } var portal=new PortalView{Target=link.Target,Feet=feet}; foreach(var cut in kit.DoorPieces) portal.Pieces.Add(Piece("Eigener Türsockel · "+link.Target,Layout.Kit,cut,new Vector2(kit.Door.center.x,kit.DoorStand),feet,scale,8)); portal.Renderer=portal.Pieces[0];Portals.Add(portal); } void BuildBlockingPillar(Vector2 foot) { // These three pillars already have 1.92 x 3.0 solid ray-blocking boxes. // Separate repeated stone courses display that complete existing volume. float height=3,width=1.92f;Rect course=new(100,104,192,26); for(float y=0;y1) { var b=Banks[1];float x=Mathf.Lerp(b.Left.x,b.Right.x,variant%2==0?.33f:.7f);var feet=new Vector2(x,b.Left.y); if(b.Right.x-b.Left.x>7&&!NearRoute(feet,2)) { float scale=1.1f/(kit.BenchStand-kit.Bench.y); Furniture.Add(Piece("Kleine Bank an der oberen Leserast",Layout.Kit,kit.Bench,new Vector2(kit.Bench.center.x,kit.BenchStand),feet,scale,8));ContactShadow(feet,kit.Bench.width*scale); } } } bool NearRoute(Vector2 at,float distance) { foreach(var link in room.Links)if(Vector2.Distance(Origin+link.At,at)("GameArt/"+key);if(!t)throw new InvalidOperationException("Missing late dungeon original: "+key);textures[key]=t;} if(topLeft.xMin<0||topLeft.yMin<0||topLeft.xMax>t.width||topLeft.yMax>t.height)throw new InvalidOperationException("Late dungeon slice outside original: "+key); var rect=new Rect(topLeft.x,t.height-topLeft.yMax,topLeft.width,topLeft.height); sprite=Sprite.Create(t,rect,new Vector2(.5f,.5f),100,0,SpriteMeshType.FullRect);sprite.name=key+" · "+topLeft; slices[(key,topLeft)]=sprite;return sprite; } } }