Пример #1
0
    // Begins an auto play starting w/ a stanza
    private IEnumerator StartAutoPlay(StanzaObject startingStanza, GTinkerText startingTinkerText)
    {
        Debug.Log("autoplay started");

        // If we aren't starting from the beginning, read the audio progress from the startingTinkerText
        GetComponent <AudioSource>().time = startingTinkerText.GetStartTime();
        // Start playing the full stanza audio
        GetComponent <AudioSource>().Play();

        int startingStanzaIndex = stanzas.IndexOf(startingStanza);

        for (int i = startingStanzaIndex; i < stanzas.Count; i++)
        {
            if (i == startingStanzaIndex)
            {
                yield return(StartCoroutine(stanzas[i].AutoPlay(startingTinkerText)));
            }
            else
            {
                yield return(StartCoroutine(stanzas[i].AutoPlay()));
            }

            // Abort early?
            if (CancelAutoPlay())
            {
                autoPlaying = false;
                GetComponent <AudioSource>().Stop();
                yield break;
            }
        }

        autoPlaying = false;
        yield break;
    }
Пример #2
0
 // Method to request an auto play starting w/ a stanza
 public void RequestAutoPlay(StanzaObject startingStanza, GTinkerText startingTinkerText = null)
 {
     Debug.Log("request auto play");
     if (!autoPlaying)          // && !sceneManager.disableAutoplay)
     {
         Debug.Log("not auto playing");
         autoPlaying    = true;
         cancelAutoPlay = false;             // reset our cancel flag
         StartCoroutine(StartAutoPlay(startingStanza, startingTinkerText));
     }
 }
Пример #3
0
    /// <summary>
    /// Creates TinkerText for a word at a position.
    /// </summary>
    /// <returns>The text.</returns>
    /// <param name="parent">Parent stanza of the TinkerText.</param>
    /// <param name="x">The x coordinate.</param>
    /// <param name="y">The y coordinate.</param>
    /// <param name="textToPrint">Text to print (word).</param>
    /// <param name="fontSize">Font size.</param>
    /// <param name="textColor">Text color.</param>
    GTinkerText CreateText(StanzaObject parent, float x, float y, string textToPrint, int fontSize, Color textColor)
    {
        GameObject UItextGO = new GameObject("Text_" + textToPrint);

        UItextGO.transform.SetParent(parent.transform);
        // Debug.Log(anim.runtimeAnimatorController);
        Text text = UItextGO.AddComponent <Text>();

        text.text                 = textToPrint;
        text.fontSize             = storyBookJson.textFontSize;
        text.color                = textColor;
        text.font                 = font;
        text.transform.localScale = new Vector3(1, 1, 1);

        //used for fitting the text box to the size of text.
        ContentSizeFitter csf = UItextGO.AddComponent <ContentSizeFitter> ();

        csf.verticalFit   = ContentSizeFitter.FitMode.PreferredSize;
        csf.horizontalFit = ContentSizeFitter.FitMode.PreferredSize;

        VerticalLayoutGroup vlg = UItextGO.AddComponent <VerticalLayoutGroup> ();

        vlg.childControlHeight = true;
        vlg.childControlWidth  = true;


        RectTransform trans = UItextGO.GetComponent <RectTransform>();

        text.alignment         = TextAnchor.UpperLeft;
        trans.anchoredPosition = new Vector3(x, y, 0);
        UItextGO.GetComponent <RectTransform> ().pivot = new Vector2(0.5f, 0.5f);
        UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(trans);

        trans.anchoredPosition = new Vector3(x + trans.rect.width / 2, y, 0);
        UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(trans);

        width        = width + trans.rect.width + minWordSpace;
        stanzaLength = width;

        //audio to each word
        //		TimeStampClass[] timeStamps = storyBookJson.pages[pageNumber].timestamps;
        //		UItextGO.AddComponent<AudioSource> ().clip = LoadAudioAsset (timeStamps [wordCount].audio);
        //		wordCount++;

        //add the animator and script to the word.
        UItextGO.AddComponent <Animator>().runtimeAnimatorController = Resources.Load("TextAnimations/textzoomcontroller") as RuntimeAnimatorController;
        GTinkerText tinkerText = UItextGO.AddComponent <GTinkerText>();

        tinkerText.stanza = UItextGO.GetComponentInParent <StanzaObject>();
        tinkerTextObjects.Add(UItextGO);
        return(UItextGO.GetComponent <GTinkerText>());
    }
Пример #4
0
    public void alignText(float length, StanzaObject parent)
    {
        startingX = -(length / 2);
        //GameObject [] go=GameObject.FindGameObjectsWithTag("stanzaobject");
        //Debug.Log (go);
        parent.transform.localPosition = new Vector3(startingX, startingY, 0);

        //foreach (GameObject stanza in go)
        //if (storyBookJson.id != 1)
        //stanza.GetComponent<RectTransform> ().localPosition = new Vector3 (startingX, startingY, 0);
        //else
        //{ stanza.GetComponent<RectTransform> ().localPosition = new Vector3 (startingX, startingY, 0);

        //}
    }