Skip to content
This repository has been archived by the owner on Sep 12, 2020. It is now read-only.

Commit

Permalink
Added OnPageShown+ GetPage
Browse files Browse the repository at this point in the history
  • Loading branch information
AtiLion committed Sep 8, 2019
1 parent fca1cc5 commit d564272
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion VRCMenuUtils/VRCMenuUtilsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,45 @@ public static void RunBeforeFlowManager(IEnumerator func)
#region VRChat Reflection
private static MethodInfo _miVRCUiManagerGetInstace;
private static MethodInfo _miVRCUiPopupManagerGetInstance;

private static EventInfo _eiVRCUiManagerOnPageShown;
#endregion
#region VRChat Properties
public static VRCUiManager VRCUiManager => (VRCUiManager)_miVRCUiManagerGetInstace?.Invoke(null, null);
public static VRCUiPopupManager VRCUiPopupManager => (VRCUiPopupManager)_miVRCUiPopupManagerGetInstance?.Invoke(null, null);
#endregion
#region VRChat Events
public static event Action<VRCUiPage> OnPageShown
{
add
{
if(_eiVRCUiManagerOnPageShown == null)
_eiVRCUiManagerOnPageShown = typeof(VRCUiManager).GetEvents(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(a => a.EventHandlerType == typeof(Action<VRCUiPage>));
if (VRCUiManager == null)
return;

_eiVRCUiManagerOnPageShown.AddEventHandler(VRCUiManager, value);
}
remove
{
if (_eiVRCUiManagerOnPageShown == null)
_eiVRCUiManagerOnPageShown = typeof(VRCUiManager).GetEvents(BindingFlags.Public | BindingFlags.Instance).FirstOrDefault(a => a.EventHandlerType == typeof(Action<VRCUiPage>));
if (VRCUiManager == null)
return;

_eiVRCUiManagerOnPageShown.RemoveEventHandler(VRCUiManager, value);
}
}
#endregion
#region VRChat Functions
public static void ShowUIPage(VRCUiPage page, bool removeHeader = true)
public static void ShowUIPage(VRCUiPage page, bool removeHeader = true, bool setupBody = true)
{
if(!setupBody)
{
VRCUiManager.ShowScreen(page);
return;
}

IEnumerator placeUi()
{
for (int i = 0; i < 4; i++)
Expand All @@ -130,6 +161,8 @@ IEnumerator placeUi()
VRCUiManager.StartCoroutine(placeUi());
VRCUiManager.ShowScreen(page);
}
public static VRCUiPage GetPage(string pageId) =>
VRCUiManager?.GetPage(pageId);
public static void HideCurrentPopup() =>
VRCUiPopupManager?.HideCurrentPopup();

Expand Down

0 comments on commit d564272

Please sign in to comment.