Kaynağa Gözat

Added Encyclopedia auto refresh articles on enable

James Peret 2 yıl önce
ebeveyn
işleme
5dd01fc68e

+ 8 - 0
Runtime/Encyclopedia/EncyclopediaController.cs

@@ -10,6 +10,8 @@ namespace KairoEngine.UI.Encyclopedia
     [HideMonoScript]
     public class EncyclopediaController : MonoBehaviour, IClickHandler
     {
+        public static EncyclopediaController instance;
+
         [ShowInInspector, HorizontalGroup("IndexLine", 0.7f), LabelText("Index")] public int menuIndex;
         [ShowInInspector, HorizontalGroup("IndexLine", 0.3f), HideLabel] public int subMenuIndex;
 
@@ -17,6 +19,12 @@ namespace KairoEngine.UI.Encyclopedia
         public GameObject categoryButtomPrefab;
         public List<EncyclopediaCategory> categories = new List<EncyclopediaCategory>();
 
+        private void Awake()
+        {
+            if(instance == null) instance = this;
+            else Destroy(this);
+        }
+
         [Button("Build Menu"), ButtonGroup("Buttons")]
         public void BuildMenu()
         {

+ 4 - 3
Runtime/Encyclopedia/EncyclopediaUi.cs

@@ -17,6 +17,7 @@ namespace KairoEngine.UI.Encyclopedia
         public Transform menuContainer;
         public Transform subMenuContainer;
         public bool createOnStart = true;
+        public bool repopulateOnEnable = false;
         public bool showDebug = false;
         public List<EncyclopediaUiView> views;
         private List<SelectedButton> menuButtonSelection;
@@ -34,10 +35,10 @@ namespace KairoEngine.UI.Encyclopedia
             if(createOnStart) Populate();
         }
 
-        private void Update()
+        private void OnEnable()
         {
-            
-        }
+            if(repopulateOnEnable) Populate();
+        } 
 
         [Button("Show Submenu"), ButtonGroup("EditorActions")]
         public void ShowSubmenu() => subMenuGameObject.SetActive(true);