コード例 #1
0
 void SendOutput(TwineOutput output)
 {
     if (OnOutput != null)
     {
         OnOutput(output);
     }
 }
コード例 #2
0
        /// <summary>
        /// Resumes a story that was paused.
        /// </summary>
        void Execute()
        {
            while (_passageExecutor.MoveNext())
            {
                TwineOutput output = _passageExecutor.Current;
                this.Output.Add(output);

                if (output is TwineLink)
                {
                    // Add links to dedicated list
                    var link = (TwineLink)output;
                    this.Links.Add(link);
                }
                else if (output is TwineText)
                {
                    // Add all text to the Text property for easy access
                    var text = (TwineText)output;
                    this.Text.Add(text);
                }

                // Let the handlers and hooks kick in
                if (output is TwinePassage)
                {
                    HooksInvoke(HooksFind("Enter", reverse: true, maxLevels: 1));

                    // Refresh the update hooks
                    _passageUpdateHooks = HooksFind("Update", reverse: false, allowCoroutines: false).ToArray();
                }
                else
                {
                    SendOutput(output);
                    HooksInvoke(HooksFind("Output"), output);
                }

                // Story was paused, wait for it to resume
                if (this.State == TwineStoryState.Paused)
                {
                    return;
                }
            }

            _passageExecutor.Dispose();
            _passageExecutor = null;

            this.State = this.Links.Count > 0 ?
                         TwineStoryState.Idle :
                         TwineStoryState.Complete;

            HooksInvoke(HooksFind("Done"));
        }
コード例 #3
0
    public void DisplayOutput(TwineOutput output)
    {
        const int maxNameLength = 30;
        RectTransform child = null;
        if (output is TwineText)
        {
            var text = (TwineText)output;
            if (!ShowEmptyLines && text.Text.Trim().Length < 1)
                return;

            Text uiText = (Text)Instantiate(TextTemplate);
            uiText.gameObject.SetActive(true);
            uiText.text = text.Text;
            uiText.name =
                text.Text.Length > maxNameLength-3 ? text.Text.Substring(0,27) + "..." :
                text.Text.Trim().Length == 0 ? "(empty line)" :
                text.Text;
            child = uiText.rectTransform;
        }
        else if (output is TwineLink)
        {
            var link = (TwineLink)output;
            if (!ShowNamedLinks && link.Name != link.Text)
                return;

            Button uiLink = (Button)Instantiate(LinkTemplate);
            uiLink.gameObject.SetActive(true);
            uiLink.name = "[[" + (link.Name.Length > maxNameLength - 3 ? link.Name.Substring(0, 27) + "..." : link.Name) + "]]";

            Text uiLinkText = uiLink.GetComponentInChildren<Text>();
            uiLinkText.text = link.Text;
            uiLink.onClick.AddListener(() => this.Story.Advance(link));
            child = (RectTransform)uiLink.transform;
        }
        else
            return;

        if (child != null)
            child.SetParent(Container);
    }
コード例 #4
0
ファイル: TwineStory.cs プロジェクト: hybrid1969/UnityTwine
 void SendOutput(TwineOutput output)
 {
     if (OnOutput != null)
         OnOutput(output);
 }
コード例 #5
0
    IEnumerator Wait(float wait, bool click, TwineOutput output)
    {
        if (wait > 0f)
        yield return new WaitForSeconds(wait);

        if (click)
        {
            while (!this.WasClicked())
                yield return null;
        }

        DisplayOutput(output);

        yield return null;
        Story["wait"] = 0.0;
        Story.Resume();
    }
コード例 #6
0
    void Story_OnOutput(TwineOutput output)
    {
        if (!this.AutoDisplay)
            return;

        // Check if a wait is needed
        float wait = 0f;
        try { wait = (float) Story["wait"].ToDouble(); }
        catch (KeyNotFoundException) { }

        // Check if a click in needed (only for links and non-empty text lines)
        bool click = false;
        if ((output is TwineLink || output is TwineText) && output.Text.Length > 0)
        {
            try { click = Story["click"].ToBool(); }
            catch (KeyNotFoundException) { }
        }

        if (click || wait > 0f)
        {
            Story.Pause();
            StartCoroutine(Wait(wait, click, output));
        }
        else
            DisplayOutput(output);
    }
コード例 #7
0
ファイル: SnoozingHooks.cs プロジェクト: Wuzseen/DIGM530-AWT
	IEnumerator relationship_Output(TwineOutput output)
	{
		if (output is TwineText && Random.Range(0,2) == 0)
		{
			if (!relationship_sfxCough.isPlaying)
			{
				relationship_sfxCough.clip = relationship_sfxCoughSounds[Random.Range(0, relationship_sfxCoughSounds.Length)];
				relationship_sfxCough.time = 0f;
				relationship_sfxCough.Play();
			}
		}
		else if (output is TwineLink && output.Name == "continue")
		{
			yield return StartCoroutine(ClickForAlarm(output as TwineLink));
		}
	}
コード例 #8
0
ファイル: SnoozingHooks.cs プロジェクト: Wuzseen/DIGM530-AWT
	IEnumerator sea_Output(TwineOutput output)
	{
		if (output is TwineLink && output.Name == "continue")
		{
			yield return StartCoroutine(ClickForAlarm(output as TwineLink));
		}
	}