diff --git a/project/SPT.Custom/Patches/EasyAssetsPatch.cs b/project/SPT.Custom/Patches/EasyAssetsPatch.cs index 87f8ae9..090f383 100644 --- a/project/SPT.Custom/Patches/EasyAssetsPatch.cs +++ b/project/SPT.Custom/Patches/EasyAssetsPatch.cs @@ -78,6 +78,9 @@ namespace SPT.Custom.Patches var bundles = (IEasyBundle[])Array.CreateInstance(EasyBundleHelper.Type, bundleNames.Length); + var bundleUtils = BundleUtils.Create(); + bundleUtils.Init(bundleNames.Length); + for (var i = 0; i < bundleNames.Length; i++) { var key = bundleNames[i]; @@ -86,6 +89,8 @@ namespace SPT.Custom.Patches // acquire external bundle if (BundleManager.Bundles.TryGetValue(key, out var bundleInfo)) { + bundleUtils.SetProgress(i, bundleInfo.FileName); + // we need base path without file extension path = BundleManager.GetBundlePath(bundleInfo); @@ -107,6 +112,8 @@ namespace SPT.Custom.Patches }); } + bundleUtils.Dispose(); + // create dependency graph instance.Manifest = manifest; _bundlesField.SetValue(instance, bundles); diff --git a/project/SPT.Custom/SPT.Custom.csproj b/project/SPT.Custom/SPT.Custom.csproj index e503e4c..9640df3 100644 --- a/project/SPT.Custom/SPT.Custom.csproj +++ b/project/SPT.Custom/SPT.Custom.csproj @@ -24,8 +24,10 @@ + + diff --git a/project/SPT.Custom/Utils/BundleUtils.cs b/project/SPT.Custom/Utils/BundleUtils.cs new file mode 100644 index 0000000..b26bfc6 --- /dev/null +++ b/project/SPT.Custom/Utils/BundleUtils.cs @@ -0,0 +1,57 @@ +using UnityEngine; + +namespace SPT.Custom.Utils +{ + public class BundleUtils : MonoBehaviour + { + private GameObject rootObject; + private int current; + private int maximum; + private string bundleName; + private Texture2D bgTexture; + + public static BundleUtils Create() + { + GameObject bundleUtilsObject = new GameObject("BundleUtilsObject"); + BundleUtils bundleUtils = bundleUtilsObject.AddComponent(); + bundleUtils.rootObject = bundleUtilsObject; + bundleUtils.current = 0; + bundleUtils.maximum = 0; + bundleUtils.enabled = true; + bundleUtils.bgTexture = new Texture2D(2, 2); + return bundleUtils; + } + + public void Init(int length) + { + maximum = length; + } + + public void SetProgress(int progress, string fileName) + { + current = progress; + bundleName = fileName; + } + + public void Dispose() + { + Destroy(rootObject); + Destroy(this); + } + + public void OnGUI() + { + GUI.skin.label.alignment = TextAnchor.MiddleCenter; + GUI.skin.window.alignment = TextAnchor.MiddleCenter; + GUI.skin.window.normal.background = bgTexture; + GUI.backgroundColor = Color.black; + GUI.Window(0, new Rect((Screen.width / 2) - 200, (Screen.height / 2) + 200, 500, 80), DrawWindow, "Bundle Loading"); + } + + private void DrawWindow(int windowId) + { + GUI.Label(new Rect(0, 35, 500, 20), $"Loading bundle: {current} / {maximum}"); + GUI.Label(new Rect(0, 50, 500, 20), bundleName); + } + } +}