From 313602a1674105b022872ba3767a02fa1c8667c1 Mon Sep 17 00:00:00 2001 From: Yoooi Date: Sun, 22 May 2022 16:37:14 +0200 Subject: [PATCH] Fix slider element not getting destroyed when UI is not visible --- src/UI/UIManager.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/UI/UIManager.cs b/src/UI/UIManager.cs index a717006..7383419 100644 --- a/src/UI/UIManager.cs +++ b/src/UI/UIManager.cs @@ -1,4 +1,5 @@ -using UnityEngine; +using System.Collections.Generic; +using UnityEngine; namespace ToySerialController.UI { @@ -6,6 +7,7 @@ public class UIManager { private static UIManager Instance; private MVRScript plugin; + private Dictionary jsonStorableFloatToSlider; public static Transform ConfigurableTextFieldPrefab => Instance.plugin.manager.configurableTextFieldPrefab; public static Transform ConfigurablePopupPrefab => Instance.plugin.manager.configurablePopupPrefab; @@ -16,6 +18,8 @@ public class UIManager private UIManager(MVRScript plugin) { this.plugin = plugin; + + jsonStorableFloatToSlider = new Dictionary(); } public static void Initialize(MVRScript plugin) @@ -43,8 +47,11 @@ public static void RemoveTextField(JSONStorableString storable) public static void RemoveSlider(JSONStorableFloat storable) { + var dynamicSlider = Instance.jsonStorableFloatToSlider[storable]; + Instance.jsonStorableFloatToSlider.Remove(storable); + Instance.plugin.DeregisterFloat(storable); - Instance.plugin.RemoveSlider(storable); + Instance.plugin.RemoveSlider(dynamicSlider); } public static void RemovePopup(JSONStorableStringChooser storable) @@ -71,7 +78,10 @@ public static UIDynamicTextField CreateTextField(JSONStorableString storable, bo public static UIDynamicSlider CreateSlider(JSONStorableFloat storable, bool rightSide) { Instance.plugin.RegisterFloat(storable); - return Instance.plugin.CreateSlider(storable, rightSide); + var dynamicSlider = Instance.plugin.CreateSlider(storable, rightSide); + + Instance.jsonStorableFloatToSlider.Add(storable, dynamicSlider); + return dynamicSlider; } public static UIDynamicPopup CreateScrollablePopup(JSONStorableStringChooser storable, bool rightSide)