Пример #1
0
 // StoryManager will call this to give TinkerText a chance to readjust the
 // width of all the text and the textButton and the overall TinkerText.
 // Also need to set the component to active.
 // Don't need to know anything about its position, the layout groups
 // should automatically handle that.
 public void Init(int id, string word, AudioTimestamp timestamp, bool isLastWord)
 {
     this.id   = id;
     this.word = word;
     this.text.GetComponent <Text>().text     = word;
     this.text.GetComponent <Text>().fontSize = TINKER_TEXT_FONT_SIZE;
     this.audioStartTime      = timestamp.start;
     this.audioEndTime        = timestamp.end;
     this.triggerAudioEndTime = timestamp.end;
     // TODO: think of a better way to handle this.
     // Kind of hacky, but this stops the audio clipping.
     // And prevents words from getting stuck on the pink highlight at the end.
     if (isLastWord)
     {
         this.audioEndTime = float.MaxValue;
         // Take diff into account so the subtraction doesn't make "end" occur before "start".
         float diff = timestamp.end - timestamp.start;
         this.triggerAudioEndTime -= Math.Min(.15f, diff * .25f);
         Logger.Log("triggerAudioEndTime " + triggerAudioEndTime);
     }
     this.gameObject.SetActive(true);
     // When a TinkerText is clicked, it should highlight.
     // TODO: consider somehow making all other tinkertexts with the same text highlight?
     this.AddClickHandler(Highlight());
 }
 // StoryManager will call this to give TinkerText a chance to readjust the
 // width of all the text and the textButton and the overall TinkerText.
 // Also need to set the component to active.
 // Don't need to know anything about its position, the layout groups
 // should automatically handle that.
 public void Init(int id, string word, AudioTimestamp timestamp)
 {
     this.id = id;
     this.text.GetComponent <Text>().text = word;
     this.audioStartTime = timestamp.start;
     this.audioEndTime   = timestamp.end;
     gameObject.SetActive(true);
 }
    // Add a new TinkerText for the given word.
    private void loadTinkerText(string word, AudioTimestamp timestamp)
    {
        if (word.Length == 0)
        {
            return;
        }
        GameObject newTinkerText =
            Instantiate((GameObject)Resources.Load("Prefabs/TinkerText"));

        newTinkerText.GetComponent <TinkerText>()
        .Init(this.tinkerTexts.Count, word, timestamp);
        // Figure out how wide the TinkerText wants to be, then decide if
        // we need to make a new stanza.
        GameObject newText        = newTinkerText.GetComponent <TinkerText>().text;
        float      preferredWidth =
            LayoutUtility.GetPreferredWidth(
                newText.GetComponent <RectTransform>()
                );

        preferredWidth = Math.Max(preferredWidth, this.MIN_TINKER_TEXT_WIDTH);
        // Add new stanza if no more room, or if previous word was terminating
        // punctuation.
        if (preferredWidth > this.remainingStanzaWidth ||
            this.prevWordEndsStanza)
        {
            // Tell this tinkerText it's first in the stanza.
            newTinkerText.GetComponent <TinkerText>().SetFirstInStanza();
            GameObject newStanza =
                Instantiate((GameObject)Resources.Load("Prefabs/StanzaPanel"));
            newStanza.transform.SetParent(this.textPanel.transform, false);
            newStanza.GetComponent <Stanza>().Init(
                this.audioManager,
                this.textPanel.GetComponent <RectTransform>().position
                );
            // Set the end time of previous stanza and start time of the new
            // stanza we're adding.
            if (this.currentStanza != null)
            {
                this.currentStanza.GetComponent <Stanza>().SetEndTimestamp(
                    timestamp.start);
            }
            this.stanzas.Add(newStanza);
            this.currentStanza = newStanza;
            this.currentStanza.GetComponent <Stanza>().SetStartTimestamp(
                timestamp.start);
            // Reset the remaining stanza width.
            this.remainingStanzaWidth =
                this.textPanel.GetComponent <RectTransform>().sizeDelta.x;
        }
        // Initialize the TinkerText width correctly.
        // Set new TinkerText parent to be the stanza.
        newTinkerText.GetComponent <TinkerText>().SetWidth(preferredWidth);
        newTinkerText.transform.SetParent(this.currentStanza.transform, false);
        this.remainingStanzaWidth -= preferredWidth;
        this.remainingStanzaWidth -= STANZA_SPACING;
        this.tinkerTexts.Add(newTinkerText);
        this.prevWordEndsStanza = Util.WordShouldEndStanza(word);
    }
 // StoryManager will call this to give TinkerText a chance to readjust the
 // width of all the text and the textButton and the overall TinkerText.
 // Also need to set the component to active.
 // Don't need to know anything about its position, the layout groups
 // should automatically handle that.
 public void Init(int id, string word, AudioTimestamp timestamp, bool isLastWord)
 {
     this.id   = id;
     this.word = word;
     this.text.GetComponent <Text>().text = word;
     this.audioStartTime = timestamp.start;
     this.audioEndTime   = timestamp.end;
     // Kind of hacky, but this stops the audio clipping.
     if (isLastWord)
     {
         this.audioEndTime = float.MaxValue;
     }
     gameObject.SetActive(true);
 }
Пример #5
0
    // Add a new TinkerText for the given word.
    private void loadTinkerText(string word, AudioTimestamp timestamp, bool isLastWord)
    {
        if (word.Length == 0)
        {
            return;
        }
        GameObject newTinkerText =
            Instantiate((GameObject)Resources.Load("Prefabs/TinkerText"));

        newTinkerText.GetComponent <TinkerText>()
        .Init(this.tinkerTexts.Count, word, timestamp, isLastWord);
        this.tinkerTexts.Add(newTinkerText);
        // Place it correctly within the stanzas.
        this.stanzaManager.AddTinkerText(newTinkerText);
    }
Пример #6
0
 // StoryManager will call this to give TinkerText a chance to readjust the
 // width of all the text and the textButton and the overall TinkerText.
 // Also need to set the component to active.
 // Don't need to know anything about its position, the layout groups
 // should automatically handle that.
 public void Init(int id, string word, AudioTimestamp timestamp, bool isLastWord)
 {
     this.id   = id;
     this.word = word;
     this.text.GetComponent <Text>().text = word;
     this.audioStartTime = timestamp.start;
     this.audioEndTime   = timestamp.end;
     // Kind of hacky, but this stops the audio clipping.
     if (isLastWord)
     {
         this.audioEndTime = float.MaxValue;
     }
     this.gameObject.SetActive(true);
     // When a TinkerText is clicked, it should highlight.
     // TODO: consider somehow making all other tinkertexts with the same text highlight?
     this.AddClickHandler(Highlight());
 }
Пример #7
0
    // Add a new TinkerText for the given word.
    private void loadTinkerText(int index, string word, AudioTimestamp timestamp, bool isLastWord)
    {
        if (word.Length == 0)
        {
            return;
        }
        GameObject newTinkerText =
            Instantiate((GameObject)Resources.Load("Prefabs/TinkerText"));

        newTinkerText.GetComponent <TinkerText>()
        .Init(this.tinkerTexts.Count, word, timestamp, isLastWord);
        // If we're using ROS, attach a click handler to the tinkertext so that there's a message
        // sent over ROS whenever the user taps on a word.
        if (Constants.USE_ROS)
        {
            newTinkerText.GetComponent <TinkerText>().AddClickHandler(this.rosManager.SendTinkerTextTappedAction(index, word));
        }
        this.tinkerTexts.Add(newTinkerText);
        // Place it correctly within the stanzas.
        this.stanzaManager.AddTinkerText(newTinkerText);
    }