Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Dauntless on February 24, 2013, 11:34:02 AM

Title: Typewriter Effect, how to reset it?
Post by: Dauntless on February 24, 2013, 11:34:02 AM
Hi,  I have a function that calls a UILabel with a Typewriter Effect on it.  It works the first time but how can I tell it to reset so it does it every time it's called?  I tried to access the script but .GetComponent(TypewriterEffect) does not seem to work?
Title: Re: Typewriter Effect, how to reset it?
Post by: ArenMook on February 24, 2013, 11:57:04 AM
It's an example script that comes with NGUI -- it's not technically a part of NGUI itself. It's meant to be an example that shows how it's done. :)

You can always AddComponent<TypewriterEffect>() to reset it after it finishes.
Title: Re: Typewriter Effect, how to reset it?
Post by: Dauntless on February 24, 2013, 12:47:46 PM
Thanks ArenMook but I'm a newbie so forgive me.  This is what I have and it gives me an error : The name 'TypewriterEffect' does not denote a valid type ('not found').  ...thanks in advance.

var informationScrollGO : GameObject;


function InformationScrollBar()
{
var informationScrollEffect : TypewriterEffect  = informationScrollGO.AddComponent(TypewriterEffect);
}
Title: Re: Typewriter Effect, how to reset it?
Post by: ArenMook on February 24, 2013, 01:14:21 PM
Did you follow the instructions on getting NGUI to work with javascript described in the readme and in the FAQ sticky? http://www.tasharen.com/forum/index.php?topic=6.0
Title: Re: Typewriter Effect, how to reset it?
Post by: Dauntless on February 24, 2013, 04:57:27 PM
Yes, I set it up originally that way.  ScreenShot below.
Title: Re: Typewriter Effect, how to reset it?
Post by: ArenMook on February 24, 2013, 05:01:26 PM
Your "Examples" folder is outside the "Plugins" folder. Typewriter script is inside the Examples folder.
Title: Re: Typewriter Effect, how to reset it?
Post by: Dauntless on February 24, 2013, 05:11:52 PM
Thank you Sir! ... it works great now.  I wasn't able to drag and drop the entire folder because some other files must be using things in there.  I just created another folder Examples/Scripts/Other then dragged and dropped the TypewriterEffect into it.  Thanks again ArenMook.
Title: Re: Typewriter Effect, how to reset it?
Post by: skatola on April 26, 2017, 04:41:42 PM
excuse me ArenMook, i'm trying to solve the same problem and Addcomponent works great but if i use something like that:

      main_label.text = "";
      main_label_obj.AddComponent<TypewriterEffect> ();
      main_label.text = test_array [counter_dialogue];
      counter_dialogue++;

the new string become entirely visible for a fraction of second before the typewriting effect start to write it correctly.
How can i avoid to see on the screen the entire string before the typewriting effect starts?
Title: Re: Typewriter Effect, how to reset it?
Post by: skatola on April 26, 2017, 05:50:08 PM
sorry another thing...
after i added a new typewritereffect i have to set again the <TypewriterEffect>().onFinished behaviour, usually i add the function in the inspector, i tried to do something like this:

      main_label_obj.AddComponent<TypewriterEffect> ();
      main_label_obj.GetComponent<TypewriterEffect> ().onFinished += my_function_in_the_same_script;

but i receive error "Operator `+=' cannot be applied to operands of type `System.Collections.Generic.List<EventDelegate>' and `method group'"

sorry i'm not very good in scripting...dunno how i can simply pass my function to typewritereffect :(
Title: Re: Typewriter Effect, how to reset it?
Post by: skatola on April 26, 2017, 11:57:47 PM
UPDATE:
tried in this way:       EventDelegate.Set (main_label_obj.GetComponent<TypewriterEffect> ().onFinished, delegate() {
         my function ();
but doesn't work :(
Title: Re: Typewriter Effect, how to reset it?
Post by: ArenMook on April 28, 2017, 09:51:20 AM
You need to call TypeWriterEffect's ResetToBeginning() function if you change the label's text yourself.

OnFinished is an NGUI's EventDelegate. You interact with it the same way as other events in NGUI:
  1. EventDelegate.Add(typewriter.onFinished, YourDelegate);
Title: Re: Typewriter Effect, how to reset it?
Post by: skatola on April 28, 2017, 11:48:59 AM
doesn't work : (

   public void interaction(){
      Destroy (main_label_obj.GetComponent<TypewriterEffect> ());
      main_label_obj.AddComponent<TypewriterEffect> ();
      main_label_obj.GetComponent<TypewriterEffect> ().ResetToBeginning ();
      EventDelegate.Add (main_label_obj.GetComponent<TypewriterEffect> ().onFinished, function_test);
      main_label.text = testi [counter_dialogue];
      counter_dialogue++;
   }

Have you any idea why my function_test don't start when main_label.text is complete?
Title: Re: Typewriter Effect, how to reset it?
Post by: skatola on April 28, 2017, 12:04:15 PM
UPDATE: if i add

EventDelegate.Add (main_label_obj.GetComponent<TypewriterEffect> ().onFinished, function_test);

on my void Start on the original typewritereffect component it works, but after i remove it and add it a new one seems like i can't point on it, no idea why...

so this works:

void Start(){
          EventDelegate.Add (main_label_obj.GetComponent<TypewriterEffect> ().onFinished, function_test);
          main_label.text = "Benvenuto Giocatore";
}

but i need to do this and don't work:
           
            Destroy (main_label_obj.GetComponent<TypewriterEffect> ());
      main_label_obj.AddComponent<TypewriterEffect> ();
      main_label_obj.GetComponent<TypewriterEffect> ().ResetToBeginning ();
      EventDelegate.Add (main_label_obj.GetComponent<TypewriterEffect> ().onFinished, function_test);

why i can't point to the new component? : (
Title: Re: Typewriter Effect, how to reset it?
Post by: ArenMook on May 04, 2017, 04:32:25 PM
Destroy() call in Unity is not immediate. DestroyImmediate() would be immediate.

I'm also not sure why you are destroying, creating, then getting the component to begin with. And more than once at that. Simply calling GetComponent<TypeWriterEffect>().ResetToBeginning() is enough. And there is no need to add the event delegate a second time. Remember, you can always EventDelegate.Remove.