using System.Collections.Generic; using UnityEngine; namespace Auralis { // Presentation only: contact tops, widths, movement and ground materials // remain owned by each room. Every kit refers to that room's own painting. public sealed partial class RoomIntegratedPlatformArt:MonoBehaviour { sealed class Kit { public string Resource;public Rect Beam,Left,Right,Carriage; public float Contact,Density,EndPixels=92;public bool RootShelf,Original,Organic; public Rect NaturalEnd;public float EndContact;public bool NaturalEndLeft; public Rect ContourBounds;public Vector2[] SourceContour;public bool RejectBlueBackdrop; } readonly List sprites=new(); readonly List fronts=new(); Material originalMaterial;bool organicMaterial; public string SourceArt{get;private set;} public float SourceDensity{get;private set;} public bool UsesOriginalPixels{get;private set;} public IReadOnlyList Fronts=>fronts; CordMesh recoveryCord;Vector2[] recoveryPath; public static void DressRiverRecovery(ClimbableLadder ladder) { if(!ladder)throw new System.ArgumentNullException(nameof(ladder)); // Only hide the practice-ladder pictures. The existing straight // climbing span and its interaction remain exactly as authored. foreach(var renderer in ladder.GetComponentsInChildren(true)) {renderer.enabled=false;renderer.forceRenderingOff=true;} var root=new GameObject("Geflochtenes Vorhof-Rückseil · reine Darstellung");root.transform.SetParent(ladder.transform,false); var art=root.AddComponent(); art.recoveryCord=CordMesh.Create(root.transform,"Vorhandenes River-Seilgeflecht statt goldener Übungssprossen",ClimbableLadder.DrawingOrder,.19f); art.recoveryPath=new[]{new Vector2(ladder.X,ladder.Bottom+.025f),new Vector2(ladder.X,ladder.Top-.035f)}; } public static SpriteRenderer[] Dress(BoxCollider2D bank,string roomKey,bool moving=false,bool includeConsoles=true) { if(!bank)throw new System.ArgumentNullException(nameof(bank)); var art=bank.GetComponent(); if(art)return art.fronts.ToArray(); if(!bank.GetComponent())bank.gameObject.AddComponent(); art=bank.gameObject.AddComponent();art.Build(bank,Select(roomKey),moving,includeConsoles:includeConsoles); return art.fronts.ToArray(); } public static SpriteRenderer[] DressSpan(Transform parent,Vector2 top,float width,string roomKey,int order=6) { var o=new GameObject("Originalraumgesims · reine Kulisse");o.transform.SetParent(parent,false); var art=o.AddComponent();art.Build(null,Select(roomKey),false,top,width); foreach(var front in art.fronts)front.sortingOrder=order;return art.fronts.ToArray(); } static Kit Select(string key) { var original=OriginalKit(key);if(original!=null)return original; switch(key) { case "glass-threshold":return new Kit{Resource="RoomIntegratedGlassV1",Beam=new Rect(30,133,1195,123),Contact=144,Density=.0054f,Left=new Rect(98,424,379,330),Right=new Rect(777,424,380,330),Carriage=new Rect(245,951,765,233)}; case "observatory-east":return new Kit{Resource="RoomIntegratedObservatoryV1",Beam=new Rect(15,130,1225,151),Contact=137,Density=.0052f,Left=new Rect(33,489,547,331),Right=new Rect(676,489,549,331),Carriage=new Rect(178,868,899,291)}; case "archive-evening":return new Kit{Resource="RoomIntegratedEveningV1",Beam=new Rect(24,105,1210,123),Contact=113,Density=.0055f,Left=new Rect(14,402,583,425),Right=new Rect(667,402,574,425),Carriage=new Rect(296,1000,666,207)}; case "rain-care":return new Kit{Resource="RoomIntegratedRainV1",Beam=new Rect(50,78,1438,207),Contact=91,Density=.0048f,Left=new Rect(83,379,419,467),Right=new Rect(1035,379,422,467),Carriage=new Rect(503,787,533,166)}; case "river-forecourt":return new Kit{Resource="RoomIntegratedRiverV1",Beam=new Rect(38,70,1461,271),Contact=83,Density=.0065f,Carriage=new Rect(489,647,535,311),RootShelf=true}; case "night-roots":return new Kit{Resource="RoomIntegratedNightV1",Beam=new Rect(31,78,1474,226),Contact=83,Density=.0065f,Carriage=new Rect(504,739,532,225),RootShelf=true}; // These additional rooms share the established violet/brown // root families. They deliberately use the dedicated bands, // not repeatedly cut diagonals from an opaque room painting. // No tiny carriage/console motif is added below short steps. case "root-carry":case "root-turn":case "root-open":case "night-vein-hall": return new Kit{Resource="RoomIntegratedNightV1",Beam=new Rect(31,78,1474,226),Contact=83,Density=.0065f,RootShelf=true}; case "mist-spool":case "mist-tension":case "river-ray": return new Kit{Resource="RoomIntegratedRiverV1",Beam=new Rect(38,70,1461,271),Contact=83,Density=.0065f,RootShelf=true}; default:throw new System.ArgumentException("Missing room-bound platform kit: "+key,nameof(key)); } } Sprite Cut(Texture2D texture,Rect topDown,Vector2 pivot) { var rect=new Rect(topDown.x,texture.height-topDown.y-topDown.height,topDown.width,topDown.height); var sprite=Sprite.Create(texture,rect,pivot,100,0,SpriteMeshType.FullRect); sprites.Add(sprite);return sprite; } void Build(BoxCollider2D bank,Kit kit,bool moving,Vector2? fixedTop=null,float fixedWidth=0,bool includeConsoles=true) { var texture=Resources.Load("GameArt/"+kit.Resource); if(!texture)throw new System.InvalidOperationException("Missing room-bound platform painting: "+kit.Resource); SourceArt=kit.Resource;SourceDensity=kit.Density;UsesOriginalPixels=kit.Original; if(kit.Original) { var mask=Resources.Load("GameArt/"+kit.Resource+"ArchitectureLayerV1"); if(mask||kit.Organic||kit.SourceContour!=null) { originalMaterial=new Material(Resources.Load(kit.Organic||kit.SourceContour!=null?"Materials/RoomIntegratedRootMask":"Materials/RoomArchitectureMask")); originalMaterial.SetTexture("_ArchitectureMask",mask?mask:Texture2D.whiteTexture); originalMaterial.SetInt("_BandCount",1); originalMaterial.SetVectorArray("_ProtectedBands",new[]{new Vector4(kit.Beam.x/texture.width,(texture.height-kit.Contact-2)/texture.height,kit.Beam.xMax/texture.width,(texture.height-kit.Contact+1)/texture.height)}); organicMaterial=kit.Organic; if(kit.SourceContour!=null) { originalMaterial.SetInt("_OutlineCount",kit.SourceContour.Length); var outline=new Vector4[48];for(int i=0;i0) { float nativeWidth=kit.Carriage.width*kit.Density; if(!kit.Original||nativeWidth<=width-.16f) { var carriage=Cut(texture,kit.Carriage,new Vector2(.5f,1)); var drive=Draw("Raumgebundenes Unterfahrwerk · mit dem getragenen Deck",carriage,top+Vector2.down*below,5); drive.transform.localScale=Vector3.one*(kit.Original?scale:Mathf.Min(width*.82f/carriage.bounds.size.x,2.45f/carriage.bounds.size.x)); } } else if(includeConsoles&&!kit.RootShelf&&kit.Left.width>0&&kit.Right.width>0) { float nativeWidth=(kit.Left.width+kit.Right.width)*kit.Density; if(!kit.Original||nativeWidth<=width-.24f) { var left=Cut(texture,kit.Left,new Vector2(0,1)); var right=Cut(texture,kit.Right,new Vector2(1,1)); float supportWidth=Mathf.Min(1.7f,width*.44f); var a=Draw("Große linke Raumkonsole unter dem Gesims",left,top+new Vector2(-width*.5f+.08f,-below),5); a.transform.localScale=Vector3.one*(kit.Original?scale:supportWidth/left.bounds.size.x); var b=Draw("Große rechte Raumkonsole unter dem Gesims",right,top+new Vector2(width*.5f-.08f,-below),5); b.transform.localScale=Vector3.one*(kit.Original?scale:supportWidth/right.bounds.size.x); } } } void Beam(Texture2D texture,Kit kit,Vector2 top,float width,float scale) { if(kit.Original) { float remainingWidth=width,edgeX=top.x-width*.5f; if(kit.NaturalEnd.width>0&&width>kit.Density*10) { float pixels=Mathf.Min(kit.NaturalEnd.width,(width/kit.Density-8)*.5f),span=pixels*kit.Density; var capRect=new Rect(kit.NaturalEndLeft?kit.NaturalEnd.x:kit.NaturalEnd.xMax-pixels,kit.NaturalEnd.y,pixels,kit.NaturalEnd.height); var cap=Cut(texture,capRect,new Vector2(kit.NaturalEndLeft?0:1,1-(kit.EndContact-capRect.y)/capRect.height)); var a=Draw("Natürlicher linker Original-Galerieabschluss",cap,new Vector2(edgeX,top.y),6); a.transform.localScale=new Vector3(kit.NaturalEndLeft?scale:-scale,scale,scale); var b=Draw("Natürlicher rechter Original-Galerieabschluss",cap,new Vector2(top.x+width*.5f,top.y),6); b.transform.localScale=new Vector3(kit.NaturalEndLeft?-scale:scale,scale,scale); edgeX+=span;remainingWidth-=span*2; } while(remainingWidth>.0001f) { float span=Mathf.Min(remainingWidth,kit.Beam.width*kit.Density),pixels=span/kit.Density; var crop=new Rect(kit.Beam.x+(kit.Beam.width-pixels)*.5f,kit.Beam.y,pixels,kit.Beam.height); var front=Cut(texture,crop,new Vector2(0,1-(kit.Contact-kit.Beam.y)/kit.Beam.height)); Draw("Unveränderter Originalraum · zusammenhängender Gesimsausschnitt",front,new Vector2(edgeX,top.y),6).transform.localScale=Vector3.one*scale; edgeX+=span;remainingWidth-=span; } return; } float endPixels=Mathf.Min(kit.EndPixels,width/(kit.Density*3)); float capWidth=endPixels*kit.Density; float pivot=1-(kit.Contact-kit.Beam.y)/kit.Beam.height; var left=Cut(texture,new Rect(kit.Beam.x,kit.Beam.y,endPixels,kit.Beam.height),new Vector2(0,pivot)); var right=Cut(texture,new Rect(kit.Beam.xMax-endPixels,kit.Beam.y,endPixels,kit.Beam.height),new Vector2(1,pivot)); Draw("Natürliche linke Raumgesimskante",left,top+Vector2.left*width*.5f,6).transform.localScale=Vector3.one*scale; Draw("Natürliche rechte Raumgesimskante",right,top+Vector2.right*width*.5f,6).transform.localScale=Vector3.one*scale; float remaining=Mathf.Max(0,width-2*capWidth),sourceWidth=kit.Beam.width-2*endPixels,x=top.x-width*.5f+capWidth; while(remaining>.0001f) { float worldWidth=Mathf.Min(remaining,sourceWidth*kit.Density),pixels=worldWidth/kit.Density; float sourceX=kit.Beam.x+endPixels+(sourceWidth-pixels)*.5f; var middle=Cut(texture,new Rect(sourceX,kit.Beam.y,pixels,kit.Beam.height),new Vector2(0,pivot)); Draw("Breite Raumgesimsfläche · unverzerrter Materialausschnitt",middle,new Vector2(x,top.y),6).transform.localScale=Vector3.one*scale; x+=worldWidth;remaining-=worldWidth; } } SpriteRenderer Draw(string label,Sprite sprite,Vector2 at,int order) { var renderer=ArtLibrary.Sprite(label,sprite,at,order,transform,false); if(originalMaterial)renderer.sharedMaterial=originalMaterial; fronts.Add(renderer);return renderer; } void LateUpdate(){if(organicMaterial&&originalMaterial)originalMaterial.SetMatrix("_BankWorldToLocal",transform.worldToLocalMatrix);if(recoveryCord)recoveryCord.Draw(recoveryPath);} void OnDestroy(){foreach(var sprite in sprites)if(sprite)Destroy(sprite);if(originalMaterial)Destroy(originalMaterial);} } }