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

Commit

Permalink
Fixed RunBeforeFlowManager
Browse files Browse the repository at this point in the history
Thanks for the fix Slaynash
  • Loading branch information
AtiLion committed Aug 28, 2019
1 parent 7e41f4e commit fca1cc5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 90 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ IEnumerator updateCheck() {
// Display some message to user
}
```
> **Note:** This is currently broken! Please use VRCMenuUtilsAPI.WaitForInit() instead!

after which you can take advantage of its functions.
To create a new user info button, you need to create a new VRCEUiButton, and assign it your OnClick event. This can be done as follows:
Expand Down
4 changes: 2 additions & 2 deletions VRCMenuUtils/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.3.1")]
[assembly: AssemblyFileVersion("0.0.3.1")]
[assembly: AssemblyVersion("0.0.3.2")]
[assembly: AssemblyFileVersion("0.0.3.2")]
133 changes: 46 additions & 87 deletions VRCMenuUtils/VRCMenuUtilsAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@ public static class VRCMenuUtilsAPI
private static bool _FlowManagerPaused = false;
private static bool _FlowManagerFinished = false;
private static bool _HookedSceneLoad = false;
private static bool _LoadingUI = false;

private static Queue<IEnumerator> _PreFlowExectution = new Queue<IEnumerator>();
#endregion
#region VRCMenuUtils Properties
public static bool IsIntialized => _UIInitialized;
public static string Version => "0.3.1";
public static string Version => "0.3.2";
#endregion
#region VRCMenuUtils Delegates
public delegate void ElementChangeDelegate(Transform transform);
Expand All @@ -43,107 +42,66 @@ public static class VRCMenuUtilsAPI
#region VRCMenuUtils Coroutine Functions
public static IEnumerator WaitForInit()
{
#if DEBUG
VRCFlowManager flowManager = Resources.FindObjectsOfTypeAll<VRCFlowManager>().FirstOrDefault();
TryHookFlowManager();

if (flowManager == null)
{
if (GameObject.Find("UserInterface") == null && !_HookedSceneLoad)
{
_HookedSceneLoad = true;
SceneManager.sceneLoaded += (Scene scene, LoadSceneMode mode) =>
{
if (!_FlowManagerFinished && !_FlowManagerPaused && scene.buildIndex == 0)
{
// Disable FlowManager
DisableFlowManager();

if (!_StartedUp)
{
_StartedUp = true;

Resources.FindObjectsOfTypeAll<VRCFlowManager>().First().StartCoroutine(SetupUI());
}
}
};
}
}
else
{
if (!_FlowManagerFinished && !_FlowManagerPaused)
{
// Disable FlowManager
DisableFlowManager();
}
if (!_StartedUp)
{
_StartedUp = true;

flowManager.StartCoroutine(SetupUI());
}
}
#else
if (!_StartedUp)
{
_StartedUp = true;
yield return SetupUI();
}
#endif

while (!_UIInitialized)
yield return null;
}
#endregion
#region VRCMenuUtils Functions
public static void RunBeforeFlowManager(IEnumerator func)
private static void TryHookFlowManager()
{
#if DEBUG
if (_FlowManagerFinished)
// Can only run before UI
if (GameObject.Find("UserInterface") == null)
{
MVRCLogger.LogError("Attmpted to run function, after flow manager has been started!");
return;
}
VRCFlowManager flowManager = Resources.FindObjectsOfTypeAll<VRCFlowManager>().FirstOrDefault();
// In inital scene, execute
if (SceneManager.GetActiveScene().buildIndex == 0)
{
// Do not allow scene load hooks
_HookedSceneLoad = true;

if(flowManager == null)
{
if (GameObject.Find("UserInterface") == null && !_HookedSceneLoad)
if (!_FlowManagerPaused && !_FlowManagerFinished)
DisableFlowManager();
}
else if (!_HookedSceneLoad)
{
// Already hooked
_HookedSceneLoad = true;

SceneManager.sceneLoaded += (Scene scene, LoadSceneMode mode) =>
{
if (!_FlowManagerFinished && !_FlowManagerPaused && scene.buildIndex == 0)
{
// Disable FlowManager
DisableFlowManager();

if (!_StartedUp)
{
_StartedUp = true;

Resources.FindObjectsOfTypeAll<VRCFlowManager>().First().StartCoroutine(SetupUI());
}
}
};
}
}
else
}
public static void RunBeforeFlowManager(IEnumerator func)
{
if (_FlowManagerFinished)
{
if (!_FlowManagerPaused)
{
// Disable FlowManager
DisableFlowManager();
}
if (!_StartedUp)
{
_StartedUp = true;

flowManager.StartCoroutine(SetupUI());
}
MVRCLogger.LogError("Attmpted to run function, after before flow manager has finished!");
return;
}
TryHookFlowManager();

_PreFlowExectution.Enqueue(func);
#endif

if (!_StartedUp)
{
GameObject obj = new GameObject();
obj.AddComponent<AnimateOnEnabled>().StartCoroutine(SetupUI());
GameObject.DontDestroyOnLoad(obj);

_StartedUp = true;

}
}
#endregion

Expand Down Expand Up @@ -191,28 +149,33 @@ public static void InputAlert(string title, string text, InputField.InputType ty
public static void InputAlert(string title, string text, InputField.InputType type, bool useNumericKeypad, string buttonText, Action<string, List<KeyCode>, Text> submitAction, Action cancelAction, string placeHolder = "Enter text....", bool hideOnSubmit = true, Action<VRCUiPopup> additionalSetup = null) =>
VRCUiPopupManager?.ShowUnityInputPopupWithCancel(title, text, type, useNumericKeypad, buttonText, submitAction, cancelAction, placeHolder, hideOnSubmit, additionalSetup);

#if DEBUG
internal static void EnableFlowManager()
{
foreach (VRCFlowManager flowManager in Resources.FindObjectsOfTypeAll<VRCFlowManager>())
flowManager.enabled = true;
_FlowManagerPaused = false;
MVRCLogger.LogWarning("Enabled Flow Manager!");
}
internal static void DisableFlowManager()
internal static void DisableFlowManager() // Thanks Slaynash for the code
{
_FlowManagerPaused = true;
foreach (VRCFlowManager flowManager in Resources.FindObjectsOfTypeAll<VRCFlowManager>())
VRCFlowManager[] managers = Resources.FindObjectsOfTypeAll<VRCFlowManager>();

foreach (VRCFlowManager flowManager in managers)
flowManager.enabled = false;
if (GameObject.Find("UserInterface") == null && !_LoadingUI)
if (GameObject.Find("UserInterface") == null)
{
_LoadingUI = true;
IEnumerator loadUi()
{
yield return null;
SceneManager.LoadScene("ui", LoadSceneMode.Single);
}

MVRCLogger.Log("Loading UserInterface...");
SceneManager.LoadScene("ui", LoadSceneMode.Single);
managers[0].StartCoroutine(loadUi());
}
MVRCLogger.LogWarning("Disabled Flow Manager!");
}
#endif
#endregion

#region UserInfo Variables
Expand Down Expand Up @@ -341,18 +304,15 @@ private static IEnumerator SetupUI()
}
MVRCLogger.Log("VRCUiManager has been loaded!");

#if !DEBUG
// Check for updates
//RunBeforeFlowManager(CheckForUpdates());
#endif
RunBeforeFlowManager(CheckForUpdates());

// Setup UserInfo
yield return SetupUserInfo();

// Setup Quick Menu
yield return SetupQuickMenu();

#if DEBUG
// Run pre-flow manager functions
while (!_FlowManagerPaused)
yield return null;
Expand All @@ -362,7 +322,6 @@ private static IEnumerator SetupUI()
// Finish
EnableFlowManager();
_FlowManagerFinished = true;
#endif
OnUserInfoButtonAdd += _UserInfoButtonAdded;
OnQuickMenuButtonAdd += _QuickMenuButtonAdded;
_UIInitialized = true;
Expand Down

0 comments on commit fca1cc5

Please sign in to comment.