The BUG caused by setting the TweenScale callback function to null in NGUI. nguitweenscale

Source: Internet
Author: User

The BUG caused by setting the TweenScale callback function to null in NGUI. nguitweenscale

I encountered a problem when using NGUI TweenScale today.


TweenScale is used twice, playForward () and playReverse (). playForward () is required to do nothing after playForward (). playReverse () is used to execute the function.


Because it takes time to play the animation, it is impossible to execute the specified function after executing the playReverse () code.


NGUI provides the corresponding delegate processing, so the idea is to set onFinished to null when playForward () and add the specified method when playReverse ().


Corresponding code

        EventDelegate.Callback panelClose= PanelClose;        panelScale.SetOnFinished(panelClose);

Time code set to null

panelScale.onFinished = null;

Select the GameObject to add TweenScale for real-time display.


Running, no problem, everything is normal


Export apk test found that the corresponding function is not executed


Back to unity, there is no problem in the test. inadvertently select another GameObject. During the test, the problem occurs.


Check the corresponding code and change the null code to the following code:

        EventDelegate.Callback finish = null;        panelScale.SetOnFinished(finish);

After testing, everything is normal


The Event Callback in NGUI adds user-added data to the linked list. Each item in the linked list contains a MonoBehaviour target and string methodName.

public List<EventDelegate> onFinished = new List<EventDelegate>();

public void SetOnFinished (EventDelegate.Callback del) { EventDelegate.Set(onFinished, del); }static public void Set (List<EventDelegate> list, Callback callback){if (list != null){list.Clear();list.Add(new EventDelegate(callback));}}

From the NGUI code, we can find that the onFinished set at the beginning and the setOnfinished set at the end are completely different operations.

One is the linked list onFinished = null, the other is the linked list onFinished. clear (), and add null to the linked list


Here, we can change the above two sentences to the following:

panelScale.onFinished.Clear();

After testing, everything is normal


Here you only need to clear and add a delegate. If you need more than one delegate, you can refer to the AddOnfinished () and RemoveOnFinished () functions.



Original article, reprinted please note

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.