/// <summary> /// Here we have a superclass intercept for catching global GameObject mouse up events. /// If object not draggable and tinker text is not null , call stanza manager onMouseUp(tinkertext). /// If tinkergraphic , call tinkrgraphic.MyOnMouseUp. /// This function can be overriden by specific scene manager. /// </summary> /// <param name="go">Game Object selected.</param> public virtual void OnMouseUp(GameObject go) { // Got a TinkerText object? (Also, make sure dragActive is false) if (!dragActive && go.GetComponent <GTinkerText>() != null) { GTinkerText tinkerText = go.GetComponent <GTinkerText>(); if (tinkerText != null) { if (stanzaManager != null) { stanzaManager.OnMouseUp(tinkerText); } } } // TinkerGraphic object else if (go.GetComponent <GTinkerGraphic>() != null) { GTinkerGraphic tinkerGraphic = go.GetComponent <GTinkerGraphic>(); if (tinkerGraphic != null) { tinkerGraphic.MyOnMouseUp(); } } }
/// <summary> /// Here we have a superclass intercept for catching global GameObject mouse currently down events. /// If input is allowed(during stanza play / after stanza play) check if Tinkertext or Tinkergraphic /// If tinkertext , call stanzamanager onmousecurrentlydown(tinkrtext). /// If tinkergraphic , call tinkrgraphic onmousecurrentlydown. /// This function can be overriden by specific scene manager. /// </summary> /// <param name="go">Game object clicked.</param> public virtual void OnMouseCurrentlyDown(GameObject go) { // Lock out other input during auto play? if (IsInputAllowed()) { // TinkerGraphic object if (go.GetComponent <GTinkerGraphic>() != null) { GTinkerGraphic tinkerGraphic = go.GetComponent <GTinkerGraphic>(); if (tinkerGraphic != null) { tinkerGraphic.OnMouseCurrentlyDown(); } } // TinkerText object else if (!dragActive && go.GetComponent <GTinkerText>() != null) { GTinkerText tinkerText = go.GetComponent <GTinkerText>(); if (tinkerText != null) { if (stanzaManager != null) { // Only allow further drag events if we aren't autoplaying if (!stanzaManager.IsAutoPlaying()) { stanzaManager.OnMouseCurrentlyDown(tinkerText); } } } } } }
public void OnPairedMouseCurrentlyDown(GTinkerText tinkerText) { if (tinkerText.stanza != null && stanzas.Contains(tinkerText.stanza)) { tinkerText.stanza.OnPairedMouseCurrentlyDown(tinkerText); } }
public void OnMouseUp(GTinkerText tinkerText) { if (tinkerText.stanza != null && stanzas.Contains(tinkerText.stanza)) { tinkerText.stanza.OnMouseUp(tinkerText); } }
// 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; }
/// <summary> /// this function handles the on mouse up events of text /// </summary> /// <param name="tinkerText"></param> public void OnMouseUp(GTinkerText tinkerText) { // Assign this new one mouseDownTinkerText = tinkerText; // And signal the tinkerText tinkerText.MyOnMouseUp(); }
/// <summary> /// If input is allowed(during stanza play / after stanza play) check if Tinkertext or Tinkergraphic /// If tinkertext , call stanzamanager onmousedown(tinkrtext). /// If tinkergraphic , call tinkrgraphic.mymousedown. /// This function can be overriden by specific scene manager. /// </summary> public virtual void OnMouseDown(GameObject go) { stanzaManager.RequestCancelAutoPlay(); // to stop auto narration when anything is clicked // Lock out other input during auto play? if (IsInputAllowed()) { // TinkerText object if (go.GetComponent <GTinkerText>() != null) { GTinkerText tinkerText = go.GetComponent <GTinkerText>(); if (tinkerText != null) { if (stanzaManager != null) { // Is an autoplay in progress? If so, see if we should interrupt if (stanzaManager.IsAutoPlaying() && inputInterruptsAutoplay) { stanzaManager.RequestCancelAutoPlay(); } stanzaManager.OnMouseDown(tinkerText); } } } // TinkerGraphic object else if (go.GetComponent <GTinkerGraphic>() != null) { GTinkerGraphic tinkerGraphic = go.GetComponent <GTinkerGraphic>(); if (tinkerGraphic != null) { tinkerGraphic.MyOnMouseDown(); } } } }
/// <summary> /// this function is called when the tinkergraphic is paired to some tinkertext /// and we want have some paired graphical animation for that text /// </summary> /// <param name="tinkerText"></param> // Paired TinkerText Mouse Down Event public void OnPairedMouseDown(GTinkerText tinkerText) { sceneManager.OnPairedMouseDown(tinkerText); isanimplaying = true; checkandStoproutines(); LoadAndPlayAnimation(tinkerText.pairedAnim); }
public void OnMouseDown(GTinkerText tinkerText, bool suppressAnim = false) { Debug.Log("mousedown2"); if (tinkerText.stanza != null && stanzas.Contains(tinkerText.stanza)) { tinkerText.stanza.OnMouseDown(tinkerText, suppressAnim); } }
private void ResetMouseCurrentlyDownStates() { if (mouseCurrentlyDownTinkerText != null) { mouseCurrentlyDownTinkerText.Reset(); } mouseCurrentlyDownTinkerText = null; }
/// <summary> /// Here we have a superclass intercept for catching global TinkerText paired mouse up events. /// </summary> /// <param name="tinkerText">Tinker text.</param> public virtual void OnPairedMouseUp(GTinkerText tinkerText) { // Renderer[] list; // list = tinkerText.pairedGraphic.gameObject.GetComponentsInChildren<Renderer>(); // foreach(Renderer item in list){ //color all the components // item.material.color = tinkerText.pairedGraphic.resetColor; // } }
// 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)); } }
/// <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>()); }
/// <summary> /// this function handles the mousedown evens on the tinkertexts of the stanza /// </summary> /// <param name="tinkerText">tinkertext that is pressed</param> /// <param name="suppressAnim">bool to check whether animation is to be suppressed</param> public void OnMouseDown(GTinkerText tinkerText, bool suppressAnim = false) { // if we aren't already mouse down on this text if (mouseDownTinkerText != null && mouseDownTinkerText != tinkerText) { // Then reset the old one mouseDownTinkerText.Reset(); } // Assign this new one mouseDownTinkerText = tinkerText; // And signal the tinkerText tinkerText.MyMouseDown(suppressAnim); }
/// <summary> /// this function handles the on paired mouse events /// </summary> /// <param name="tinkerText"></param> public void OnPairedMouseDown(GTinkerText tinkerText) { // if we aren't already mouse down on this text if (mouseDownTinkerText != null && mouseDownTinkerText != tinkerText) { // Then reset the old one mouseDownTinkerText.Reset(); } // Assign this new one mouseDownTinkerText = tinkerText; // And trigger the tinkerText only if stanza narrate is false //if(stanzaNarrate==false) tinkerText.OnPairedMouseDown(); }
/// <summary> /// this function handles the onPairedMouseCurrenltyDown event on tinkertext /// </summary> /// <param name="tinkerText"></param> public void OnPairedMouseCurrentlyDown(GTinkerText tinkerText) { // If this text is already marked as mouse down, clear that if (mouseDownTinkerText != null && mouseDownTinkerText == tinkerText) { mouseDownTinkerText = null; // and reassign it to currently down mouseCurrentlyDownTinkerText = tinkerText; //DetectStanzaAutoPlay(tinkerText); } else if (mouseCurrentlyDownTinkerText != null) { // If this text isn't already marked as currently down if (mouseCurrentlyDownTinkerText != tinkerText) { // Then reset the old one mouseCurrentlyDownTinkerText.Reset(); // Assign this new one mouseCurrentlyDownTinkerText = tinkerText; // Signal tinkerText tinkerText.OnPairedMouseCurrentlyDown(); //DetectStanzaAutoPlay(tinkerText); } } else { // Assign this new one mouseCurrentlyDownTinkerText = tinkerText; // Signal tinkerText tinkerText.OnPairedMouseCurrentlyDown(); //DetectStanzaAutoPlay(tinkerText); } }
/// <summary> /// Here we have a superclass intercept for catching global TinkerText paired mouse down events. /// </summary> /// <param name="tinkerText">Tinker text.</param> public virtual void OnPairedMouseDown(GTinkerText tinkerText) { }
// Paired TinkerText Mouse Up Event public void OnPairedMouseUp(GTinkerText tinkerText) { sceneManager.OnPairedMouseUp(tinkerText); }
/// <summary> /// Auto stanza play of. /// calls on mouse down of each text to play its respective animation if present /// zoomin and zoomout of texts with delays acoordinf to the start and end time of texts /// </summary> /// <param name="startingTinkerText">Starting tinker text.</param> public IEnumerator AutoPlay(GTinkerText startingTinkerText = null) { //{ stanzaNarrate = true; Debug.Log("auto play"); int startingTinkerTextIndex = 0; if (startingTinkerText != null) { startingTinkerTextIndex = tinkerTexts.IndexOf(startingTinkerText); } for (int i = startingTinkerTextIndex; i < tinkerTexts.Count; i++) { //link the corresponding paried animation during auto play GTinkerText t = null; if (tinkerTexts[i] != null) { t = tinkerTexts[i]; } if (t.star) { for (int j = 0; j < t.pairedGraphics.Count; j++) { t.pairedGraphics [j].PlayCompleteAnim(); } } //GTinkerGraphic link = t.GetComponent<GTinkerText> ().pairedGraphic; //if paired graphic is present //if (link != null) { //GSManager scenescript = stanzaManager.sceneManager; //call its respective scene onmousedown //scenescript.OnMouseDown(t.gameObject); //scenescript.OnMouseUp (t.gameObject); //} Animator anim = t.GetComponent <Animator>(); if (anim != null) { anim.speed = 1 / t.playTime; } // If we aren't on last word, delay before playing next word if (i < tinkerTexts.Count - 1) { // delay according to timing data float pauseDelay = tinkerTexts[i + 1].GetStartTime() - tinkerTexts[i].GetEndTime(); if (anim != null) { anim.Play("textzoomout"); } yield return(new WaitForSeconds(t.playTime / 2)); if (anim != null) { anim.Play("textzoomin"); } yield return(new WaitForSeconds(t.playTime / 2)); if (pauseDelay != 0) { if (anim != null) { anim.speed = 1 / pauseDelay; } if (anim != null && anim.GetCurrentAnimatorStateInfo(0).IsName("idle")) { anim.Play("pausedelay"); } yield return(new WaitForSeconds(pauseDelay)); } } else // Delay before next stanza { if (anim != null) { anim.Play("textzoomout"); } yield return(new WaitForSeconds(t.playTime / 2)); if (anim != null) { anim.Play("textzoomin"); } yield return(new WaitForSeconds(t.playTime / 2)); if (anim != null && endDelay != 0) { anim.speed = 1 / endDelay; anim.Play("enddelay"); } yield return(new WaitForSeconds(endDelay)); } // Abort early? if (stanzaManager.CancelAutoPlay()) { yield break; } } //stanzaNarrate=false; // Stop the coroutine yield break; }
/// <summary> /// Here we have a superclass intercept for catching global TinkerText paired mouse currently down events. /// </summary> /// <param name="tinkerText">Tinker text.</param> public virtual void OnPairedMouseCurrentlyDown(GTinkerText tinkerText) { // override me }
// Paired TinkerText Mouse Down Event public void OnPairedMouseCurrentlyDown(GTinkerText tinkerText) { sceneManager.OnPairedMouseCurrentlyDown(tinkerText); }