Skip to content

Commit

Permalink
Fix slider element not getting destroyed when UI is not visible
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoooi0 committed May 22, 2022
1 parent 851381c commit 313602a
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/UI/UIManager.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using UnityEngine;
using System.Collections.Generic;
using UnityEngine;

namespace ToySerialController.UI
{
public class UIManager
{
private static UIManager Instance;
private MVRScript plugin;
private Dictionary<JSONStorableFloat, UIDynamicSlider> jsonStorableFloatToSlider;

public static Transform ConfigurableTextFieldPrefab => Instance.plugin.manager.configurableTextFieldPrefab;
public static Transform ConfigurablePopupPrefab => Instance.plugin.manager.configurablePopupPrefab;
Expand All @@ -16,6 +18,8 @@ public class UIManager
private UIManager(MVRScript plugin)
{
this.plugin = plugin;

jsonStorableFloatToSlider = new Dictionary<JSONStorableFloat, UIDynamicSlider>();
}

public static void Initialize(MVRScript plugin)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 313602a

Please sign in to comment.