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