| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- 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<FateforgeApp>();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<TMP_FontAsset>(path);if(asset)return asset;
- asset=TMP_FontAsset.CreateFontAsset(AssetDatabase.LoadAssetAtPath<Font>(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<ArtMap>(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<ArtLibrary>(Root+"/Theme/ArtLibrary.asset");if(!art){art=ScriptableObject.CreateInstance<ArtLibrary>();AssetDatabase.CreateAsset(art,Root+"/Theme/ArtLibrary.asset");}
- art.entries=map.entries.Select(e=>new ArtEntry{id=e.id,sprite=AssetDatabase.LoadAssetAtPath<Sprite>(e.path),audio=AssetDatabase.LoadAssetAtPath<AudioClip>(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<TextAsset>(Root+"/Resources/Fateforge/content.json");EditorUtility.SetDirty(art);
- theme=AssetDatabase.LoadAssetAtPath<UiTheme>(Root+"/Theme/PortraitTheme.asset");if(!theme){theme=ScriptableObject.CreateInstance<UiTheme>();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<TMP_FontAsset>{theme.bodyFont};theme.bodyFont.fallbackFontAssetTable=new System.Collections.Generic.List<TMP_FontAsset>{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<Sprite>(panelPath);theme.reelMotion=AssetDatabase.LoadAssetAtPath<Material>(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<Button>();
- var root=Panel(null,"Card",0,0,140,140,new Color(.12f,.07f,.22f),true);var card=root.gameObject.AddComponent<CardView>();var bg=Art(root,"card",0,0,140,140);Ui.Stretch(bg.rectTransform);
- card.symbol=Art(root,"citron",0,0,110,110);Ui.Stretch(card.symbol.rectTransform,12,12,12,12);
- card.frame=Art(root,"frame",0,0,140,140);Ui.Stretch(card.frame.rectTransform);card.value=Text(root,"Value","15",-44,1,48,34,21);card.value.rectTransform.anchorMin=card.value.rectTransform.anchorMax=new Vector2(0,1);card.value.rectTransform.anchoredPosition=new Vector2(24,-1);
- card.sticker=Art(root,"compte_double",0,0,35,35);card.sticker.rectTransform.anchorMin=card.sticker.rectTransform.anchorMax=Vector2.one;card.sticker.rectTransform.pivot=Vector2.one;card.sticker.rectTransform.anchoredPosition=new Vector2(-3,-102);card.sticker.rectTransform.anchorMin=card.sticker.rectTransform.anchorMax=new Vector2(1,0);card.sticker.rectTransform.anchoredPosition=new Vector2(-3,37);
- card.mark=Text(root,"Status","",0,0,64,30,17);card.mark.rectTransform.anchorMin=card.mark.rectTransform.anchorMax=new Vector2(.5f,0);card.mark.rectTransform.anchoredPosition=new Vector2(0,30);
- v.cardPrefab=SavePrefab(root.gameObject,"Card").GetComponent<CardView>();
- root=Panel(null,"MarketOffer",0,0,205,166,theme.panel);var offer=root.gameObject.AddComponent<OfferView>();offer.details=Ui.Button(root,"Details","",0,0,205,88,theme);Ui.Stretch((RectTransform)offer.details.transform,0,0,0,78);offer.details.GetComponent<Image>().color=Color.clear;
- offer.icon=Art(offer.details.transform,"market_elixir",0,3,76,82);Ui.Stretch(offer.icon.rectTransform,44,4,44,4);
- offer.charge=Art(offer.details.transform,"citron",66,0,32,32);offer.charge.rectTransform.anchorMin=offer.charge.rectTransform.anchorMax=Vector2.one;offer.charge.rectTransform.anchoredPosition=new Vector2(-21,-4);
- offer.buy=Ui.Button(root,"Buy","4",0,78,205,88,theme,null,true);var buyRect=(RectTransform)offer.buy.transform;buyRect.anchorMin=new Vector2(0,0);buyRect.anchorMax=new Vector2(1,0);buyRect.pivot=new Vector2(.5f,0);buyRect.anchoredPosition=Vector2.zero;buyRect.sizeDelta=new Vector2(0,88);offer.price=offer.buy.GetComponentInChildren<TMP_Text>();v.offerPrefab=SavePrefab(root.gameObject,"MarketOffer").GetComponent<OfferView>();
- root=Panel(null,"GuideEntry",0,0,600,132,new Color(.15f,.10f,.22f));var icon=Art(root,"swap",-246,14,86,100);icon.name="Icon";Text(root,"Name","Trick",64,8,434,38,27).alignment=TextAlignmentOptions.MidlineLeft;Text(root,"Description","Description",64,48,434,78,23).alignment=TextAlignmentOptions.TopLeft;v.guideEntryPrefab=SavePrefab(root.gameObject,"GuideEntry");
- }
- [MenuItem("Fateforge/Build Portrait Scene")]
- public static void Build()
- {
- if(EditorApplication.isPlaying)throw new InvalidOperationException(EnglishCopy.StopPlayModeBeforeRebuildingThePortrait);PrepareAssets();
- var scene=EditorSceneManager.NewScene(NewSceneSetup.EmptyScene,NewSceneMode.Single);var camera=new GameObject(EnglishCopy.MainCamera,typeof(Camera),typeof(AudioListener));camera.tag="MainCamera";var cam=camera.GetComponent<Camera>();cam.clearFlags=CameraClearFlags.SolidColor;cam.backgroundColor=theme.background;cam.orthographic=true;camera.transform.position=new Vector3(0,0,-10);
- new GameObject("EventSystem",typeof(EventSystem),typeof(StandaloneInputModule));
- var canvasGo=new GameObject(EnglishCopy.FateforgeCanvas,typeof(RectTransform),typeof(Canvas),typeof(CanvasScaler),typeof(GraphicRaycaster));var canvas=canvasGo.GetComponent<Canvas>();canvas.renderMode=RenderMode.ScreenSpaceOverlay;var scaler=canvasGo.GetComponent<CanvasScaler>();scaler.uiScaleMode=CanvasScaler.ScaleMode.ScaleWithScreenSize;scaler.referenceResolution=new Vector2(750,1334);scaler.screenMatchMode=CanvasScaler.ScreenMatchMode.MatchWidthOrHeight;scaler.matchWidthOrHeight=0;
- var v=canvasGo.AddComponent<ViewBindings>();v.theme=theme;v.art=art;Prefabs(v);
- v.background=Art(canvasGo.transform,"home_background",0,0,750,1334);Ui.Stretch(v.background.rectTransform);v.background.preserveAspect=false;v.background.color=new Color(.39f,.28f,.45f);var tint=Panel(canvasGo.transform,"PurpleVeil",0,0,750,1334,new Color(.07f,.025f,.13f,.72f));Ui.Stretch(tint);
- v.safeArea=Ui.Rect(canvasGo.transform,"SafeArea",0,0,750,1334);Ui.Stretch(v.safeArea);
- v.home=Ui.Rect(v.safeArea,EnglishCopy.Home,0,0,750,1334);Ui.Stretch(v.home);
- Text(v.home,"Kicker",EnglishCopy.ALITTLELUCKALITTLEMAGIC,0,170,700,40,22).color=theme.gold;
- var logo=Text(v.home,"Logo",EnglishCopy.FateforgeSlots,0,220,700,210,87);logo.font=theme.titleFont;logo.color=theme.text;logo.lineSpacing=-15;logo.enableAutoSizing=true;logo.fontSizeMin=42;logo.fontSizeMax=87;
- var buttons=Ui.Rect(v.home,"Buttons",0,500,500,520);
- v.normalRun=Ui.Button(buttons,"NormalMode",EnglishCopy.NormalMode,0,0,500,88,theme,null,true);
- v.endlessRun=Ui.Button(buttons,"EndlessMode",EnglishCopy.EndlessMode,0,108,500,88,theme);
- v.homeSettings=Ui.Button(buttons,EnglishCopy.Settings,English.Settings,0,216,500,88,theme);
- v.homeHelp=Ui.Button(buttons,EnglishCopy.Help,English.Help,0,324,500,88,theme);
- v.leaderboard=Ui.Button(buttons,"Leaderboard","Leaderboard",0,432,500,88,theme);
- v.saveStatus=Text(v.home,"SaveStatus","",0,1110,650,50,20);v.saveStatus.color=theme.muted;
- var motif=Art(v.home,"spirit",0,975,130,150);Art(motif.transform,"spirit_eyes",-3,103,30,30);
- v.play=Ui.Rect(v.safeArea,"Play",0,0,750,1334);Ui.Stretch(v.play);
- v.menu=Ui.Button(v.play,"Menu","Menu",-305,12,100,88,theme);v.help=Ui.Button(v.play,EnglishCopy.Help,"?",305,12,100,88,theme);v.title=Text(v.play,"Brand",EnglishCopy.FateforgeSlots853b01,0,24,480,50,39);v.title.font=theme.titleFont;v.title.enableAutoSizing=true;v.title.fontSizeMin=24;v.title.fontSizeMax=39;
- v.level=Text(v.play,"Level",English.NormalLevel(1),-145,106,400,36,23);v.level.color=theme.muted;v.coins=Text(v.play,EnglishCopy.Coins2bef47,EnglishCopy.Text5COINS,242,106,170,36,24);v.coins.color=theme.cyan;
- v.magnetRack=Ui.Rect(v.play,"MagnetRack",0,154,680,80);
- v.cabinet=Panel(v.play,"Cabinet",0,236,702,828,new Color(.54f,.35f,.13f));var rim=Panel(v.cabinet,"InnerRim",0,8,686,812,new Color(.23f,.12f,.09f));Ui.Stretch(rim,8,8,8,8);var velvet=Panel(rim,"Velvet",0,12,658,782,new Color(.13f,.045f,.18f));Ui.Stretch(velvet,14,12,14,14);
- var crown=Art(v.cabinet,"crown",0,-35,648,108);crown.raycastTarget=false;
- var scorePanel=Panel(v.cabinet,"ScoreReadout",0,40,612,66,new Color(.075f,.04f,.10f,.95f));Text(scorePanel,"ScoreCaption","SCORE",-232,2,100,24,17).color=theme.muted;v.score=Text(scorePanel,EnglishCopy.Score,"0",-147,23,260,39,28);Text(scorePanel,"TargetCaption","TARGET",212,2,120,24,17).color=theme.muted;v.target=Text(scorePanel,EnglishCopy.Target,"4,000",151,23,260,39,28);v.target.color=theme.gold;Text(scorePanel,"Separator","/",0,17,30,42,26).color=theme.muted;
- v.marketTitle=Text(v.cabinet,"MarketTitle",English.Market,0,47,600,54,34);v.marketTitle.font=theme.titleFont;
- v.boardArea=Ui.Rect(v.cabinet,"CabinetInterior",0,116,650,528);v.boardArea.gameObject.AddComponent<RectMask2D>();v.board=Ui.Rect(v.boardArea,"Reels",0,0,650,528);Ui.Stretch(v.board);v.boardGroup=v.board.gameObject.AddComponent<CanvasGroup>();v.market=Ui.Rect(v.boardArea,"Market",0,0,650,528);Ui.Stretch(v.market);
- v.directions=Text(v.cabinet,"MatchMultipliers","--- 1.75 | 2.00 / 2.25",0,623,610,34,21);
- v.formula=Ui.Rect(v.cabinet,"RoundPreview",0,652,580,74);Text(v.formula,"Caption",English.RoundPreview,0,0,580,24,17).color=theme.muted;
- v.previewPoints=Text(v.formula,"BasePoints","0",-194,27,180,44,30);Text(v.formula,"Multiply","×",-86,26,42,44,26).color=theme.muted;v.previewMultiplier=Text(v.formula,EnglishCopy.Multiplier,"0.00",6,27,128,44,30);Text(v.formula,"Equals","=",96,26,40,44,26).color=theme.muted;v.previewTotal=Text(v.formula,"Total","0",208,27,170,44,30);v.previewTotal.color=theme.gold;
- v.dock=Ui.Rect(v.cabinet,"PrimaryActions",0,730,654,88);v.collect=Ui.Button(v.dock,"Collect",EnglishCopy.Collect3,-22,0,430,88,theme,null,true);
- v.deck=Ui.Button(v.cabinet,"DeckDrawer","",293,730,88,88,theme);var drawer=Panel(v.deck.transform,"Drawer",0,24,54,42,theme.gold);Panel(drawer,"Opening",0,5,40,11,theme.background);Panel(drawer,"Handle",0,27,18,4,theme.background);
- v.equipment=Ui.Rect(v.play,"Equipment",0,1110,702,200);v.spirit=Art(v.equipment,"spirit",-264,8,190,188);v.spirit.color=new Color(.35f,.9f,1.6f);Art(v.spirit.transform,"spirit_eyes",-4,129,35,35);
- var bar=Panel(v.equipment,"EnergyTrack",-264,168,148,18,new Color(.08f,.15f,.2f));v.energyFill=Ui.Image(Ui.Rect(bar,"EnergyFill",0,0,148,18),theme.panelSprite,theme.cyan);Ui.Stretch(v.energyFill.rectTransform);v.energyFill.type=Image.Type.Filled;v.energyFill.fillMethod=Image.FillMethod.Horizontal;
- var energyIcon=Art(v.equipment,"energy_icon",-330,152,48,48);v.energy=Text(energyIcon.transform,EnglishCopy.Energy,"3",0,4,42,40,23);v.energy.color=theme.background;
- v.tricks=Ui.Rect(v.equipment,EnglishCopy.Tricks,-125,8,100,185);v.tickets=Ui.Rect(v.equipment,EnglishCopy.Tickets,205,0,294,190);
- v.hint=Text(v.play,"Hint",EnglishCopy.ShapeYourMatchesThenCollect,0,1305,700,24,17);v.hint.color=theme.muted;
- v.modal=Ui.Rect(v.safeArea,"ModalLayer",0,0,750,1334);Ui.Stretch(v.modal);Ui.Image(v.modal,null,new Color(.025f,.012f,.045f,.92f),true);
- v.modalPanel=Panel(v.modal,"Dialog",0,107,702,1120,theme.gold,true);var fill=Panel(v.modalPanel,"Fill",0,3,696,1114,theme.panel,true);Ui.Stretch(fill,3,3,3,3);v.modalTitle=Text(v.modalPanel,"Title",EnglishCopy.Settings,-20,24,550,66,37);v.modalTitle.font=theme.titleFont;v.modalClose=Ui.Button(v.modalPanel,"Close","×",292,14,88,88,theme);
- var viewport=Ui.Rect(v.modalPanel,"Viewport",0,120,650,960);Ui.Stretch(viewport,24,120,24,24);viewport.gameObject.AddComponent<RectMask2D>();Ui.Image(viewport,null,Color.clear,true);v.modalBody=Ui.Rect(viewport,"Content",0,0,650,800);v.modalBody.anchorMin=new Vector2(0,1);v.modalBody.anchorMax=Vector2.one;v.modalBody.sizeDelta=new Vector2(0,800);var scroll=viewport.gameObject.AddComponent<ScrollRect>();scroll.content=v.modalBody;scroll.viewport=viewport;scroll.horizontal=false;scroll.movementType=ScrollRect.MovementType.Clamped;scroll.scrollSensitivity=38;
- v.quickLayer=Ui.Rect(v.safeArea,"TooltipLayer",0,0,750,1334);Ui.Stretch(v.quickLayer);Ui.Image(v.quickLayer,null,new Color(0,0,0,.2f),true);v.quickClose=v.quickLayer.gameObject.AddComponent<Button>();v.quickClose.transition=Selectable.Transition.None;
- v.quickPanel=Panel(v.quickLayer,"Tooltip",0,300,650,240,new Color(.23f,.15f,.30f),true);v.quickTitle=Text(v.quickPanel,"Title","Card",0,18,590,45,29);v.quickTitle.color=theme.gold;v.quickBody=Ui.Rect(v.quickPanel,"Body",0,76,600,155);Ui.Stretch(v.quickBody,22,76,22,16);
- canvasGo.AddComponent<SafeAreaLayout>().view=v;canvasGo.AddComponent<FateforgeApp>().view=v;v.modal.gameObject.SetActive(false);v.quickLayer.gameObject.SetActive(false);v.play.gameObject.SetActive(false);
- PlayerSettings.productName=EnglishCopy.FateforgeSlots853b01;PlayerSettings.defaultInterfaceOrientation=UIOrientation.Portrait;PlayerSettings.allowedAutorotateToLandscapeLeft=false;PlayerSettings.allowedAutorotateToLandscapeRight=false;PlayerSettings.allowedAutorotateToPortraitUpsideDown=false;PlayerSettings.defaultScreenWidth=750;PlayerSettings.defaultScreenHeight=1334;
- CarnivalSceneStyler.Apply(v);PhysicalSceneStyler.Apply(v);EditorSceneManager.SaveScene(scene,ScenePath);var others=EditorBuildSettings.scenes.Where(s=>s.path!=ScenePath).ToList();others.Insert(0,new EditorBuildSettingsScene(ScenePath,true));EditorBuildSettings.scenes=others.ToArray();AssetDatabase.SaveAssets();Resolution(750,1334);Debug.Log(EnglishCopy.FateforgePortraitSceneAndPrefabsCreated);
- }
- public static void Resolution(int width,int height)
- {
- var assembly=typeof(EditorWindow).Assembly;var flags=BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance;var sizesType=assembly.GetType("UnityEditor.GameViewSizes");var sizes=sizesType.GetProperty("instance",BindingFlags.Static|BindingFlags.Public|BindingFlags.FlattenHierarchy).GetValue(null);var group=sizesType.GetProperty("currentGroup",flags).GetValue(sizes);var type=group.GetType();string label=EnglishCopy.Fateforge+width+"x"+height;var labels=(string[])type.GetMethod("GetDisplayTexts").Invoke(group,null);int index=Array.FindIndex(labels,s=>s.Contains(label));
- if(index<0){var size=Activator.CreateInstance(assembly.GetType("UnityEditor.GameViewSize"),Enum.Parse(assembly.GetType("UnityEditor.GameViewSizeType"),"FixedResolution"),width,height,label);type.GetMethod("AddCustomSize").Invoke(group,new[]{size});index=(int)type.GetMethod("GetTotalCount").Invoke(group,null)-1;}
- var viewType=assembly.GetType("UnityEditor.GameView");var window=EditorWindow.GetWindow(viewType);viewType.GetProperty("selectedSizeIndex",flags).SetValue(window,index);window.Repaint();
- }
- }
- }
|