Browse Source

Fixed UI story panel flickering

jamesperet 2 years ago
parent
commit
55ad960194
3 changed files with 31 additions and 5 deletions
  1. 1 1
      Readme.md
  2. 29 3
      Runtime/UI/StoryViewUI.cs
  3. 1 1
      package.json

+ 1 - 1
Readme.md

@@ -1,4 +1,4 @@
-# 📦 KairoEngine.StorySystem v0.1.2
+# 📦 KairoEngine.StorySystem v0.1.4
 
 The Story System uses the Ink Language and runtime to navigate through a story written in a plain text file. This package contains the Story Module that receives an ink story and runs it. The story can show lines and branches, execute functions in unity and wait for events. Unity also has an API for navigating, getting and setting variables in the story.
 

+ 29 - 3
Runtime/UI/StoryViewUI.cs

@@ -9,6 +9,7 @@ using KairoEngine.StorySystem;
 
 namespace KairoEngine.StorySystem.UI
 {
+    [HideMonoScript]
     public class StoryViewUI : SerializedMonoBehaviour, IUiSystemElement
     {
         public string storyName = "Storyline";
@@ -27,6 +28,7 @@ namespace KairoEngine.StorySystem.UI
         [BoxGroup("Story Branches"), ShowIf("@showBranches")] public bool hidePanelAfterChoice = true;
         [BoxGroup("Story Branches"), ShowIf("@showBranches")] public GameObject storyBranchPrefab;
         [BoxGroup("Story Branches"), ShowIf("@showBranches")] public Transform branchContainer;
+        [BoxGroup("Story Branches"), ShowIf("@showBranches")] public int prePopulateButtons = 0;
 
         [BoxGroup("Portraits")] public bool usePortraits = false;
         [BoxGroup("Portraits"), ShowIf("@usePortraits")] public Image portraitImage;
@@ -52,6 +54,17 @@ namespace KairoEngine.StorySystem.UI
             if(showBranches && branchContainer == null) Debug.LogError("StoryViewUI is missing a Story Branch Container", this.gameObject);
         }
 
+        void Start()
+        {
+            for (int i = 0; i < prePopulateButtons; i++)
+            {
+                GameObject obj = Instantiate(storyBranchPrefab, branchContainer);
+                obj.name = obj.name.Replace("(Clone)", "");
+                obj.SetActive(false);
+                buttons.Add(obj);
+            }
+        }
+
         void OnEnable()
         {
             EventManager.broadcast.StartListening(storyName, OnStoryStep);
@@ -102,14 +115,27 @@ namespace KairoEngine.StorySystem.UI
         {
             if(buttons != null)
             {
-                for (int i = 0; i < buttons.Count; i++) Destroy(buttons[i]);
+                for (int i = storyStep.branches.Count; i < buttons.Count; i++) 
+                {
+                    //Destroy(buttons[i]);
+                    buttons[i].SetActive(false);
+                }
             }
             buttons = new List<GameObject>();
             ShowPanel();
             for (int i = 0; i < storyStep.branches.Count; i++)
             {
-                GameObject obj = Instantiate(storyBranchPrefab, branchContainer);
-                obj.name = obj.name.Replace("(Clone)", "");
+                GameObject obj;
+                if(buttons.Count > i) 
+                {
+                    obj = buttons[i];
+                    obj.SetActive(true);
+                }
+                else 
+                {
+                    obj = Instantiate(storyBranchPrefab, branchContainer);
+                    obj.name = obj.name.Replace("(Clone)", "");
+                }
                 StoryViewButton btn = obj.GetComponent<StoryViewButton>();
                 btn.Init(storyName, storyStep, i, this);
                 buttons.Add(obj);

+ 1 - 1
package.json

@@ -1,7 +1,7 @@
 {
     "name": "at.kairoscope.kairoengine.story-system",
     "displayName": "KairoEngine Story System",
-    "version": "0.1.3",
+    "version": "0.1.4",
     "unity": "2020.3",
     "description": "Kairoengine story system based on the Ink language.",
     "dependencies": {