private void OnClickChoiceButton(ChoiceLine sender, Choice choice) { m_ResponseIndex = sender.transform.GetSiblingIndex(); UnityUtils.DestroyObject(sender); m_Story.ChooseChoiceIndex(choice.index); Refresh(); }
private ChoiceLine CreateChoiceView(string text) { ChoiceLine choice = Instantiate(m_PlayerChoicePrefab, m_Canvas.transform, false); Line line = choice.GetComponent <Line>(); line.SetText(text); return(choice); }
private void Next() { if (m_Story.canContinue) { string text = m_Story.Continue().Trim(); Line nextLine = CreateContentView(text, m_ResponseIndex); m_ResponseIndex = -1; string back; string right; string left; // Check possible commands. if (GetTagValue("back", out back) && back != m_LastBack) { m_LastBack = back; m_Backdrop.DestroyAllChildren(); if (m_Assets.Backdrops.ContainsKey(back)) { Instantiate(m_Assets.Backdrops[back], m_Backdrop, false); } } if (GetTagValue("right", out right) && right != m_LastRight) { m_LastRight = right; m_OnStageRight.DestroyAllChildren(); if (m_Assets.Characters.ContainsKey(right)) { GameObject go = Instantiate(m_Assets.Characters[right], m_OnStageRight, false); go.transform.position = m_OffStageRight.position; go.transform.DOLocalMove(Vector3.zero, m_SlideDuration); } } if (GetTagValue("left", out left) && left != m_LastLeft) { m_LastLeft = left; m_OnStageLeft.DestroyAllChildren(); if (m_Assets.Characters.ContainsKey(left)) { GameObject go = Instantiate(m_Assets.Characters[left], m_OnStageLeft, false); go.transform.position = m_OffStageLeft.position; go.transform.DOLocalMove(Vector3.zero, m_SlideDuration); } } if (m_OnFirstLine) { m_OnFirstLine = false; Next(); return; } TextFade tf = nextLine.GetComponentInChildren <TextFade>(); if (tf) { tf.OnComplete.AddListener(Next); } else { DelayTracker.DelayAction(m_NextDelay, Next); } return; } if (m_Story.currentChoices.Count > 0) { // Fade old choices. GetComponentsInChildren <Line>().Where(l => l.LineType == Line.Type.Player).ForEach(l => l.FadeOut()); for (int i = 0; i < m_Story.currentChoices.Count; i++) { Choice choice = m_Story.currentChoices[i]; ChoiceLine button = CreateChoiceView(choice.text.Trim()); button.OnClick.AddListener(() => OnClickChoiceButton(button, choice)); } } else { ChoiceLine choice = CreateChoiceView("End of story.\nRestart?"); choice.OnClick.AddListener(StartStory); } }