| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using System;
- using System.IO;
- using System.Linq;
- using TMPro;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.UI;
- namespace Olympus.Editor
- {
- // All textures are authored here or are independently generated full-image assets.
- // Never read a mockup, screen plate, atlas region, or non-default UV rectangle.
- public static class TempleKit
- {
- public const string Folder="Assets/Olympus/Resources/Olympus/Elements/";
- public const float K=750f/941;
- public static Color Cream=new Color32(255,242,211,255),Gold=new Color32(255,214,117,255),Ink=new Color32(47,23,5,255);
- public static TMP_FontAsset Font=>AssetDatabase.LoadAssetAtPath<TMP_FontAsset>("Assets/Olympus/Resources/Olympus/Suite/Temple Serif.asset");
- static Material HeadingMaterial=>AssetDatabase.LoadAssetAtPath<Material>(Folder+"Embossed serif.mat");
- public static RectTransform R(string name,Transform parent,float x,float y,float w,float h)
- {
- var r=OlympusUi.Rect(name,parent);r.anchorMin=r.anchorMax=new Vector2(0,1);r.pivot=new Vector2(0,1);r.anchoredPosition=new Vector2(x*K,-y*K);r.sizeDelta=new Vector2(w*K,h*K);return r;
- }
- public static Sprite S(string key)
- {
- string replacement=key=="gold_button"?"v3_button":key=="ornate_panel"?"v3_panel":key=="tile"?"v3_tile":key=="circle"?"v3_round":key=="blue_disc"?"v3_timer":key=="trophy"?"v3_trophy":key=="chest"?"v3_chest":key;
- if(key=="victory_crest")replacement="trophy";
- if(key=="reward_chest")replacement="chest";
- return AssetDatabase.LoadAssetAtPath<Sprite>(Folder+replacement+".png");
- }
- public static Sprite Art(string key)=>AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Olympus/Resources/Olympus/Art/"+key+".png");
- public static Sprite Question(string key)=>AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Olympus/Resources/Olympus/Questions/"+key+".png");
- public static Sprite Power(int i)=>S(new[]{"v3_hint","v3_time","v3_reveal","v3_skip"}[i]);
- public static Image I(string name,Transform p,Sprite s,float x,float y,float w,float h,bool aspect=true)
- {var i=R(name,p,x,y,w,h).gameObject.AddComponent<Image>();i.sprite=s;i.raycastTarget=false;i.preserveAspect=aspect;return i;}
- public static Image Plate(string name,Transform p,float x,float y,float w,float h,string key="panel")
- {
- string sprite=key=="panel"||key=="wood"?(h<155?"v3_plaque":"v3_panel"):key=="button"?"v3_button":key=="row"?"v3_panel":key;
- var i=I(name,p,S(sprite),x,y,w,h);
- if(i.sprite && i.sprite.border!=Vector4.zero)
- {
- i.type=Image.Type.Sliced;i.preserveAspect=false;
- var slice=i.gameObject.AddComponent<ProportionalSlice>();slice.capsule=key=="button"||key=="ivory"||sprite=="v3_plaque";slice.cornerSize=(key=="row"?16:42)*K;slice.Apply();
- }
- return i;
- }
- public static TextMeshProUGUI T(string name,Transform p,string text,float x,float y,float w,float h,float size,Color? color=null)
- {
- var t=R(name,p,x,y,w,h).gameObject.AddComponent<TextMeshProUGUI>();t.font=Font;t.text=text;t.fontSize=t.fontSizeMax=size*K;t.fontSizeMin=size*K*.65f;t.enableAutoSizing=true;t.color=color??Cream;t.alignment=TextAlignmentOptions.Center;t.textWrappingMode=TextWrappingModes.Normal;t.raycastTarget=false;
- if(size>=40&&(!color.HasValue||color.Value==Gold))
- {
- t.fontSharedMaterial=HeadingMaterial;t.enableVertexGradient=true;
- t.colorGradient=new VertexGradient(Color.white,Color.white,new Color32(225,190,126,255),new Color32(225,190,126,255));
- }
- var s=t.gameObject.AddComponent<Shadow>();s.effectDistance=new Vector2(1,-1.6f);s.effectColor=new Color(0,0,0,.75f);return t;
- }
- public static Button B(string name,Transform p,float x,float y,float w,float h,string label=null,float size=38,string key="button")
- {
- var i=Plate(name,p,x,y,w,h,key);i.raycastTarget=true;var b=i.gameObject.AddComponent<Button>();b.targetGraphic=i;var c=b.colors;c.highlightedColor=new Color(1.08f,1.06f,1,1);c.pressedColor=new Color(.7f,.57f,.35f,1);c.disabledColor=new Color(.48f,.43f,.34f,1);b.colors=c;
- if(label!=null)T(name+" label",i.transform,label,5,2,w-10,h-4,size,key=="button"||key=="tile"?Ink:Cream);return b;
- }
- public static Button Hit(string name,Transform p,float x,float y,float w,float h)
- {var b=B(name,p,x,y,w,h);b.image.sprite=null;b.image.color=Color.clear;return b;}
- public static Graphic G(string name,Transform p,TempleGlyph.Kind kind,float x,float y,float w,float h,Color? color=null)
- {
- if(kind==TempleGlyph.Kind.Laurel)
- {
- // Keep the painted leaves' proportions while spacing the two branches around text.
- // Both Images reference the complete independently generated asset, never a mockup slice.
- var root=I(name,p,null,x,y,w,h);root.color=Color.clear;float leafHeight=Mathf.Min(h,w*.52f),sw=leafHeight*2163f/727f,branch=sw*.27f;
- for(int side=0;side<2;side++)
- {
- var window=R("Laurel window "+side,root.transform,side==0?0:w-branch,(h-leafHeight)*.5f,branch,leafHeight);window.gameObject.AddComponent<RectMask2D>();
- I("Painted laurel "+side,window,S("v2_laurels"),side==0?0:branch-sw,0,sw,leafHeight);
- }
- return root;
- }
- string sprite=kind==TempleGlyph.Kind.Gear?"v3_gear":kind==TempleGlyph.Kind.Book?"v3_book":kind==TempleGlyph.Kind.Profile?"v3_profile":kind==TempleGlyph.Kind.Sound?"v3_sound":kind==TempleGlyph.Kind.Music?"v3_music":kind==TempleGlyph.Kind.Hand?"v3_hand":kind==TempleGlyph.Kind.Brush?"v3_brush":kind==TempleGlyph.Kind.Letters?"v3_letters":null;
- if(sprite!=null)return I(name,p,S(sprite),x,y,w,h,kind!=TempleGlyph.Kind.Laurel);
- var g=R(name,p,x,y,w,h).gameObject.AddComponent<TempleGlyph>();g.kind=kind;g.color=color??Gold;g.raycastTarget=false;return g;
- }
- public static void Background(Transform p,bool trial=false)
- {I("Independent temple environment",p,trial?Art("background_olympus"):S("v3_background"),0,0,941,1672).gameObject.AddComponent<ScreenSpaceBackground>();}
- public static void Title(Transform p,string value,float y=200)
- {Plate("Title plaque",p,180,y-12,581,112,"wood");G("Title laurels",p,TempleGlyph.Kind.Laurel,150,y-13,640,116);T("Title",p,value,240,y,460,90,56,Gold);}
- public static void Logo(Transform p,float y,float height=215)
- {
- // Independently painted brand wordmark; all functional labels remain TMP.
- I("Sculpted Olympus wordmark",p,S("v3_logo"),58,y,825,height);
- }
- public static void Prepare()
- {
- Directory.CreateDirectory(Folder);
- var heading=HeadingMaterial;
- if(!heading){heading=new Material(Font.material);AssetDatabase.CreateAsset(heading,Folder+"Embossed serif.mat");}
- heading.SetColor("_OutlineColor",new Color32(44,20,5,255));heading.SetFloat("_OutlineWidth",.09f);heading.SetFloat("_FaceDilate",.015f);EditorUtility.SetDirty(heading);
- // Only these three procedural textures remain in the current UI kit.
- foreach(var key in new[]{"ivory","coin","green_disc"})Make(key);
- AssetDatabase.Refresh();
- foreach(string dir in new[]{Folder,"Assets/Olympus/Resources/Olympus/Art/","Assets/Olympus/Resources/Olympus/Questions/"})
- foreach(string file in Directory.GetFiles(dir,"*.png"))
- {
- string path=file.Replace('\\','/');var imp=(TextureImporter)AssetImporter.GetAtPath(path);string key=Path.GetFileNameWithoutExtension(path);
- var border=Vector4.zero;
- if(key=="ivory")border=new Vector4(56,54,56,54);
- float ppu=100;
- if(key=="v3_panel"||key=="v3_plaque"||key=="v3_button")
- {
- imp.GetSourceTextureWidthAndHeight(out int sw,out int sh);
- if(key=="v3_panel")border=Vector4.one*(sw*.13f);
- else border=new Vector4(sh*.5f,sh*.48f,sh*.5f,sh*.48f);
- }
- bool illustrative=key.StartsWith("avatar_")||key.StartsWith("power_")||key.StartsWith("v2_")||new[]{"trophy","chest","gold_coin","portal_medallion"}.Contains(key);
- bool compact=key.StartsWith("avatar_")||key.StartsWith("v3_")&&!new[]{"v3_panel","v3_plaque","v3_button","v3_background","v3_logo"}.Contains(key);
- int maxSize=key=="v3_background"?2048:key=="v3_logo"?1024:compact?256:key.StartsWith("power_")||key.StartsWith("v3_")?512:2048;
- imp.textureType=TextureImporterType.Sprite;imp.spriteImportMode=SpriteImportMode.Single;imp.spriteBorder=border;imp.spritePixelsPerUnit=ppu;imp.alphaIsTransparency=true;imp.mipmapEnabled=illustrative||compact;imp.filterMode=illustrative||compact?FilterMode.Trilinear:FilterMode.Bilinear;imp.maxTextureSize=maxSize;imp.npotScale=TextureImporterNPOTScale.None;var settings=new TextureImporterSettings();imp.ReadTextureSettings(settings);settings.spriteMeshType=SpriteMeshType.FullRect;imp.SetTextureSettings(settings);imp.textureCompression=TextureImporterCompression.Uncompressed;imp.SaveAndReimport();
- // A 1254px source is not a 1254 UI-unit icon. SetNativeSize and
- // dragging assets onto a 750x1334 Canvas now have sensible sizes.
- if(key.StartsWith("v3_")&&key!="v3_background")IndependentSpriteImporter.TrimPadding(imp,path,key);
- float native=NativeWidth(key);
- if(native>0){var sprite=AssetDatabase.LoadAssetAtPath<Sprite>(path);imp.GetSourceTextureWidthAndHeight(out int sourceWidth,out int sourceHeight);imp.spritePixelsPerUnit=sprite.rect.width/native*100*sourceWidth/sprite.texture.width;imp.SaveAndReimport();}
- }
- }
- public static float NativeWidth(string key)
- {
- if(key=="v3_background")return 750;
- if(key=="v3_logo")return 658;
- if(new[]{"v3_hint","v3_time","v3_reveal","v3_skip"}.Contains(key))return 124;
- if(key=="v3_panel")return 340;
- if(key=="v3_button"||key=="v3_plaque")return 256;
- if(key=="v3_timer")return 112;
- if(key=="v3_tile")return 72;
- if(key.StartsWith("v3_"))return 64;
- if(key.StartsWith("avatar_"))return 80;
- if(key=="gold_coin")return 40;
- if(key=="portal_medallion")return 360;
- return 0;
- }
- public static void SaveComponents()
- {
- const string folder="Assets/Olympus/Prefabs/UI/";Directory.CreateDirectory(folder);
- foreach(string name in new[]{"GoldButton","LetterTile","Panel","AnswerField","Avatar","Powerup"})
- {
- RectTransform r;
- if(name=="GoldButton"||name=="LetterTile")r=(RectTransform)B(name,null,0,0,name=="GoldButton"?320:91,name=="GoldButton"?90:91,name=="GoldButton"?"CONTINUE":"A",40,name=="GoldButton"?"button":"tile").transform;
- else if(name=="Panel"||name=="AnswerField")r=Plate(name,null,0,0,400,name=="Panel"?400:100,name=="Panel"?"panel":"ivory").rectTransform;
- else r=I(name,null,name=="Avatar"?Art("avatar_1"):Power(0),0,0,name=="Avatar"?100:156,name=="Avatar"?100:156,true).rectTransform;
- r.anchoredPosition=Vector2.zero;PrefabUtility.SaveAsPrefabAsset(r.gameObject,folder+name+".prefab");UnityEngine.Object.DestroyImmediate(r.gameObject);
- }
- }
- static Color C(byte r,byte g,byte b)=>new Color32(r,g,b,255);
- static void Make(string key)
- {
- bool round=key=="circle"||key=="coin"||key.EndsWith("_disc"),gold=key=="button"||key=="tile"||key=="coin",ivory=key=="ivory";
- int w=key=="button"||ivory?384:128,h=key=="button"||ivory?112:128;var t=new Texture2D(w,h,TextureFormat.RGBA32,false);var pix=new Color32[w*h];
- for(int y=0;y<h;y++)for(int x=0;x<w;x++)
- {
- float xx=x+.5f,yy=y+.5f,edge;
- if(round)edge=60-Vector2.Distance(new Vector2(xx,yy),new Vector2(64,64));
- else if(key=="button"||ivory){float cx=Mathf.Clamp(xx,54,w-54);edge=52-Vector2.Distance(new Vector2(xx,yy),new Vector2(cx,h/2));}
- else {edge=Mathf.Min(Mathf.Min(xx,w-xx),Mathf.Min(yy,h-yy))-2;edge=Mathf.Min(edge,(Mathf.Min(xx,w-xx)+Mathf.Min(yy,h-yy)-16)*.707f);}
- Color c;if(edge<0)c=Color.clear;
- else if(edge<2)c=C(58,28,7);else if(edge<4)c=C(255,232,162);else if(edge<8)c=Color.Lerp(C(130,64,10),C(246,191,78),yy/h);else if(edge<10)c=C(255,221,131);else if(edge<12)c=C(87,43,10);
- else if(gold){float f=(float)y/h;c=Color.Lerp(C(174,98,12),C(255,225,130),f);if(f>.68f)c=Color.Lerp(c,C(255,246,197),.23f);}
- else if(ivory)c=Color.Lerp(C(221,213,194),C(255,251,239),(float)y/h);
- else if(key.EndsWith("_disc"))c=Color.Lerp(key=="blue_disc"?C(8,39,87):C(15,63,5),key=="blue_disc"?C(15,179,231):C(117,204,20),(float)y/h);
- else {c=Color.Lerp(key=="wood"?C(68,29,9):C(28,14,7),key=="wood"?C(119,61,23):C(69,38,17),(float)y/h);float grain=Mathf.Sin(x*.14f+Mathf.Sin(y*.08f)*3)*Mathf.Sin(y*.9f)*.017f;c+=new Color(grain,grain*.65f,grain*.25f,0);}
- pix[y*w+x]=c;
- }
- t.SetPixels32(pix);t.Apply();File.WriteAllBytes(Folder+key+".png",t.EncodeToPNG());UnityEngine.Object.DestroyImmediate(t);
- }
- }
- }
|