using HMUI; using IPA.Utilities; using System; using System.Linq; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; using VRUIControls; using Image = UnityEngine.UI.Image; using Logger = SongBrowser.Logging.Logger; namespace SongBrowser.Internals { public static class BeatSaberUI { private static PhysicsRaycasterWithCache _physicsRaycaster; public static PhysicsRaycasterWithCache PhysicsRaycasterWithCache { get { if (_physicsRaycaster == null) _physicsRaycaster = Resources.FindObjectsOfTypeAll().First().GetComponent().GetField("_physicsRaycaster"); return _physicsRaycaster; } } /// /// Creates a ViewController of type T, and marks it to not be destroyed. /// /// The variation of ViewController you want to create. /// The newly created ViewController of type T. public static T CreateViewController(string name) where T : ViewController { T vc = new GameObject(typeof(T).Name, typeof(VRGraphicRaycaster), typeof(CanvasGroup), typeof(T)).GetComponent(); vc.GetComponent().SetField("_physicsRaycaster", PhysicsRaycasterWithCache); vc.rectTransform.anchorMin = new Vector2(0f, 0f); vc.rectTransform.anchorMax = new Vector2(1f, 1f); vc.rectTransform.sizeDelta = new Vector2(0f, 0f); vc.rectTransform.anchoredPosition = new Vector2(0f, 0f); vc.gameObject.SetActive(false); vc.name = name; return vc; } public static T CreateCurvedViewController(string name, float curveRadius) where T : ViewController { T vc = new GameObject(typeof(T).Name, typeof(VRGraphicRaycaster), typeof(CurvedCanvasSettings), typeof(CanvasGroup), typeof(T)).GetComponent(); vc.GetComponent().SetField("_physicsRaycaster", PhysicsRaycasterWithCache); vc.GetComponent().SetRadius(curveRadius); vc.rectTransform.anchorMin = new Vector2(0f, 0f); vc.rectTransform.anchorMax = new Vector2(1f, 1f); vc.rectTransform.sizeDelta = new Vector2(0f, 0f); vc.rectTransform.anchoredPosition = new Vector2(0f, 0f); vc.gameObject.SetActive(false); return vc; } /// /// Create an icon button, simple. /// /// /// /// /// public static Button CreateIconButton(String name, RectTransform parent, String buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick, Sprite icon) { Logger.Debug("CreateIconButton({0}, {1}, {2}, {3}, {4}", name, parent, buttonTemplate, anchoredPosition, sizeDelta); Button btn = UnityEngine.Object.Instantiate(Resources.FindObjectsOfTypeAll