using System; using System.IO; using System.Linq; using System.Reflection; using TMPro; using UnityEditor; using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.TextCore.LowLevel; using UnityEngine.UI; namespace Fateforge.Editor { public static class FateforgeBuilder { const string Root="Assets/Fateforge"; public const string ScenePath=Root+"/Scenes/FateforgeMain.unity"; [MenuItem("Fateforge/Service Simulation")] public static void ServiceSimulation(){var app=UnityEngine.Object.FindFirstObjectByType();if(EditorApplication.isPlaying&&app)app.ShowSimulation();else Debug.Log("Enter Play Mode to inspect simulated services.");} [Serializable] sealed class MapEntry {public string id,path;} [Serializable] sealed class ArtMap {public MapEntry[] entries;} static UiTheme theme; static ArtLibrary art; static Image Art(Transform p,string id,float x,float y,float w,float h) {var image=Ui.Image(Ui.Rect(p,id,x,y,w,h),art.Sprite(id),Color.white);image.preserveAspect=true;return image;} static TMP_Text Text(Transform p,string name,string text,float x,float y,float w,float h,float size=26) {return Ui.Text(p,name,text,x,y,w,h,size,theme);} static RectTransform Panel(Transform parent,string name,float x,float y,float w,float h,Color color,bool block=false) {var r=Ui.Rect(parent,name,x,y,w,h);Ui.Image(r,theme.panelSprite,color,block);return r;} static TMP_FontAsset Font(string name,string file) { string path=Root+"/Theme/"+name+".asset";var asset=AssetDatabase.LoadAssetAtPath(path);if(asset)return asset; asset=TMP_FontAsset.CreateFontAsset(AssetDatabase.LoadAssetAtPath(file),48,5,GlyphRenderMode.SDFAA,1024,1024,AtlasPopulationMode.Dynamic,true);asset.name=name;AssetDatabase.CreateAsset(asset,path); asset.atlasTextures[0].name=name+EnglishCopy.Atlas;AssetDatabase.AddObjectToAsset(asset.atlasTextures[0],asset);asset.material.name=name+EnglishCopy.Material;AssetDatabase.AddObjectToAsset(asset.material,asset); asset.TryAddCharacters(string.Concat(Enumerable.Range(32,95).Select(i=>(char)i))+"×·—–↻∞",out string missing);EditorUtility.SetDirty(asset);return asset; } static void PrepareAssets() { foreach(string dir in new[]{"Theme","Prefabs","Scenes"})Directory.CreateDirectory(Root+"/"+dir);AssetDatabase.Refresh(); var map=JsonUtility.FromJson(File.ReadAllText(Root+"/Resources/Fateforge/art-map.json")); foreach(var entry in map.entries.Where(e=>e.path.StartsWith(Root+"/Imported/")&&e.path.EndsWith(".png"))){var importer=(TextureImporter)AssetImporter.GetAtPath(entry.path);if(importer.textureType!=TextureImporterType.Sprite){importer.textureType=TextureImporterType.Sprite;importer.spriteImportMode=SpriteImportMode.Single;importer.mipmapEnabled=false;importer.alphaIsTransparency=true;importer.maxTextureSize=4096;importer.SaveAndReimport();}} art=AssetDatabase.LoadAssetAtPath(Root+"/Theme/ArtLibrary.asset");if(!art){art=ScriptableObject.CreateInstance();AssetDatabase.CreateAsset(art,Root+"/Theme/ArtLibrary.asset");} art.entries=map.entries.Select(e=>new ArtEntry{id=e.id,sprite=AssetDatabase.LoadAssetAtPath(e.path),audio=AssetDatabase.LoadAssetAtPath(e.path)}).ToList(); var aliases=new[]{("reel_start","spinSound"),("reel_stop","stopSound"),("match","matchSound"),("victory","victorySound"),("coin","rewardSound"),("perfect","victorySound"),("scatter","spinSound")}; foreach(var pair in aliases){var source=art.entries.First(x=>x.id==pair.Item2);art.entries.Add(new ArtEntry{id=pair.Item1,audio=source.audio});} art.content=AssetDatabase.LoadAssetAtPath(Root+"/Resources/Fateforge/content.json");EditorUtility.SetDirty(art); theme=AssetDatabase.LoadAssetAtPath(Root+"/Theme/PortraitTheme.asset");if(!theme){theme=ScriptableObject.CreateInstance();AssetDatabase.CreateAsset(theme,Root+"/Theme/PortraitTheme.asset");} theme.bodyFont=Font("CasinoSerif","Assets/Fateforge/Art/Fonts/CrimsonText-Regular.ttf");theme.titleFont=Font("CasinoSerifBold","Assets/Fateforge/Art/Fonts/CrimsonText-Bold.ttf");theme.titleFont.fallbackFontAssetTable=new System.Collections.Generic.List{theme.bodyFont};theme.bodyFont.fallbackFontAssetTable=new System.Collections.Generic.List{Font(EnglishCopy.ReadableLatin,"Assets/Fateforge/Resources/Fateforge/Fonts/NotoSansSC-Regular.ttf")};theme.bodyFont.TryAddCharacters("…×·◆◇",out string missingSymbols);var italic=Font("CasinoSerifItalic","Assets/Fateforge/Art/Fonts/CrimsonText-Italic.ttf");var boldItalic=Font("CasinoSerifBoldItalic","Assets/Fateforge/Art/Fonts/CrimsonText-BoldItalic.ttf"); foreach(var face in new[]{theme.bodyFont,theme.titleFont}){face.fontWeightTable[4].regularTypeface=face;face.fontWeightTable[4].italicTypeface=italic;for(int weight=5;weight<=9;weight++){face.fontWeightTable[weight].regularTypeface=theme.titleFont;face.fontWeightTable[weight].italicTypeface=boldItalic;}EditorUtility.SetDirty(face);} italic.TryAddCharacters("…",out missingSymbols);boldItalic.TryAddCharacters("…",out missingSymbols);EditorUtility.SetDirty(italic);EditorUtility.SetDirty(boldItalic); string panelPath=Root+"/Theme/RoundedPanel.png"; if(!File.Exists(panelPath)){var texture=new Texture2D(64,64,TextureFormat.RGBA32,false);for(int y=0;y<64;y++)for(int x=0;x<64;x++){float dx=Mathf.Max(12-x,x-51),dy=Mathf.Max(12-y,y-51);float a=1-Mathf.Clamp01(Mathf.Sqrt(Mathf.Max(0,dx)*Mathf.Max(0,dx)+Mathf.Max(0,dy)*Mathf.Max(0,dy))-11);texture.SetPixel(x,y,new Color(1,1,1,a));}texture.Apply();File.WriteAllBytes(panelPath,texture.EncodeToPNG());UnityEngine.Object.DestroyImmediate(texture);AssetDatabase.ImportAsset(panelPath);var importer=(TextureImporter)AssetImporter.GetAtPath(panelPath);importer.textureType=TextureImporterType.Sprite;importer.spriteImportMode=SpriteImportMode.Single;importer.spriteBorder=new Vector4(16,16,16,16);importer.alphaIsTransparency=true;importer.mipmapEnabled=false;importer.SaveAndReimport();} theme.panelSprite=AssetDatabase.LoadAssetAtPath(panelPath);theme.reelMotion=AssetDatabase.LoadAssetAtPath(Root+"/Theme/ReelMotion.mat");if(!theme.reelMotion){theme.reelMotion=new Material(Shader.Find("Fateforge/Reel Motion"));AssetDatabase.CreateAsset(theme.reelMotion,Root+"/Theme/ReelMotion.mat");}PhysicalSkinImporter.Import(theme);EditorUtility.SetDirty(theme);AssetDatabase.SaveAssets(); } static GameObject SavePrefab(GameObject root,string name) {var prefab=PrefabUtility.SaveAsPrefabAsset(root,Root+"/Prefabs/"+name+".prefab");UnityEngine.Object.DestroyImmediate(root);return prefab;} static void Prefabs(ViewBindings v) { var action=Ui.Button(null,"ActionButton",EnglishCopy.Continue,0,0,560,88,theme,null,true);v.actionPrefab=SavePrefab(action.gameObject,"ActionButton").GetComponent