Beispiel #1
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        var story = target as Story;

        if (story == null || story.Output == null)
        {
            return;
        }

        EditorGUILayout.Separator();

        EditorGUILayout.LabelField("Story State", story.State.ToString());
        EditorGUILayout.LabelField("Current Passage", story.CurrentPassage == null ? "(none)" : story.CurrentPassage.Name);

        EditorGUILayout.Separator();

        int defaultIndent = EditorGUI.indentLevel;

        for (int i = 0; i < story.Output.Count; i++)
        {
            StoryOutput output = story.Output[i];

            if (output is Embed)
            {
                continue;
            }

            int         groupCount = 0;
            OutputGroup group      = output.Group;
            while (group != null)
            {
                groupCount++;
                group = group.Group;
            }
            EditorGUI.indentLevel = defaultIndent + groupCount;
            EditorGUILayout.LabelField(output.ToString());
        }

        EditorGUI.indentLevel = defaultIndent;
    }
    public virtual void DisplayOutput(StoryOutput output)
    {
        // Deternine where to place this output in the hierarchy - right after the last UI element associated with the previous output, if exists
        TwineTextPlayerElement last = Container.GetComponentsInChildren <TwineTextPlayerElement>()
                                      .Where(elem => elem.SourceOutput.Index < output.Index)
                                      .OrderBy(elem => elem.SourceOutput.Index)
                                      .LastOrDefault();
        int uiInsertIndex = last == null ? -1 : last.transform.GetSiblingIndex() + 1;

        // Temporary hack to allow other scripts to change the templates based on the output's Style property
        SendMessage("Twine_BeforeDisplayOutput", output, SendMessageOptions.DontRequireReceiver);

        if (output is StoryText)
        {
            var text = (StoryText)output;
            if (!string.IsNullOrEmpty(text.Text))
            {
                foreach (Match m in rx_splitText.Matches(text.Text))
                {
                    string word   = m.Value;
                    Text   uiWord = (Text)Instantiate(WordTemplate);
                    uiWord.gameObject.SetActive(true);
                    uiWord.text = word;
                    uiWord.name = word;
                    AddToUI(uiWord.rectTransform, output, uiInsertIndex);
                    if (uiInsertIndex >= 0)
                    {
                        uiInsertIndex++;
                    }
                }
            }
        }
        else if (output is StoryLink)
        {
            var link = (StoryLink)output;
            if (!ShowNamedLinks && link.IsNamed)
            {
                return;
            }

            Button uiLink = (Button)Instantiate(LinkTemplate);
            uiLink.gameObject.SetActive(true);
            uiLink.name = "[[" + link.Text + "]]";

            Text uiLinkText = uiLink.GetComponentInChildren <Text>();
            uiLinkText.text = link.Text;
            uiLink.onClick.AddListener(() =>
            {
                this.Story.DoLink(link);
            });
            AddToUI((RectTransform)uiLink.transform, output, uiInsertIndex);
        }
        else if (output is LineBreak)
        {
            var br = (RectTransform)Instantiate(LineBreakTemplate);
            br.gameObject.SetActive(true);
            br.gameObject.name = "(br)";
            AddToUI(br, output, uiInsertIndex);
        }
        else if (output is OutputGroup)
        {
            // Add an empty indicator to later positioning
            var groupMarker = new GameObject();
            groupMarker.name = output.ToString();
            AddToUI(groupMarker.AddComponent <RectTransform>(), output, uiInsertIndex);
        }
    }