|
@@ -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);
|