public CanvasPanel AddPanel(string name, Texture2D tex, Vector2 pos, Vector2 sz, Rect bgSubSection) { CanvasPanel panel = new CanvasPanel(canvas, tex, position + pos, sz, bgSubSection); panels.Add(name, panel); return(panel); }
public static void BuildMenu(GameObject canvas) { Log("Building Skin Swapper Panel"); y = 30.0f; Panel = new CanvasPanel( canvas, GUIController.Instance.images["Panel_BG"], new Vector2(0, y), Vector2.zero, new Rect(0, 0, GUIController.Instance.images["Panel_BG"].width, 60) ); float textHeight = 90; Panel.AddText( "Change Skin Text", "Change Skin", new Vector2(0, y), new Vector2(GUIController.Instance.images["Panel_BG"].width, textHeight), GUIController.Instance.trajanNormal, 24, FontStyle.Bold, TextAnchor.MiddleCenter ); y += textHeight; GC.Collect(); foreach (string path in Directory.GetDirectories(CustomKnight.DATA_DIR)) { string directoryName = new DirectoryInfo(path).Name; Texture2D tex = null; int imageHeight = 128; int imageWidth = 300; if (File.Exists((CustomKnight.DATA_DIR + "/" + directoryName + "/Icon.png").Replace("\\", "/"))) { byte[] iconBytes = File.ReadAllBytes((CustomKnight.DATA_DIR + "/" + directoryName + "/Icon.png").Replace("\\", "/")); Texture2D icon = new Texture2D(2, 2); bool isLoaded = icon.LoadImage(iconBytes, true); if (isLoaded) { tex = Resize(icon, imageWidth, imageHeight); } } else if (File.Exists((CustomKnight.DATA_DIR + "/" + directoryName + "/icon.png").Replace("\\", "/"))) { byte[] iconBytes = File.ReadAllBytes((CustomKnight.DATA_DIR + "/" + directoryName + "/icon.png").Replace("\\", "/")); Texture2D icon = new Texture2D(2, 2); bool isLoaded = icon.LoadImage(iconBytes, true); if (isLoaded) { tex = Resize(icon, imageWidth, imageHeight); } } else if (File.Exists((CustomKnight.DATA_DIR + "/" + directoryName + "/Knight.png").Replace("\\", "/"))) { byte[] knightBytes = File.ReadAllBytes((CustomKnight.DATA_DIR + "/" + directoryName + "/Knight.png").Replace("\\", "/")); Texture2D knightTex = new Texture2D(2, 2); bool isLoaded = knightTex.LoadImage(knightBytes, true); if (isLoaded) { Color[] colors = knightTex.GetPixels(2890, 2523, imageWidth, imageHeight); tex = new Texture2D(imageWidth, imageHeight); tex.SetPixels(colors); tex.Apply(); } } else { tex = new Texture2D(imageWidth, imageHeight); } Panel.AddButton( directoryName, tex, new Vector2(0, y), Vector2.zero, ChangeSkin, new Rect(0, y, imageWidth, imageHeight), GUIController.Instance.trajanNormal, directoryName, 24 ); y += imageHeight; GC.Collect(); } Panel.SetActive(false, true); Vector2 newPanelSize = new Vector2(GUIController.Instance.images["Panel_BG"].width, y); Panel.ResizeBG(newPanelSize); On.HeroController.Pause += OnPause; On.HeroController.UnPause += OnUnpause; UnityEngine.SceneManagement.SceneManager.activeSceneChanged += OnSceneChange; }